I'm using FM12 and have a script setup to export to PDF, successfully working and combining all necessary pages. What I want to do is insert a PDF before the first page. It will always be the same PDF file.
Use Insert FIle to insert a copy of your PDF into a container field. Then use Export FIeld Contents to export it to $filePath. This generates a copy of your pre-existing PDF at the location where you will save your new PDF and with the name of the new PDF file. Do that after the Set variable step and before the first save as PDF step. Then make your first Save as PDF step an "append" save as PDF just like you show in the last step.
Many thanks for that.
Could you provide a bit more detail please?
Are all of those steps done on the script writing section? It's the container field bit I don't understand, and I cannot find the Export Field Contents option either.
I think that I've got somewhere. I've managed to set a container field on the page and have inserted pdf and exported fields to $filepath. It seems to work, but in place of showing the PDF it shows an icon of a PDF file snd the filename below it.
Thank you, by the way.
That's what it should show if you used insert file and does it really matter? (Insert PDF could be used in FMP12 and if you optimize the container field for interactive content, but the results are the same.) The container field just serves as a temporary holder for your file while making a copy of it.
I don't think I explained it right.
I'm not bothered about it showing an icon inside FM, but it still only shows an icon in the exported PDF. So, page 1 of the PDF is a blank page with the icon of a PDF file and the filename on it.
What am I doing wrong?
Can you post the script you are using?
To post a script to the forum:
For some unknown reason I didn't get an email saying I had a response, I just stumbled across this through Google.
Printing: Print | Print Energy Survey Report to pdf
[ $filepath ; Value: Get ( DesktopPath )
& Branches::Energy Survey Title
& ".pdf" ]
[ Orientation: Portrait; Paper size: 8.26" x 11.69" ]
[ Restore; No dialog ]
Go to Related Record
[ From table: “Branches”; Using layout: “Print 01 ES Cover Page” (Branches) ]
[ Show only related records ]
Save Records as PDF
[ File Name: “$filepath” ; Current record ]
Document - Title: /*Branches::Print_report_title*/; Compatibility: Acrobat 5 and later ]
Pages - Number Pages From: 1; Include: All pages ]
Security - Printing: High Resolution ; Editing: Any except extracting pages ; Enable copying ; Enable Screen Reader ]
Initial View - Show: Pages Panel and Page ; Page Layout: Single Page; Magnification: 100% ]
[ From table: “Zones”; Using layout: “Print 02 ES Summary Page” (Zones) ]
[ File Name: “$filepath” ; Records being browsed ]
[ Restore; Append; No dialog ]
[ From table: “Zones”; Using layout: “Print 04 ES Quotation” (Zones) ]
[ From table: “Zones”; Using layout: “Print 03 ES Lamp Data Sheets” (Zones) ]
[ From table: “Zones”; Using layout: “Print 05 ES Appendicies” (Zones) ]
Go to Layout
[ original layout ]
7 November 2012 20:21:01 Key Electrical v3.6.fmp12 - Print | Print Energy Survey Report to pdf -1-
Your script differs from my original suggestion--which was to store the cover page in a container field, but it should still work.
IF you insert Halt script immediately after the first Save As PDF script step and then examine the PDF, what do you see in the PDF file?
Apologies, I pasted the script from before I added the container field to start from a clean point, if that makes sense.
I will add that page again and repost.
This is a screenshot of the cover page after adding the other lines.
[ Branches::ExPDF ]
Storage method: Let user choose ]
Display content ]
Compression: Never compress ]
Export Field Contents
[ “$filePath” ]
7 November 2012 20:58:23 Key Electrical v3.6 - Copy.fmp12 - Print | Print Energy Survey Report to pdf -1-
The script should not need to use Insert File. You should need to only insert the file once manually or in a different script and then you can export from it as many times as you need to generate this report. But then maybe the user needs to be able to select the file to import.
Export Field Contents [ “$filePath” ]
is missing the name of the container field into which you inserted the PDF.
It should read:
Export Field Contents [ Branches::ExPDF ; “$filePath” ]
Note that Export Field Contents with a file path specified, but no field specified will delete any file of the name and location specified in the file path.
Thank you for all this help.
I've got it working perfectly, only it works two or three times then I have to insert the file into the container field again. What am I doing wrong?
Can't tell from what you have posted. If you have to insert into the container field again, either something is clearing the container field or you are not always referring to the same record each time.
There is the whole code to insert PDF:
publicstaticstring FolderName = "c:/";
privatevoid button1_Click(object sender, EventArgs e)
string fileName = FolderName + "Sample.pdf";
string fileNameAdd = FolderName + "add.pdf";
REDocument doc = REFile.OpenDocumentFile(fileName, new PDFDecoder());//use PDFDecoder open a pdf fileint pageCount = doc.GetPageCount();//get pdf's page count
Debug.WriteLine("Page Count: " + pageCount);
BasePage newPage = doc.CreateEmptyPage();//create a new page by REDocument
doc.AddPage(newPage, 2);//add a new page to REDocument
pageCount = doc.GetPageCount();//get new pdf's page count
Debug.WriteLine("Page Count: " + pageCount);
REFile.SaveDocumentFile(doc, fileNameadd, new PDFEncoder());//save new pdf
Retrieving data ...