DynaPDF.OpenOutputFile
----------------------

The function opens the output file into which the PDF file should be written.

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

MBS( "DynaPDF.OpenOutputFile"; PDF; Path ) 

**MBS**( **"DynaPDF.OpenOutputFile";** /\* The function opens the output file into which the PDF file should be written. \*/  
**$PDF**; /\* The PDF reference returned from [DynaPDF.New](DynaPDFNew.md). \*/   
**$Path**) /\* The file path to create the PDF.  
The file name should include pdf file extension.e.g. "C:\\Test.pdf" \*/ 

### Parameters

| Parameter | Description | Example |
|---|---|---|
| PDF | The PDF reference returned from [DynaPDF.New](DynaPDFNew.md). | $pdf |
| Path | The file path to create the PDF.   The file name should include pdf file extension. | "C:\\Test.pdf" |

### Result

Returns OK on success.

### Description

The function opens the output file into which the PDF file should be written.   
The PDF file must be created in memory if this function should be used. This is the case if you called [DynaPDF.New](DynaPDFNew.md) without a file path.  
  
It is strongly recommended to check with [DynaPDF.HaveOpenDocument](DynaPDFHaveOpenDocument.md) whether a PDF file is still in memory before calling this function.  
  
If you get back an error "Cannot open file!", please check if you didn't open the file before with [DynaPDF.OpenPDFFromFile](DynaPDFOpenPDFFromFile.md). In that case a call to [DynaPDF.CloseImportFile](DynaPDFCloseImportFile.md) may be needed.  
  
This function requires a native path. Use [Path.FileMakerPathToNativePath](PathFileMakerPathToNativePath.md) to convert a FileMaker path to a native path if required. If you like to have the user choose the path, you can use [FileDialog](component_FileDialog.md) functions.  
For Server be aware that server has limited permissions and may not be able to access all files on a computer.  
See also [OpenOutputFile](https://www.monkeybreadsoftware.com/DynaPDF-Manual/OpenOutputFile.shtml) function in DynaPDF manual.

### Examples

Import selected pages from one PDF and write into a new one:

 # New PDF   
Set Variable \[$pdf ; Value:MBS ("[DynaPDF.New](DynaPDFNew.md)")\]  
  
\# Open existing PDF file (or use [DynaPDF.OpenPDFFromContainer](DynaPDFOpenPDFFromContainer.md) for container)   
Set Variable \[$r ; Value:MBS ("[DynaPDF.OpenPDFFromFile](DynaPDFOpenPDFFromFile.md)"; $pdf ; $path )\]  
  
\# Query page count   
Set Variable \[$pageCount ; Value:MBS ( "[DynaPDF.GetImportPageCount](DynaPDFGetImportPageCount.md)"; $pdf )\]  
  
\# Import the pages you need   
Set Variable \[$r ; Value:MBS ("[DynaPDF.ImportPDFPage](DynaPDFImportPDFPage.md)"; $pdf ; 1)\]  
Set Variable \[$r ; Value:MBS ("[DynaPDF.ImportPDFPage](DynaPDFImportPDFPage.md)"; $pdf ; 2)\]  
Set Variable \[$r ; Value:MBS ("[DynaPDF.ImportPDFPage](DynaPDFImportPDFPage.md)"; $pdf ; 3)\]  
Set Variable \[$r ; Value:MBS ("[DynaPDF.ImportPDFPage](DynaPDFImportPDFPage.md)"; $pdf ; $pagecount - 1)\]  
Set Variable \[$r ; Value:MBS ("[DynaPDF.ImportPDFPage](DynaPDFImportPDFPage.md)"; $pdf ; $pagecount - 2)\]  
  
\# Set output to this file path   
\# MBS ( "DynaPDF.OpenOutputFile"; $pdf ; "/Users/cs/Desktop/output.pdf" )   
  
\# Write PDF   
Set Variable \[$r ; Value:MBS ("[DynaPDF.Save](DynaPDFSave.md)"; $pdf )\]  
  
\# release memory   
Set Variable \[$r1 ; Value:MBS ("[DynaPDF.Release](DynaPDFRelease.md)"; $pdf )\]  
Read in a file, add text and write back:

 # Start new PDF   
Set Variable \[ $pdf ; Value: MBS ("[DynaPDF.New](DynaPDFNew.md)") \]  
\#   
\# import existing file   
Set Variable \[ $r ; Value: MBS ("[DynaPDF.OpenPDFFromFile](DynaPDFOpenPDFFromFile.md)"; $pdf ; "/Users/cs/Temp/Installation.pdf") \]  
Set Variable \[ $r ; Value: MBS ("[DynaPDF.ImportPDFFile](DynaPDFImportPDFFile.md)"; $pdf ; 1) \]  
Set Variable \[ $r ; Value: MBS ("[DynaPDF.CloseImportFile](DynaPDFCloseImportFile.md)"; $pdf ) \]  
\#   
\# now edit a page   
Set Variable \[ $r ; Value: MBS ("[DynaPDF.EditPage](DynaPDFEditPage.md)"; $pdf ; 1) \]  
Set Variable \[ $r ; Value: MBS ("[DynaPDF.SetFont](DynaPDFSetFont.md)"; $pdf ; "Helvetica"; 0; 20) \]  
Set Variable \[ $r ; Value: MBS ("[DynaPDF.WriteText](DynaPDFWriteText.md)"; $pdf ; 100; 100; "Hello World") \]  
Set Variable \[ $r ; Value: MBS ("[DynaPDF.EndPage](DynaPDFEndPage.md)"; $pdf ) \]  
\#   
\# save back to same file   
Set Variable \[ $r ; Value: MBS ("DynaPDF.OpenOutputFile"; $pdf ; "/Users/cs/Temp/Installation.pdf") \]  
Set Variable \[ $r ; Value: MBS ("[DynaPDF.Save](DynaPDFSave.md)"; $pdf ) \]  
\#   
\# cleanup   
Set Variable \[ $r ; Value: MBS ("[DynaPDF.Release](DynaPDFRelease.md)"; $pdf ) \]  
### See also

- [DynaPDF.FlushPages](DynaPDFFlushPages.md)
- [DynaPDF.HaveOpenDocument](DynaPDFHaveOpenDocument.md)
- [DynaPDF.ImportPDFFile](DynaPDFImportPDFFile.md)
- [DynaPDF.ImportPDFPage](DynaPDFImportPDFPage.md)
- [DynaPDF.New](DynaPDFNew.md)
- [DynaPDF.OpenPDFFromContainer](DynaPDFOpenPDFFromContainer.md)
- [DynaPDF.OpenPDFFromFile](DynaPDFOpenPDFFromFile.md)
- [DynaPDF.Release](DynaPDFRelease.md)
- [DynaPDF.SaveAndSignFileExt](DynaPDFSaveAndSignFileExt.md)
- [Path.FileMakerPathToNativePath](PathFileMakerPathToNativePath.md)

### Example Databases

- [DynaPDF/Add Page Links](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/DynaPDF/Add%20Page%20Links.shtml#2ScriptAnchor_)
- [DynaPDF/Form/Form](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/DynaPDF/Form/Form.shtml#4ScriptAnchor_)
- [DynaPDF/Merge PDFs](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/DynaPDF/Merge%20PDFs.shtml#2ScriptAnchor_)

### Blog Entries

- [MBS FileMaker Advent calendar - Door 6 - Sending Out Wishlist Forms](https://www.mbsplugins.de/archive/2024-12-06/MBS_FileMaker_Advent_calendar_/monkeybreadsoftware_blog_filemaker)
- [Add page links for FileMaker](https://www.mbsplugins.de/archive/2022-06-18/Add_page_links_for_FileMaker/monkeybreadsoftware_blog_filemaker)
- [PDF Forms with MBS Plugin](https://www.mbsplugins.de/archive/2018-04-21/PDF_Forms_with_MBS_Plugin/monkeybreadsoftware_blog_filemaker)
- [Optimize PDF Script](https://www.mbsplugins.de/archive/2016-01-19/Optimize_PDF_Script/monkeybreadsoftware_blog_filemaker)

### FileMaker Magazin

- [Ausgabe 1/2022, Seite 21](https://filemaker-magazin.de/neuigkeit/4172-Appetithappen-FMM_202201)
- [Ausgabe 1/2022, Seite 19](https://filemaker-magazin.de/neuigkeit/4172-Appetithappen-FMM_202201)

This function checks for a license.

Created 18th August 2014 , last changed 6th June 2024

  
[DynaPDF.New](DynaPDFNew.md) - [DynaPDF.OpenOutputFileEncrypted](DynaPDFOpenOutputFileEncrypted.md)

[HTML Version](DynaPDFOpenOutputFile.shtml)