Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I include another PDF in CFDOCUMENT?

I have a PDF generated in Coldfusion. I would like to add pages from another PDF sitting in the folder. I've checked cfpdf, but it doesn't seem to be the way to go. Is there a way to do this?

<cfdocument format="PDF" fontEmbed = "yes" pageType="A4" margintop="0.2" marginbottom="0.1" marginleft="0.2" marginright="0.2">
        <cfinclude template="header.inc">
        ... content ....
        pages 2nd PDF should be here
</cfdocument>
like image 362
Kokesh Avatar asked Feb 27 '26 14:02

Kokesh


2 Answers

Here in its simplest form is how to append an existing PDF on disk to a dynamically created PDF and serve it to the browser without writing anything new to the physical or virtual file system.

<!--- Create a new PDF and store it in a variable called newPdf --->
<cfdocument format="PDF" name="newPdf">
  Content of new PDF here. Content of an existing PDF to be appended below.
</cfdocument>

<!--- Append to the new PDF the contents of the existing PDF located in the same folder as this script and store it in a variable called mergedPdf --->
<cfpdf action="merge" name="mergedPdf">
    <cfpdfparam source="newPdf">
    <cfpdfparam source="existing.pdf">
</cfpdf>

<!--- Output the merged PDF to the browser --->
<cfcontent type="application/pdf" variable="#ToBinary( mergedPdf )#" reset="true">

(You might want to add a <cfheader> to suggest how the PDF should be handled by the browser, ie inline or attachment.)

like image 95
CfSimplicity Avatar answered Mar 02 '26 16:03

CfSimplicity


Take a look at the action="merge" attribute of cfpdf.

like image 20
Richard Herbert Avatar answered Mar 02 '26 14:03

Richard Herbert



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!