Skip to Content
Author's profile photo Suresh Kumar Karri

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.

Step1: 

Call the FP_JOB_OPEN function module with below parameters

*   Call abode with structure gs_frm_interface and  get the PDF
fp_outputparamsdevice     ‘PRINTER’.
fp_outputparamsdest         ‘PDF’.
fp_outputparamsnodialog  abap_true.

fp_outputparamspreview   abap_false.
fp_outputparamsgetpdf     abap_true.
fp_outputparamsreqnew   abap_true.

fp_outputparamspreview    ‘ ‘.

fp_outputparamsassemble  ‘X’.
fp_outputparamsbumode   ‘M’.       ” This is Bundle Mode
fp_outputparamsgetpdf      ‘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
CHANGING
ie_outputparams fp_outputparams
EXCEPTIONS
cancel          1
usage_error     2
system_error    3
internal_error  4
OTHERS          5.
IF sysubrc <> 0.
*            <error handling>
ENDIF.

 

STEP2:

Get the Adobe Form function Module using FP_FUNCTION_MODULE_NAME and Call the function module for your 1st Adobe Form.

 

STEP3:

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.

 

STEP4:

Call the FP_JOB_OPEN as you would do normally

 

Step 5:

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’
IMPORTING
e_pdf_table pdf_table.

READ TABLE pdf_table INTO la_pdf INDEX 1.
IF sysubrc EQ 0.
e_pdf_content la_pdf.
ELSE.
* Raise Appropriate Error
ENDIF.

 

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.

Assigned Tags

      10 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Isil Kobak
      Isil Kobak

      What is the type of e_pdf_content and how to use it in the functions?

      Author's profile photo Suresh Karri
      Suresh Karri
      Blog Post Author

      Hi Isil,

       

      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.

      Author's profile photo Digvijay Inamdar
      Digvijay Inamdar

      Hi Suresh,

      Please post code for download same pdf on desktop

      Author's profile photo Sugato Biswas
      Sugato Biswas

      Hi Suresh,

      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.

      DATAlo_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 ).
      ENDLOOP.

      * Call kernel method to merge the specified PDF files.
      lo_pdf_merger->merge_documentsIMPORTING 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.

      Author's profile photo Suresh Karri
      Suresh Karri
      Blog Post Author

      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.

       

      Suresh Karri

      Author's profile photo DJ Kishore
      DJ Kishore

      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.

      Author's profile photo Akshay Rana
      Akshay Rana

      hello dj, did you found the solution?

      Author's profile photo DJ Kishore
      DJ Kishore

      Please reply..its bit urgent

      Author's profile photo Suresh Karri
      Suresh Karri
      Blog Post Author

      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.

       

      ++

      Author's profile photo Suresh Karri
      Suresh Karri
      Blog Post Author

      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.