SAP Knowledge Base Article - Public

2892364 - Failed to Load PDF Document Error While Generating PDF file via Custom Code

Symptom

You have created a custom action from SDK (for eg: GenerateSummary) to generate custom PDF templates. While executing this custom action via PDI code the file get's corrupted and if you try to open the document you will receive the below error:-

Failed to Load PDF Document.

Environment

SAP Cloud for Customer

SAP Business ByDesign

SAP Cloud Application Studio

Reproducing the Issue

  1. Login to frontend UI.
  2. Navigate to the screen where you have done the custom development.
  3. Perform the actions as per your requirement to Generate the PDF document.
  4. This will call the custom code written to generate the document.
  5. The action will be completed successfully but the PDF generated is corrupted.
  6. Upon opening the file, message Failed to Load PDF Document pop's up.

Cause

This issue happens when there is a context switch from the standard BO to custom BO ( custom BO's after modify which eventually calls the GenerateSummary action) due to a cross BO call. Then in the custom BO you try to modify entities of the standard BO where it started from (Creating an attachment folder on standard BO).

Resolution

In case the GenerateSummary action is triggered from the UI there is no context switch, therefore determinations of attachment folder are called. The attachment folder and content is then generated as required.

Below are the suggestions to overcome this issue:-

1. You can use UI button to call custom BO's action, as this scenario works.
2. In case you need to create an attachment while saving a standard BO, you can move the creation of the attachment folder to a custom action on the standard BO itself.
3. If you want to have only one action to Generate an attachment, then follow point #2 and call that action from the UI button.

Keywords

Failed to Load PDF Document Cannot generate PDF document Unable to open custom PDF attachment attachment creation not working via SDK Custom generated PDF error , KBA , unable to previewcustom form , custom pdf error , generation of pdf file corrupt , AP-RC-BDS-SCR , ByDesign Studio Scripting (ABSL) , AP-RC-BDS-BO , ByDesign Studio BO definition/generation , AP-RC-BDS-OM , ByDesign Studio Output Management(Forms) , Problem

Product

SAP Business ByDesign all versions ; SAP Cloud Applications Studio all versions ; SAP Cloud for Customer add-ins all versions ; SAP Cloud for Customer core applications all versions