« Sending email with a … | Home | MBS FileMaker Plugin,… »

Render pictures from PDF

Sometimes you need a preview picture of a PDF document. Our PDF Library example shows how to browse a PDF with each page being shown in a record with a preview picture. Great to avoid interactive containers and especially avoid the user getting the whole PDF transferred from server to the client computer.

We have several ways to render PDF pictures:

DynaPDF.GeneratePreview

With DynaPDF Pro you can render PDF pages cross platform (macOS, Windows, iOS and Linux) as you have your own PDF engine on hand. DynaPDF.GeneratePreview is a convenience function to quickly pass in a container value with a PDF inside and get back a PDF with preview. Great way to add previews when inserting a PDF on Windows or Linux. With a preview, the PDF can be shown in a non-interactive container.

Set Variable [ $OutputPDF ; Value: MBS( "DynaPDF.GeneratePreview"; $InputPDF) ]

The function has a flag to only give you an image, so you can also use it like this:

Set Variable [ $OutputPicture; Value: MBS( "DynaPDF.GeneratePreview"; $InputPDF; 1; "preview.jpg") ]

Of course you can do more with DynaPDF.RenderPage as you see before.

PDFKit.GeneratePreview

PDFKit is the PDF library coming with macOS and iOS. You can use PDFKit.GeneratePreview function to add a preview to a PDF container value like the one above and then store the PDF with preview in the database.

Set Variable [ $OutputPDF ; Value: MBS( "PDFKit.GeneratePreview"; $InputPDF) ]

You may run a bot to look through PDF containers, check with our Container.GetTypes function if a preview is there and add it if necessary.

DynaPDF.RenderPage

With DynaPDF we can initialize the library with DynaPDF.Initialize function and then load a PDF in memory and render individual pages. The following script imports the whole PDF and then renders a given page specified by the page number:

# Start new PDF workspace
Set Variable [$pdf; Value:MBS("DynaPDF.New")]
# Load PDF from container
Set Variable [$r; Value:MBS("DynaPDF.OpenPDFFromContainer"; $pdf; Test::data)]
# Import all pages
Set Variable [$r; Value:MBS("DynaPDF.ImportPDFFile"; $pdf)]
# Render one page as Picture
Set Variable [$r; Value:MBS("DynaPDF.RenderPage"; $pdf; $pageNumber)]
# Put in Container
Set Field [Test::PageImage; $r]
# cleanup
Set Variable [$r; Value:MBS("DynaPDF.Release"; $pdf)]


The DynaPDF.RenderPage function can take much more parameters and you may specify the DPI you like to get. And you may specify various flags like for excluding form fields. You can specify the desired image file format (TIFF, JPEG, PNG, BMP or JPC) and pixel format (1bit, gray, RGB, BGR, RGBA, BGRA, ARGB, ABGR, CMYK, CMYKA and GrayA) or compression filter (Flate, JPEG, CCITT3, CCITT4, LZW or JP2K). For example the following call creates a 300 dpi CMYK tiff file:

Set Variable [ $r ; Value: MBS("DynaPDF.RenderPage"; $pdf; 1; 300; 0; 0; "default"; "CMYK"; "Flate"; "Tiff"; "test.tif") ]

If you need a DynaPDF Pro license, please check our pricing website and there we have a bundle of MBS Plugin for Server with DynaPDF Pro license.

PDFKit.GetPDFPageImage

With the PDFKit.GetPDFPageImage function you can query the picture for a page using PDFKit on macOS or iOS:

Set Variable [ $OutputPicture; Value: MBS( "PDFKit.GetPDFPageImage"; MyTable::PDFContainer; $pageNumber; "jpeg"; "test.jpg"; 300; 1 ) ]As you see we can specify page number, desired image type (JPEG, PNG, GIF or BMP), the DPI for the resolution and what box to use. Like DynaPDF we prefer crop box, but fall back to media box for the page. Media box defines the paper size, while crop box would tell the printing company, where to crop the paper to get the desired final page size. Claris FileMaker Plugin

27 06 21 - 12:10