iOS has built-in support for reading and writing PDF documents.
The Canvas object allows us to display existing PDF documents and to create new PDF documents.
Displaying a PDF document
First we need to load the PDF file. This is done with PDFDocument object:
Dim pdf As PDFDocument pdf.Initialize(File.DirAssets, "example.pdf")
cvs.DrawPDF(pdf, 1, cvs.TargetRect)
Note that the first page number is 1.
That's it. A simple PDF reader example is attached. You need to add a PDF file to the Files folder in order to run it.
Creating a new PDF document
The Canvas object also allows us to create new PDF documents. Instead of drawing to a View, the Canvas draws to a PDF file.
Dim pcvs As Canvas pcvs.InitializePDF(File.DirDocuments, "1.pdf", 612, 792)
You can now use the standard Canvas methods to draw to the file.
There are two important points:
1. You can create new pages by calling Canvas.NextPDFPage.
2. You must call Canvas.Release when you are done drawing.
2.5 KB Views: 1,210