Once you save the document to disk, this information will be available (and displayed) as part of the PDF properties- for example, using the Preview app on macOS:
MyPDF.Keywords = "Xojo, PDF, Code, Multiplatform” For example: MyPDF.Author = "Xojo Developer"
You can set the usual metadata to the PDF documents using Xojo. We will be able to draw it on the desired coordinates (and with the desired size of 50 x 50 pixels) over the PDF document page using the following sentences: g.DrawPicture(Arboles, 20, 20, 50, 50) Let’s say we did add the “Trees” Picture to our Xojo project. For example, let’s use some large fragment of text so it will be centred on the new Page (this one will be the classic “Lorem Ipsum” text, stored in this case by the kLoremIpsum Constant): Var textWrap As Integer = 200Īt this point, our PDF document will be as the one displayed in the following screenshot: In order to add a new page to your PDF document you only need to call the NextPage method on its graphic context: g.NextPageĪnd that means that, from now on, all the drawing commands will be made on the new page. G.DrawText(helloWorld, x - textWidth, y - textHeight) Adding New Pages to the PDF Document Var textHeight As Integer = (g.TextHeight / 2) - g.FontAscent Var textWidth As Integer = g.TextWidth(HelloWorld) / 2 Var helloWorld As String = "Hello PDF World" While the next one will draw the “Hello PDF World” text centered on the page and over the previously drawn circle. G.FillOval(x - offset, y - offset, size, size)
For that you can use the same methods and properties you use when drawing over any regular Graphics context.įor example, the following code snippet will draw a filled circle centered on the PDF page: Var g As Graphics = MyPDF.Graphics You’ll be able to include text, Pictures and some geometric forms like Lines, Circles/Ovals, Rectangles/Rounded Rectangles (both in their filled or outline variants). So, in this case, the PDF document will be created with a 500 width x 500 height pixels for the page. Or any other arbitrary size: Var MyPDF As New PDFDocument(500, 500) If you want to specify a concrete page size, you may use any of the included Enumeration values, for example: Var MyPDF As New PDFDocument(4) It will use the by default constructor, creating a document with a letter size blank page. So, in this case you only need to use: Var MyPDF As New PDFDocument Creating a PDF DocumentĪs when using any other class from the Xojo framework, start by creating a new instance for the PDF document. In addition, because the text is vectorial it will be searchable using any PDF utility with text search capabilities and, for example, when using the Preview app on macOS, the data detector’s technology will be able to catch and act on some specific data like telephone numbers or postal addresses. The fact that both text and geometric forms are vectorial in your PDF documents means that these will be rendered with 100% quality, independently the scale factor you (or your users) may be using once they display them with any PDF viewer utility or App. In addition, you’ll be glad to know that both the text and the geometric forms you add to your PDF documents are vectorial! Except those generated when “printing” PDF documents from your Reports those will be vectorial once we add Obejct2D support to the PDFDocument class. This is the first iteration of the PDFDocument class and we are very aware of the things that we will be adding in future releases that are not in 2020r1. Nevertheless, this first set of features will let you create many of the documents you need in Desktop, Web and Console. Xojo 2020r1 brings a highly requested feature to the Xojo IDE: the ability to create PDF documents from code! Now you can use the already familiar methods in Xojo’s Graphics class to create Standard PDF 1.4 documents with the PDFDocument class.