
* lv_pdf_data contains the binary PDF data. (XSTRING)
DATA: ls_meta TYPE sfpmetadata,
lx_fpex TYPE REF TO cx_fp_runtime,
lo_fp TYPE REF TO if_fp,
lo_pdfobj TYPE REF TO if_fp_pdf_object.
* add metadata to PDF document
TRY.
"Create PDF Object.
lo_fp = cl_fp=>get_reference( ).
lo_pdfobj = lo_fp->create_pdf_object( connection = 'ADS' ).
lo_pdfobj->set_document( pdfdata = lv_pdf_data ).
"Set title.
ls_meta-title = 'My PDF File Title'.
lo_pdfobj->set_metadata( metadata = ls_meta ).
lo_pdfobj->execute( ).
"Get the PDF content back with title
lo_pdfobj->get_document( IMPORTING pdfdata = ls_stream-value ).
CATCH cx_fp_runtime_internal
cx_fp_runtime_system
cx_fp_runtime_usage INTO lx_fpex.
ENDTRY.
"'application/pdf' is required to inform the browsers that
"this is a PDF file so that it can be opened in the default
"PDF viewer of the browser.
ls_stream-mime_type = 'application/pdf'.
copy_data_to_ref( EXPORTING is_data = ls_stream
CHANGING cr_data = er_stream ).
"'Content-Disposition: inline' directs the browsers to preview
"the PDF instead of downloading the file.
"'filename' is required by Chrome to suggets the file name while downloading.
"IE does not respect the 'filename' with 'inline', but respects
"when Content-Disposition is 'attachemnt'
ls_lheader-name = 'Content-Disposition'.
ls_lheader-value = |inline; filename="MyFileName.pdf"|.
set_header( is_header = ls_lheader ).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
10 | |
7 | |
7 | |
5 | |
4 | |
4 | |
4 | |
3 | |
3 | |
3 |