Here a example of making a simple pdf file

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…


dim t as TextOutputStream
  dim f as FolderItem
  f=GetFolderItem("test.pdf")
  f.Delete
  t=TextOutputStream.Create(f)
  
  
  
  t.WriteLine "%PDF-1.1"
  
  t.WriteLine "%•±Î"
  
  
  
  t.WriteLine "1 0 obj"
  
  t.WriteLine "  << /Type /Catalog"
  
  t.WriteLine "     /Pages 2 0 R"
  
  t.WriteLine "  >>"
  
  t.WriteLine "endobj"
  
  t.WriteLine " "
  
  t.WriteLine "2 0 obj"
  
  t.WriteLine "  << /Type /Pages"
  
  t.WriteLine "     /Kids [3 0 R]"
  
  t.WriteLine "     /Count 1"
  
  t.WriteLine "     /MediaBox [0 0 300 620]"
  
  t.WriteLine " "
  
  t.WriteLine "  >>"
  
  t.WriteLine "endobj"
  
  t.WriteLine " "
  
  t.WriteLine "3 0 obj"
  
  t.WriteLine "  <<  /Type /Page"
  
  t.WriteLine "      /Parent 2 0 R"
  
  t.WriteLine "      /Resources"
  
  t.WriteLine "     << /Font"
  
  t.WriteLine "           << /F2"
  
  t.WriteLine "               << /Type /Font"
  
  t.WriteLine "                  /Subtype /Type1"
  
  t.WriteLine "                  /BaseFont /Arial"
  
  t.WriteLine "               >>"
  
  t.WriteLine "           >>"
  
  t.WriteLine "       >>"
  
  t.WriteLine "      /Contents 4 0 R"
  
  t.WriteLine " >>"
  
  t.WriteLine "endobj"
  
  t.WriteLine " "
  
  t.WriteLine "4 0 obj"
  
  t.WriteLine "  << /Length 55 >>"
  
  t.WriteLine " "
  
  t.WriteLine " "
  
  t.WriteLine "stream"
  
  t.WriteLine" "
  
  t.WriteLine"BT"
  
  t.WriteLine"    /F2 10 Tf"
  
  t.WriteLine"    10 600 Td"
  
  t.WriteLine"    (Hello) Tj"
  
  t.WriteLine" "
  
  t.WriteLine" "
  
  t.WriteLine" "
  
  t.WriteLine"  ET"
  
  t.WriteLine" "
  
  
  
  t.WriteLine" "
  
  t.WriteLine"BT"
  
  t.WriteLine"    /F2 10 Tf"
  
  t.WriteLine"    10 590 Td"
  
  t.WriteLine"  (Example line 2)   Tj"
  
  t.WriteLine" "
  
  t.WriteLine" "
  
  t.WriteLine" "
  
  t.WriteLine"  ET"
  
  t.WriteLine" "
  
  
  
  t.WriteLine" "
  
  t.WriteLine"BT"
  
  t.WriteLine"    /F2 10 Tf"
  
  t.WriteLine"    10 580 Td"
  
  t.WriteLine"    (            Example line 3) Tj"
  
  t.WriteLine" "
  
  t.WriteLine" "
  
  t.WriteLine" "
  
  t.WriteLine"  ET"
  
  t.WriteLine" "
  
  
  
  t.WriteLine" "
  
  t.WriteLine"BT"
  
  t.WriteLine"    /F2 10 Tf"
  
  t.WriteLine"    10 570 Td"
  
  t.WriteLine"    (            ) Tj"
  
  t.WriteLine" "
  
  t.WriteLine" "
  
  t.WriteLine" "
  
  t.WriteLine"  ET"
  
  t.WriteLine" "
  
  
  
  t.WriteLine" "
  
  t.WriteLine"BT"
  
  t.WriteLine"    /F2 10 Tf"
  
  t.WriteLine"    10 560 Td"
  
  t.WriteLine"    (  Greetings, from Frederik Pot) Tj"
  
  t.WriteLine" "
  
  t.WriteLine" "
  
  t.WriteLine" "
  
  t.WriteLine"  ET"
  
  t.WriteLine" "
  
  
  
  t.WriteLine"endstream"
  
  t.WriteLine"endobj"
  
  t.WriteLine" "
  
  t.WriteLine" "
  
  t.WriteLine" "
  
  t.WriteLine"xref"
  
  t.WriteLine"0 5"
  
  t.WriteLine"0000000000 65535 f "
  
  t.WriteLine"0000000018 00000 n "
  
  t.WriteLine"0000000077 00000 n "
  
  t.WriteLine"0000000178 00000 n "
  
  t.WriteLine"0000000457 00000 n "
  
  t.WriteLine"trailer"
  
  t.WriteLine"  <<  /Root 1 0 R"
  
  t.WriteLine"      /Size 5"
  
  t.WriteLine"  >>"
  
  t.WriteLine"startxref"
  
  t.WriteLine"565"
  
  t.WriteLine"%%EOF"
  
     
  t.Close
  f.Launch
  
  

