I have used below visualforce code to display two pdf in a single page but in the result, I am getting two different PDFs with two sections with iframe.
Is it possible to combine these two PDFs in single PDF ?
mainPage
<apex:page renderAs="pdf">
<apex:include pageName="POC_PDF1"/>
<apex:include pageName="POC_PDF2"/>
</apex:page>
POC_PDF1
<apex:page >
This is PDF1
</apex:page>
POC_PDF2
<apex:page Controller="xyzController">
<iframe src="data:application/pdf;base64,{!pdf}" height="1000px" width="100%"/>
</apex:page>
Apex code :
public class xyzController {
public xyzController(ApexPages.StandardController controller){}
public ContentVersion conVersion {
get {
conVersion = [SELECT VersionData, FileType FROM ContentVersion WHERE ContentDocument.Title = 'PDF_081108' AND IsLatest = true];
return conVersion;
}
private set;
}
public String pdf {
get {
return EncodingUtil.base64encode(conVersion.VersionData);
}
}
}
Best Answer
Added based on comments
You need not use
iframe
. Instead you can return theurl
based onContentVerionId
and render image/pdf:pdf2 page:
its apex controller:
OLD ANSWER
iframe
will not work as it creates totally separateDOM
s. You should use apex:include which will:You can try with 2 options:
OPTION 1: Join 2 pages and then render as PDF
MainPage.vfp:
POC_pdf1.vfp:
POC_pdf2.vfp:
OPTION 2: Create 2 separate PDFs and join them in main page:
MainPage.vfp:
POC_pdf1.vfp:
POC_pdf2.vfp: