DynaPDF.GeneratePreview
-----------------------

Adds a preview picture to a PDF container.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [DynaPDF](component_DynaPDF.md) | [4.0](newinversion40.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "DynaPDF.GeneratePreview"; PDFContainer { ; OnlyImage; ImageName; Password } ) 

**MBS**( **"DynaPDF.GeneratePreview";** /\* Adds a preview picture to a PDF container. \*/  
**$PDFContainer**; /\* The input PDF container value. Must contain a PDF file.e.g. MyTable::PDFContainer \*/   
**$OnlyImage**; /\* Optional; Default is 0. But if you pass 1, the plugin does not return the PDF data in the result, but only the preview.e.g. 0 \*/   
**$ImageName**; /\* Optional; If OnlyImage is 1, you can specify a file name for the image result.e.g. "preview.jpg" \*/   
**$Password**) /\* Optional; The password to decrypt the file. \*/ 

### 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 | The password to decrypt the file. | $password | Optional      Added in version **11.4**. |

### 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](DynaPDFInitialize.md) 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](DynaPDFRenderPage.md) for more options on rendering and [Plugin.SetPreviewSize](PluginSetPreviewSize.md) for setting resolution.  
  
On macOS the [PDFKit.GeneratePreview](PDFKitGeneratePreview.md) function can be an alternative way, but limited to the capabilities of Apple’s frameworks.  
See also [GeneratePreview](https://www.monkeybreadsoftware.com/DynaPDF-Manual/RenderPageToImage.shtml) function in DynaPDF manual.

### Examples

Add a preview to PDF container

 # does container have jpeg preview?   
If \[MBS ( "[Container.GetTypeSize](ContainerGetTypeSize.md)" ; test::pdf ; "JPEG") &lt;= 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](FilesReadFile.md)"; "C:\\Users\\Christian\\Desktop\\test.pdf"; "auto") \]   
\# Does have PDF and no image?   
Set Variable \[ $types ; Value: MBS ( "[Container.GetTypes](ContainerGetTypes.md)"; $PDF ) \]   
\# PDF included?   
If \[ Position ( $types ; "PDF " ; 1 ; 1 ) &gt; 0 \]   
 # Image preview missing?  
 If \[ Position ( $types ; "JPEG" ; 1 ; 1 ) &lt; 1 and Position ( $types ; "PNGf" ; 1 ; 1 ) &lt; 1 \]   
 # Use DynaPDF if initialized, we can use it  
 If \[ MBS ( "[DynaPDF.IsInitialized](DynaPDFIsInitialized.md)" ) \]   
 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](PDFKitGeneratePreview.md)"; $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

- [Container.Export](ContainerExport.md)
- [Container.GetType](ContainerGetType.md)
- [Container.GetTypes](ContainerGetTypes.md)
- [Container.GetTypeSize](ContainerGetTypeSize.md)
- [DynaPDF.Initialize](DynaPDFInitialize.md)
- [DynaPDF.IsInitialized](DynaPDFIsInitialized.md)
- [DynaPDF.SaveAndSignFileExt1](DynaPDFSaveAndSignFileExt1.md)
- [Files.ReadFile](FilesReadFile.md)
- [PDFKit.GetPDFPageImage](PDFKitGetPDFPageImage.md)
- [Plugin.SetPreviewSize](PluginSetPreviewSize.md)

### Release notes

- **Version 14.5**
    - Improved [DynaPDF.GeneratePreview](https://www.mbsplugins.eu/DynaPDFGeneratePreview.shtml), [DynaPDF.ReadImageResolution](https://www.mbsplugins.eu/DynaPDFReadImageResolution.shtml), [DynaPDF.ReadImageFormat](https://www.mbsplugins.eu/DynaPDFReadImageFormat.shtml), [DynaPDF.InsertImage](https://www.mbsplugins.eu/DynaPDFInsertImage.shtml), [DynaPDF.AttachFileContainer](https://www.mbsplugins.eu/DynaPDFAttachFileContainer.shtml), [DynaPDF.AddOutputIntentEx](https://www.mbsplugins.eu/DynaPDFAddOutputIntentEx.shtml), [DynaPDF.CreateICCBasedColorSpaceContainer](https://www.mbsplugins.eu/DynaPDFCreateICCBasedColorSpaceContainer.shtml) and [DynaPDF.OpenPDFFromContainer](https://www.mbsplugins.eu/DynaPDFOpenPDFFromContainer.shtml) to return proper error if container is empty.
- **Version 11.4**
    - Added password parameter for [DynaPDF.GeneratePreview](https://www.mbsplugins.eu/DynaPDFGeneratePreview.shtml) function.

### Example Databases

- [CURL/CURL Download PDF and add preview with DynaPDF](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/CURL/CURL%20Download%20PDF%20and%20add%20preview%20with%20DynaPDF.shtml#1ScriptAnchor_)
- [DynaPDF/Generate Previews](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/DynaPDF/Generate%20Previews.shtml#2ScriptAnchor_)

### Blog Entries

- [MBS FileMaker Plugin, version 14.5pr8](https://www.mbsplugins.de/archive/2024-11-08/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [Windows PDF Functions](https://www.mbsplugins.de/archive/2023-04-11/Windows_PDF_Functions/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 11.4pr5](https://www.mbsplugins.de/archive/2021-09-03/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [Things you can do with DynaPDF](https://www.mbsplugins.de/archive/2021-07-02/Things_you_can_do_with_DynaPDF/monkeybreadsoftware_blog_filemaker)
- [Render pictures from PDF](https://www.mbsplugins.de/archive/2021-06-27/Render_pictures_from_PDF/monkeybreadsoftware_blog_filemaker)
- [Seven things to add to your FileMaker solution today with MBS Plugin](https://www.mbsplugins.de/archive/2021-03-21/Seven_things_to_add_to_your_Fi/monkeybreadsoftware_blog_filemaker)
- [Normalize PDF orientation with MBS Plugins and DynaPDF](https://www.mbsplugins.de/archive/2018-03-09/Normalize_PDF_orientation_with/monkeybreadsoftware_blog_filemaker)
- [FileMaker and PDF Containers](https://www.mbsplugins.de/archive/2017-08-30/FileMaker_and_PDF_Containers/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 5.0pr9](https://www.mbsplugins.de/archive/2015-02-01/MBS_FileMaker_Plugin_version_5/monkeybreadsoftware_blog_filemaker)
- [MBS Filemaker Plugin, version 4.1pr3](https://www.mbsplugins.de/archive/2014-03-04/MBS_Filemaker_Plugin_version_4/monkeybreadsoftware_blog_filemaker)

This function checks for a license.

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

  
[DynaPDF.FreeTextAnnot](DynaPDFFreeTextAnnot.md) - [DynaPDF.GetActionCount](DynaPDFGetActionCount.md)

[HTML Version](DynaPDFGeneratePreview.shtml)