Skip to content

furkancosgun/abap-html2pdf-generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“„ HTML2PDF_GENERATOR: ABAP HTML to PDF Conversion via JavaScript

πŸš€ Overview

This project provides a robust solution for generating high-quality, complex PDF documents directly from ABAP by leveraging client-side web technologies. It utilizes the power of html2pdf.js (which, in turn, uses html2canvas and jsPDF) within the SAP GUI's HTML Viewer control to convert rich HTML content into a Base64-encoded PDF string, which is then passed back to the ABAP backend.

This approach is highly effective for generating complex, styled reports that are difficult to achieve with standard SAP Smartforms or Adobe Forms technology alone, especially for dynamic, long-running documents.

✨ Key Features

  • Complex HTML Support: Easily generate styled reports using modern CSS, complex tables, lists, and custom layouts.
  • Dynamic Configuration: Supports configurable PDF options (format, orientation, unit) passed from the ABAP program to the JavaScript library.
  • ABAP Backend Integration: Securely posts the Base64-encoded PDF data back to the ABAP program using the SAPEVENT mechanism.
  • Library Agnostic: The core logic is encapsulated in a function module (ZHTML2PDF_GENERATE) for easy reusability.

πŸ’‘ Usage Example

To generate a PDF, you would call the main function module from your ABAP report, providing the HTML string as input.

REPORT z_your_custom_report.

DATA lv_html_content TYPE string.
DATA lv_binary       TYPE xstring.

* 1. Build your custom HTML string (e.g., from an internal table)
lv_html_content = |<h1>My Financial Report</h1><p>...</p>|.

* 2. Call the generator
CALL FUNCTION 'ZHTML2PDF_GENERATE'
  EXPORTING
    iv_content     = lv_html_content
    iv_format      = 'A4'       " Page format
    iv_orientation = 'portrait' " Page orientation
  IMPORTING
    ev_binary      = lv_binary  " XSTRING containing the final PDF
  EXCEPTIONS
    OTHERS         = 1.

IF sy-subrc = 0.
  * 3. Display or save the PDF binary data (e.g., using CL_GUI_FRONTEND_SERVICES=>GUI_DOWNLOAD)
ENDIF.

🀝 Contributing

Contributions are welcome! If you have suggestions for performance improvements, bug fixes, or advanced features, please submit a pull request or open an issue.

πŸ“œ License

This project is licensed under the MIT License - see the LICENSE file for details (You should create this file).

About

ABAP HTML to PDF Conversion via JavaScript

Topics

Resources

License

Stars

Watchers

Forks

Languages