Table of Contents
23.12.1 Class PdfDocument (gb.poppler)
This class represents a PDF document. It enables its content to be read and rendered. The class behaves like a read-only array. This is how you create a new PDF document of type PdfDocument from a PDF file in Gambas:
Dim hPdfDocument As PdfDocument hPdfDocument = New PdfDocument ( Path As String [ , Owner As String, Password As String ] )
- Path is the path to the PDF file.
- Owner is the owner of the document.
- Password is the password. The last two parameters are optional.
You can use the PdfPage class to return a specific page of a PDF document as a virtual object based on its index. Index is a value between 0 and the value of the property PdfDocument.Max = PdfDocument.Count -1.
Dim hPdfDocument As PdfDocument Dim hPdfPage As PdfPage hPdfPage = hPdfDocument [ Index As Integer ]
23.12.1.1 Properties
The PdfDocument class has the following properties:
| Property | Data type | Description |
|---|---|---|
| Antialiasing | Boolean | Returns or sets the value whether or not antialiasing is used for drawing pages. |
| Author | String | Returns the author of the PDF document. |
| Count | Integer | Returns the number of pages of the PDF document. |
| Max | Integer | Returns the number of pages of the document minus one; Max = Count -1. |
| CreationDate | Date | Returns the date on which the PDF document was created. |
| Creator | String | Returns the creator of the PDF document. |
| Producer | String | Returns the producer of the PDF document. |
| Index | .PdfDocumentIndex | Returns the index (table of contents) of a PDF document as a virtual object of type .PdfDocumentIndex. |
| Keywords | String | Returns a comma-separated list as a string. |
| Linearized | Boolean | Specifies whether the document is linearised or not. Linearisation of PDF content enables efficient incremental access to the PDF file in a network environment. |
| ModificationDate | Date | Returns the date the PDF document was last modified. |
| Resolution | Float | Returns or sets the resolution of the PDF document in DPI. |
| Rotation | Integer | Returns or sets the global page rotation in degrees. The value must be a multiple of 90: 0, 90, 180 or 270. The rotation angle can also be negative, for example -90. |
| Subject | String | Returns the subject of the PDF document. |
| TextAntialiasing | Boolean | Returns the value or sets whether the text is anti-aliased when drawing a page. |
| TextHinting | Boolean | Returns the value or sets whether text hinting was used when drawing a page. |
| Title | String | Returns the title of the PDF document. |
| Version | String | Returns the version of the PDF document as a string. |
Table 23.12.1.1.1 : Properties of the PdfDocument class
Notes
- Creator: If the document was converted from another format, the creator (C) is the name of the product (P) that created the original document from which it was converted. Source: https://poppler.freedesktop.org/api/glib/PopplerDocument.html#poppler-document-get-creator. Examples: C = Writer, P = LibreOffice 6.4; C = dvips(k) 5.96 Copyright 2007 Radical Eye Software, P = GPL Ghostscript 8.60.
- Producer: Returns the producer of the document. If the document was converted from another format, the producer is the name of the product that converted it to PDF. Source: https://poppler.freedesktop.org/api/glib/PopplerDocument.html#poppler-document-get-producer.
- Keywords: Note that only an internally comma-separated string is returned - such as “gb.media, gb.media.form, GStreamer”.
- ModificationDate: If a PDF document was newly created with OpenLibre, for example, the value read always has a date with the year 1969 or 1970 - and is therefore incorrect. The following source code therefore does not use the 'ModificationDate' property and uses the 'LastChange' property, which describes when the PDF document was last changed:
sMessage = Format(Stat(FMain.DocumentPath).LastChange, "dd.mm.yyyy hh:nn:ss") Print sMessage
23.12.1.2 Methods
The PdfDocument class only has one method:
| Method | Return type | Description |
|---|---|---|
| Find ( Label As String ) | Integer | Returns the page index of the page that has the identifier 'Label'. If no page was found, -1 is returned. |
Table 23.12.1.2.1 : Method of the PdfDocument class
23.12.1.3 Excursus
On the page https://wiki.ubuntuusers.de/poppler-utils/ you will find a brief description of command line programmes from the poppler-utils collection, which you can use to obtain information about PDF documents or convert them into an XML file, for example.
Here is an example of reading the fonts used in a PDF document, which is not possible using the Gambas component gb.poppler:
hans@pc-a-mint20:~/Dokumente$ pdffonts k23.12.pdf name type encoding emb sub uni object ID ------------------------------------ ----------------- ---------------- --- --- --- --------- BAAAAA+LiberationSans TrueType WinAnsi yes yes yes 48 0 CAAAAA+DejaVuSansMono TrueType WinAnsi yes yes yes 33 0 DAAAAA+LiberationSans-Italic TrueType WinAnsi yes yes yes 43 0 EAAAAA+LiberationSans-Bold TrueType WinAnsi yes yes yes 38 0
