Merge Multiple Adobe Forms into 1 PDF Content
Sometimes we get requirements from clients to combine multiple PDF output documents into 1 document similar to PDF Merge functionality provided by 3rd party tools. This blogs talks about the steps to achieve the same without storing the files on Application server and running UNIX commands to run a script to merge them.
Call the FP_JOB_OPEN function module with below parameters
* Call abode with structure gs_frm_interface and get the PDF
fp_outputparams–device = ‘PRINTER’.
fp_outputparams–dest = ‘PDF’.
fp_outputparams–nodialog = abap_true.
fp_outputparams–preview = abap_false.
fp_outputparams–getpdf = abap_true.
fp_outputparams–reqnew = abap_true.
fp_outputparams–preview = ‘ ‘.
fp_outputparams–assemble = ‘X’.
fp_outputparams–bumode = ‘M’. ” This is Bundle Mode
fp_outputparams–getpdf = ‘M’. ” This should be set to M, compare to regular value X being ” passed
* Sets the output parameters and opens the spool job
CALL FUNCTION ‘FP_JOB_OPEN’ “& Form Processing: Call Form
ie_outputparams = fp_outputparams
cancel = 1
usage_error = 2
system_error = 3
internal_error = 4
OTHERS = 5.
IF sy–subrc <> 0.
* <error handling>
Get the Adobe Form function Module using FP_FUNCTION_MODULE_NAME and Call the function module for your 1st Adobe Form.
Get the Adobe Form function Module using FP_FUNCTION_MODULE_NAME and Call the function module for your 2nd Adobe Form.
Make sure you call all the Adobe form Function module, as many as you want here.
Call the FP_JOB_OPEN as you would do normally
Use the Function module ‘FP_GET_PDF_TABLE’ to get the Merged PDF content, as shown below
DATA pdf_table TYPE tfpcontent.
DATA la_pdf LIKE LINE OF pdf_table.
CALL FUNCTION ‘FP_GET_PDF_TABLE’
e_pdf_table = pdf_table.
READ TABLE pdf_table INTO la_pdf INDEX 1.
IF sy–subrc EQ 0.
e_pdf_content = la_pdf.
* Raise Appropriate Error
The PDF content will now have all the Adobe forms PDF content merged into 1 PDF content, and this can used to display in Webdynpro or downloaded to you desktop.
What is the type of e_pdf_content and how to use it in the functions?
e_pdf_content is of table type RAWSTRING . It contains the PDF Content in RAWSTRING format. You can use this PDF content in function like a) Download b) Display PDF in Webdynpro by assigning the data source for an Adobe UI element.
Please post code for download same pdf on desktop
Thanks for writing this blog. In my opinion, In Step 5: if you read pdf_table with index 1, it will only consider the 1st PDF, not the 2nd one. pdf_table table will return Y no of rows for Y no of individual PDF forms to be merged.
I had a similar requirement to merge multiple PDF to single one and write it to application directory. For that I had to implement note 2264208. This contains rectification of class CL_RSPO_PDF_MERGE.
Then perform the below steps.
DATA: lo_pdf_merger TYPE REF TO cl_rspo_pdf_merge,
lv_rc TYPE i.
CREATE OBJECT lo_pdf_merger.
LOOP AT pdf_table INTO la_pdf.
lo_pdf_merger->add_document( la_pdf ).
* Call kernel method to merge the specified PDF files.
lo_pdf_merger->merge_documents( IMPORTING merged_document = e_pdf_content
rc = lv_rc ).
Now e_pdf_content will contain the XSTRING/RAWSTRING value of the merged PDF and you can use this to download or write to application directory.
Thanks Biswas , for your Valuable comments.
In the scenario i was trying to merge multiple PDF contents into 1 PDF , and that is the reason why we use READ table INDEX 1 . The Main purpose is to get all the PDF contents merged into single PDF content. So you should not see more than entry in the PDF content table.
Thank you for mentioning about the OSS note 2264208 and Class CL_RSPO_PDF_MERGE.
I have digital signature in my each pdf file. After implemented your code..multiple forms are merging but digital signature is not flowing in my final output.
hello dj, did you found the solution?
Please reply..its bit urgent
Did you try the Class that Sugato Biswas was trying to mention. Please check of the cl_rspo_pdf_merge method of merging will resolve your issue with signature.
Hi Kishore, I have not dealt with merging PDF's with Signatures. Not 100% sure why you would not get the signature in the merged document. Please reach out to SDN with this question, you might get some answers.
I know, the thread is already quite old, but one information could be helpful for others with the same problems regarding signed pdf documents.
It's not possible, that a signature of a pdf document remains or remains valid after a change of the document. The signature ensures, that the pdf document was not modified after the signing.
Thank you very much for these amazing contribution!.
It's something we are currently need to solve - which will be really really helpful for me 🙂 🙂 :).
Only one question may rise for me: Would the logic above work with PDF/A files?.
It'd be just awesome!!!!.
If not...do you have a clue how might be possible to reach it??
Thank you so much in advance!.