Components All New MacOS Windows Linux iOS
Examples Mac & Win Server Client Guides Statistic FMM Blog Deprecated Old

DynaPDF.GeneratePreview

Adds a preview picture to a PDF container.

Component Version macOS Windows Linux Server iOS SDK
DynaPDF 4.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes ✅ Yes
MBS( "DynaPDF.GeneratePreview"; PDFContainer { ; OnlyImage; ImageName; Password } )   More

Parameters

Parameter Description Example Flags
PDFContainer The input PDF container value. Must contain a PDF file. MyTable::PDFContainer
OnlyImage Default is 0. But if you pass 1, the plugin does not return the PDF data in the result, but only the preview. 0 Optional
ImageName If OnlyImage is 1, you can specify a file name for the image result. "preview.jpg" Optional
Password Available in MBS FileMaker Plugin 11.4 or newer.
The password to decrypt the file.
$password Optional

Result

Returns updated container value or error.

Description

Adds a preview picture to a PDF container.
On Windows if you have a PDF in a container FileMaker will not show a preview due to a missing PDF rendering library. On macOS the system can show PDF directly and FileMaker uses this.
This function renders first page as JPEG and add it to the container value as preview.
You need to use DynaPDF.Initialize before to load the DynaPDF library and set the license key (Pro required).
With version 5.0 optionally only creates image without passing PDF data back.

Requires DynaPDF Pro license for the raster engine to create bitmaps from PDF pages.
See also DynaPDF.RenderPage for more options on rendering and Plugin.SetPreviewSize for setting resolution.

On macOS the PDFKit.GeneratePreview function can be an alternative way, but limited to the capabilities of Apple’s frameworks.

See also GeneratePreview function in DynaPDF manual.

Examples

Add a preview to PDF container

# does container have jpeg preview?
If [MBS( "Container.GetTypeSize" ; test::pdf; "JPEG") <= 0]
    # Add preview to PDF in container
    Set Field [test::pdf; MBS("DynaPDF.GeneratePreview"; test::pdf)]
End If

Add a preview to PDF container if needed:

# get a PDF somewhere
Set Variable [ $PDF ; Value: MBS( "Files.ReadFile"; "C:\Users\Christian\Desktop\test.pdf"; "auto") ]
# Does have PDF and no image?
Set Variable [ $types ; Value: MBS( "Container.GetTypes"; $PDF) ]
# PDF included?
If [ Position ( $types ; "PDF " ; 1 ; 1 ) > 0 ]
    # Image preview missing?
    If [ Position ( $types ; "JPEG" ; 1 ; 1 ) < 1 and Position ( $types ; "PNGf" ; 1 ; 1 ) < 1 ]
        # Use DynaPDF if initialized, we can use it
        If [ MBS( "DynaPDF.IsInitialized" ) ]
            Set Variable [ $PDF2 ; Value: MBS( "DynaPDF.GeneratePreview"; $PDF) ]
            If [ MBS("IsError") = 0 ]
                # Success, so use the new PDF
                Set Variable [ $PDF ; Value: $PDF2 ]
            End If
        Else If [ MBS( "IsMacOSX" ) = 1 ]
            # On Mac use PDFKit
            Set Variable [ $PDF2 ; Value: MBS( "PDFKit.GeneratePreview"; $PDF) ]
            If [ MBS("IsError") = 0 ]
                # Success, so use the new PDF
                Set Variable [ $PDF ; Value: $PDF2 ]
            End If
        End If
    End If
End If
# Store PDF with preview
Set Field [ test::Image ; $PDF ]

Make preview picture from PDF with password:

Set Field [ Contacts::Photo Container ; MBS( "DynaPDF.GeneratePreview"; Contacts::PDFFile; 1; "test.jpg"; "secret" ) ]

See also

Release notes

Example Databases

Blog Entries

This function checks for a license.

Created 18th August 2014, last changed 24th March 2022


DynaPDF.FreeTextAnnot - DynaPDF.GetActionCount