Skip to content

PDFViewer for Xojo iOS Projects

Many users asked for a way to view and navigate the pages of a PDF document in their iOS projects. Starting with Xojo 2023r2, this is possible with the new MobilePDFViewer control. Continue reading to get tips on how to use this in your iOS projects.

The use of this control is pretty straightforward. Add it to the layout of a Screen in your iOS project. You can use the Inspector Panel to set the background color (by default it is white) and whether it displays the page thumbnails. Of course, the available properties can also be set via code.

Here’s how it looks running in the Simulator:

You will then need to tell the PDFViewer which PDF file to display. Do this by assigning the FolderItem to the document property of the PDFViewer control instance. The following lines of code assigns document that has been added to the Resources folder using a Copy File step in the IDE:

Var f As FolderItem = SpecialFolder.Resource("SampleDocument.pdf")

If f <> Nil And f.Exists Then
  PDFViewer1.Document = f
End If

It is also possible to change the layout of the pages in the PDFViewer with the DisplayMode property that accepts any of the values of the MobilePDFViewer.DisplayModes Enumeration:

  • SinglePage
  • SinglePageContinuous
  • TwoUp
  • TwoUpContinuous

It is possible to get the number of pages in the document through the Pages property. You can jump to a specific page in the PDF by setting its number using the Page property.

Lastly, another useful feature of the PDFViewer control is being able to call the Content method in order to retrieve all the text found in the document. To learn more about all the great new PDF features in Xojo, check out the PDF tag of the Xojo Programming Blog.

Javier Menendez is an engineer at Xojo and has been using Xojo since 1998. He lives in Castellón, Spain and hosts regular Xojo hangouts en español. Ask Javier questions on Twitter at @XojoES or on the Xojo Forum.