« Load PDF from MS SQL … | Home | MBS Xojo Plugins, ver… »

Windows PDF Classes

Since Microsoft added some PDF functions to their frameworks in Windows 10, we can now implement a plugin for it. That got possible since we dropped Windows 7 and require newer functions for component management in Windows 8. For MBS Xojo Plugins 23.2, we add the new classes for you to try out:

Windows PDF screenshot

The key feature is to open PDF documents and render preview pictures for individual pages. The classes do not things like merge and split, form controls or creating of new PDF documents. For that, please use our MBS Xojo DynaPDF Plugin.

The WindowsPDFDocumentMBS class can load a PDF from either a FolderItem, a file path or data in either MemoryBlock or String. The loading can be synchronously or asynchronously in the background. For large PDF documents and a more responsive application, you may want to show a loading window and then run the asynchronous load process.

Once the document is loaded, you can query page count and get objects for the pages. The page class WindowsPDFPageMBS can then provide details on the page like its size, preferred zoom level or rotation. Dimensions can be queried for all page boxes:

  • Media Box, the size of the paper
  • Art Box, the size of the content, which should not be covered later.
  • Bleed Box, the area to draw to, usually bigger than trim box.
  • Trim Box, where to cut the paper after printing.
  • Crop Box, the area to show or print.

Most of them are optional and we usually just use Media Box to show whole page. Or on processing the pages, we may use crop box (if exists) to only show the cropped part.

You can render the page to a picture. The RenderToStream function returns a string with picture data encoded in either JPEG, PNG, TIFF or BMP. This can be configured with the WindowsPDFPageRenderOptionsMBS class. Using that class, you can also set destination size of the preview image. A background color allows you to define the background and default is white. Optionally you can define a source rectangle to only render a portion of the page.

If an error occurs, you get an exception using our WindowsPDFExceptionMBS class. If needed, we could later add asynchronous rendering in the background, which may help to make the example project more responsible when rendering the previews.

Another thing we could make it a comparison of the preview graphics and check how much Microsoft implemented on the more special cases. Like checking for gradients, spot colors, CMYK colors and embedded image formats. PDFKit on macOS also has a few limits there, so if you need full coverage, you may want to check out MBS Xojo DynaPDF Plugin.

Please don't hesitate to contact us if you have questions.

The biggest plugin in space...
11 04 23 - 12:34