I am adding a “Print…” feature to a shaded example and found…
If I build the data directly to the PDF, I get Vector data:
g = p.ShowPrinterDialog
If g <> Nil Then
g.DrawText("My nice Text", 20,20)
but, if I use (print) a Picture, I get bitmap data:
g = p.ShowPrinterDialog
If g <> Nil Then
g.DrawPicture OffScreen,0,0
In that project, I build in a Function a Picture that holds the TABLEs list, and in a different Function, the Pictures that displays all TABLEs Structure.
Unless I am wrong, I have to duplicate these to create a Vector PDF…
Ideas ?
To avoid misunderstanding, here’s a copy of the image that is generated from a sqlite data base (with a different background for Ian: no yellow in the TABLEs descriptions - cmy(0.10,0.00,0.10) - ):
It’s what I have been doing for the last 20 years.
Two separate rendering routines.
Arguably, if you write for PDF, all you really need is a ‘print my PDF’ function, and ditch the print version.
Ive never gotten round to doing that, I probably should.
I thought the idea was that you could have a common rendering method and pass in either a graphics context for a picture, a printer page or a PDF document page.
This is precisely what the original poster needs to do. His rendering function needs to accept a Graphics object and draw into it; the surrounding code needs to worry about creating the object that supplies the Graphics object.
Fortunately this should be a very easy change to make.
To clarify, the PDFGraphics object is a subclass of the Graphics object. Which means you can pass it to a method that accepts a Graphics object. Put all the drawing code into a method that takes a Graphics object and draw away. Call it with what ever graphics context you want to create the scalable vector version of your printout, PDF file or even a picture object.
Create a new method that takes a graphics object as a parameter. Place all your drawing code in that method. Keep all the code that decides if you are printing or generating a pdf outside of that method.
Now when you want to make a pdf do what you do now but call your new method to perform the drawing, passing it the PDF graphics object.
When you want to print open the printer object and call the new method passing in the printers graphics object.
You can even create a picture and pass the graphics object to the new method. Or even call it in a paint event passing in that graphics object.