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 Applications Studio
Reproducing the Issue
-
Login to frontend UI.
- Navigate to the screen where you have done the custom development.
- Perform the actions as per your requirement to Generate the PDF document.
- This will call the custom code written to generate the document.
- The action will be completed successfully but the PDF generated is corrupted.
- Upon opening the file, the 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 (e.g. custom BO's AfterModify 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 (e.g. 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 call the custom BO's action via a UI button/action placed on the screen.
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
PDI, SDK, 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, unable to preview, custom form, custom pdf error, generation of pdf file corrupt , KBA , 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
SAP Knowledge Base Article - Public