Below a code to make a simple pdf file… just put it under a button … it makes the file test.pdf and launches it…
The code is free to use/modify/spread.
Remark that each line extra the ‘-10’ asks… good luck.
This code is easily to port to other ide’s/software…
Note … this will NOT work if the text exceeds what you entered in your example.
PDF is very picky about its pointer, their location, and size… Add more text, and your XREF table becomes invalid
The code below works fine and comes from the docs (one of the examples from PrinterSetup):
Dim g As Graphics
Dim p As PrinterSetup
p = New PrinterSetup
If p.PageSetupDialog Then
g = OpenPrinterDialog(p)
If g <> Nil Then
g.DrawString("Greetings to Frederik Pot from Emile Schwarz.", 50, 50)
I only changed the string.
To get a pdf, on OS X, click in the OK button (Printer Setup window), then in the PDF popup, choose the first or the second option.
On Windows, install a virtual printer (as said earlier) and do nearly the same (watch carefully what youre doing 'cause there is a lot of available options).
The generated pdf have vectorial text.
You can change the font name, size, etc. before the DrawString line,using Graphics commands (g.TextFont, g.TextSize) the orientation: g.Landscape = True
OK, this is far different than what the op says, but I make PDF (and paper) reports using this way (the user tried to print in A3 instead of A4: I never tested that and THIS WORKED !)
PS: you can even pass graphics (images, photos, Object2D ) if you need (Ive done that in the front page).
I nearly forgot: I prefer a Xojo made Export to PDF feature (that can create vector pdf)
PDF is “kinda” forgiving… but not too much. All those numbers MEAN something, and if the pointers don’t match the contents, then PDF readers say “So sorry, too bad”… So while you code might work for “simple” (ie. short) examples, it will begin to fail if you add more that a few lines or code, and WILL fail if you attempt more pages.
gPDF (source code available) handles all of that and much much more, in the same syntax as you are familiar with using the Xojo Canvas
PDF format is somewhat complex… and for the most part unforgiving… As I have said many times… you cannot just cobble it together, because once you get past a certain point, the PDF will become corrupt, and the pointers, indexes, lengths etc MUST line up… and just adding “stuff” doesn’t allow that…
which what programs like gPDF and DynaPDF do… all those calculations