« Things to do in Colog… | Home | Xojo Stammtisch in Wi… »

Create a PDF with PageGraphics and DynaPDF

Here a nice short example on how to draw a PDF with our new PageGraphics property in DynaPDFMBS class:

Dim pdf As New DynapdfMBS // please subclass DynapdfMBS to implement error event Dim f As FolderItem = SpecialFolder.Desktop.Child("DynaPDF Graphics.pdf") 'pdf.SetLicenseKey "Starter" // For this example you can use a Starter, Lite, Pro or Enterprise License // Create new PDF. Use f = nil for in-memory PDF Call pdf.CreateNewPDF(f) // append a new page, so we have an open page Call pdf.Append // get graphics object to draw on the page Dim g As Graphics = pdf.PageGraphics // draw as usual g.DrawString "Hello World", 105, 100 g.DrawRect 100, 80, 100, 100 // close page and file Call pdf.EndPage Call pdf.CloseFile // for in-memory PDF, use GetBuffer here to grab it. 'Dim PDFData As String = pdf.GetBuffer

You can put the actual drawing code into a method with g as graphics parameter and than call it on several places. e.g. call it from Canvas.Paint event to show it in a window, call it with graphics from OpenPrinterDialog to draw in printing context or call it with PageGraphics to draw into a PDF document. The biggest plugin in space...
06 05 19 - 13:50