User Tools

Site Tools


Sidebar

Multimedia

k23:k23.12:k23.12.1:start

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:

PropertyData typeDescription
AntialiasingBooleanReturns or sets the value whether or not antialiasing is used for drawing pages.
AuthorStringReturns the author of the PDF document.
CountIntegerReturns the number of pages of the PDF document.
MaxIntegerReturns the number of pages of the document minus one; Max = Count -1.
CreationDateDateReturns the date on which the PDF document was created.
CreatorStringReturns the creator of the PDF document.
ProducerStringReturns the producer of the PDF document.
Index .PdfDocumentIndexReturns the index (table of contents) of a PDF document as a virtual object of type .PdfDocumentIndex.
KeywordsStringReturns a comma-separated list as a string.
LinearizedBooleanSpecifies whether the document is linearised or not. Linearisation of PDF content enables efficient incremental access to the PDF file in a network environment.
ModificationDateDateReturns the date the PDF document was last modified.
ResolutionFloatReturns or sets the resolution of the PDF document in DPI.
RotationIntegerReturns 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.
SubjectStringReturns the subject of the PDF document.
TextAntialiasingBooleanReturns the value or sets whether the text is anti-aliased when drawing a page.
TextHintingBooleanReturns the value or sets whether text hinting was used when drawing a page.
TitleStringReturns the title of the PDF document.
VersionStringReturns 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:

MethodReturn typeDescription
Find ( Label As String )IntegerReturns 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
The website uses a temporary session cookie. This technically necessary cookie is deleted when the browser is closed. You can find information on cookies in our privacy policy.
k23/k23.12/k23.12.1/start.txt · Last modified: 24.06.2024 by emma

Page Tools