Note … this will NOT work if the text exceeds what you entered in your example.
Trust me :slight_smile:
PDF is very picky about its pointer, their location, and size… Add more text, and your XREF table becomes invalid

Dave, I hope next year you get back to your PDF class. It was really promising.

Meanwhile:

So, for anyone looking for a simple and free pdf writer, fpdf this is it. Desktop version: http://www.circlecalc.us/rpdf (1).zip ?

For Windows.

On OS X, simply use the PopupMenu (bottom left) to choose the Action you want (save to pdf on disk, Open it in Preview, save it as ps, etc.)

What about PDFWriter ?
(just do not activate all options that install other software with it)

Just for fun.

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) End If End If

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 you’re 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 !)

Enjoy.

PS: you can even pass graphics (images, photos, Object2D…) if you need (I’ve done that in the front page).

I nearly forgot: I prefer a Xojo made Export to PDF feature (that can create vector pdf)

Emile . . . fpdf is for creating the pdf in the first place.

John… Same for PDFWriter.

BTW: if you’re talking about the example above, can you expand your answer (I do not understand the point: the result is the same; one code = two features).

Hi, i am again into the pdf format… now i achieved to work also with colors ,here a example code for those who like it… just put it under a button:

  dim t as TextOutputStream
  dim f as FolderItem
  f=GetFolderItem("test.pdf")
  f.Delete
  t=TextOutputStream.Create(f)
  
  t.WriteLine"%PDF-1.2"
  t.WriteLine"1 0 obj<</Type /Page/Parent 5 0 R"
  t.WriteLine"/Resources 3 0 R"
  t.WriteLine"/Contents 2 0 R>>endobj"
  t.WriteLine"2 0 obj<< /Length 51 >>"
  t.WriteLine"stream"
  
  t.WriteLine"BT"
  t.WriteLine" /F1 12 Tf 1 0 0 1 "
  t.WriteLine" 60 590" ''left top
  t.WriteLine"Tm (Xojo...Drawing is fun...)Tj"
  t.WriteLine"  ET"
  
  
  t.WriteLine" 250 0 0 rg"''color
  t.WriteLine" 120 580 m"''move to
  t.WriteLine" 100 140  l"
  t.WriteLine" 80 160 l"
  t.WriteLine" f"
  
  t.WriteLine" 0 250 0 rg"
  t.WriteLine" 200 560 m"
  t.WriteLine" 210 140  l"
  t.WriteLine" 280 160 l"
  t.WriteLine" f"
  
  t.WriteLine" 0 0 250 rg"
  t.WriteLine"BT"
  t.WriteLine" /F1 20 Tf 1 0 0 1 "
  t.WriteLine" 10 560" ''left top
  t.WriteLine"Tm (Xojo...Drawing is fun...)Tj"
  t.WriteLine"  ET"
  
  
  t.WriteLine"endstream"
  t.WriteLine"endobj"
  t.WriteLine"3 0 obj<< /ProcSet[/PDF/Text] /Font <</F1 4 0 R >>>>endobj"
  t.WriteLine"4 0 obj<< /Type /Font/Subtype /Type1/Name /F1/BaseFont/Arial >>endobj"
  
  t.WriteLine"5 0 obj<< /Type /Pages/Kids [ 1 0 R ]/Count 1"
  t.WriteLine"/MediaBox[ 0 0 300 600 ] >>endobj"
  t.WriteLine"6 0 obj<< /Type /Catalog/Pages 5 0 R >>endobj"
  t.WriteLine"trailer<< /Root 6 0 R >>"
  
  
  t.Close
  f.Launch

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

http://www.rdS.com/gpdf/

You should include a link to it when you mention it Dave
People might not know where to locate it and may not scroll back through a long forum thread to find such a link

And if you haven’t you should ask Paul to list it on the Third Party products lists
Maybe Dana as well to list it in the store

Thanks. Norman… I added the link above…
And have “spoken” with Dana, and just haven’t gotten around to that yet … my bad for sure :frowning:

BTW, I do already have gPDF on the 3rd Party Product page:

http://developer.xojo.com/third-party-products$pdf

I have to share that since I have listed RubberViews in the Xojo App Store, I have enjoyed regular sales.

Not everybody frequents the forum, and a significant number of people buy in the Xojo store.

Well, when i did some tests , i found out that the ‘rgb color’ is not working… more a 1 for red(1 0 0) , a 1 for green (0 1 0) and a 1 for blue (0 0 1)… have no solution for it till now… Goodluck…

Regards,

Frederik Pot

Doubles … values from 0 to 1 ?

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

Thank you both…

It worked Jeff ! . Thank you verry much !

Regards,

Frederik Pot