open-abap-pdf
A standalone PDF generator written in ABAP that builds a multi-page document from text, lines, rectangles and circles placed at given coordinates and returns it as a string or an xstring.
Builds a PDF in ABAP code with no other component: zcl_open_abap_pdf=>create( ) opens a document, add_page adds pages in A4, Letter or a custom size, text is set in Helvetica, Times-Roman or Courier, and lines, rectangles and circles are drawn in RGB colours, with each call returning the instance so they chain. render( ) returns the document as a string and render_binary( ) as an xstring. Every element is placed at coordinates the caller gives in points, with helpers that convert millimetres and inches, and the README says nothing about sending the result to a printer or a spool, which stays with the application. The README states the plan of running the same code on classic ECC, classic and embedded "Steampunk" and transpiled under open-abap, and open-abap.org lists it among its general-purpose, multi-target libraries.
Facts
Where it sits
Who is behind it
In the atlas: maintains 9@open-abapmaintainerLars HvamContributes to this
In the atlas: maintains 13, contributes to 92, wrote 1@larshp1 contributor
What it declares
Every artifact
- Type
- Package
- Origin
- By a community org
As a package
- Where it runs
- does not say
- Distributed through
- does not say
Connections
Producing printed forms, PDFs and filled templates for people
Download
README
quoted from open-abap/open-abap-pdf under MIT, readopen-abap-pdf
Standalone PDF generation in ABAP
Pull requests welcome
Plan is to have the same code run on:
- Classic ECC
- Classic Steampunk
- Embedded Steampunk
- open-abap/transpiled
Features
- Create multi-page PDF documents
- Add text with customizable fonts (Helvetica, Times-Roman, Courier)
- Set text, draw, and fill colors (RGB)
- Draw shapes: lines, rectangles, circles
- Fluent API for method chaining
- Support for A4, Letter, and custom page sizes
- Unit conversion helpers (mm to points, inches to points)
Usage
Basic Example
DATA(lo_pdf) = zcl_open_abap_pdf=>create( ).
lo_pdf->add_page( ).
lo_pdf->set_font( iv_name = 'Helvetica' iv_size = 24 ).
lo_pdf->text( iv_x = 50 iv_y = 50 iv_text = 'Hello World!' ).
DATA(lv_pdf_string) = lo_pdf->render( ).
Fluent API
DATA(lv_pdf) = zcl_open_abap_pdf=>create(
)->add_page(
)->set_font( iv_name = 'Helvetica' iv_size = 16
)->set_text_color( iv_r = 0 iv_g = 0 iv_b = 128
)->text( iv_x = 100 iv_y = 100 iv_text = 'Blue Text'
)->render( ).
Drawing Shapes
DATA(lo_pdf) = zcl_open_abap_pdf=>create( ).
lo_pdf->add_page( ).
" Draw a line
lo_pdf->line( iv_x1 = 50 iv_y1 = 100 iv_x2 = 200 iv_y2 = 100 ).
" Draw a rectangle (outline)
lo_pdf->rect( iv_x = 50 iv_y = 150 iv_width = 100 iv_height = 50 iv_style = 'D' ).
" Draw a filled rectangle
lo_pdf->set_fill_color( iv_r = 200 iv_g = 200 iv_b = 255 ).
lo_pdf->rect( iv_x = 50 iv_y = 220 iv_width = 100 iv_height = 50 iv_style = 'F' ).
" Draw a circle
lo_pdf->circle( iv_x = 300 iv_y = 200 iv_radius = 40 iv_style = 'DF' ).
DATA(lv_pdf) = lo_pdf->render( ).
Multiple Pages
DATA(lo_pdf) = zcl_open_abap_pdf=>create( ).
lo_pdf->add_page( ).
lo_pdf->set_font( iv_name = 'Helvetica' iv_size = 24 ).
lo_pdf->text( iv_x = 50 iv_y = 50 iv_text = 'Page 1' ).
lo_pdf->add_page( ).
lo_pdf->text( iv_x = 50 iv_y = 50 iv_text = 'Page 2' ).
DATA(lv_pdf) = lo_pdf->render( ).
Custom Page Size
" Letter size
lo_pdf->add_page(
iv_width = zcl_open_abap_pdf=>c_letter_width
iv_height = zcl_open_abap_pdf=>c_letter_height ).
" Custom size in mm (converted to points)
lo_pdf->add_page(
iv_width = zcl_open_abap_pdf=>mm_to_pt( 100 )
iv_height = zcl_open_abap_pdf=>mm_to_pt( 150 ) ).
API Reference
Class Methods
| Method | Description |
|---|---|
create( ) | Creates a new PDF document instance |
mm_to_pt( iv_mm ) | Converts millimeters to points |
inch_to_pt( iv_inch ) | Converts inches to points |
Instance Methods
| Method | Description |
|---|---|
add_page( iv_width, iv_height ) | Adds a new page (default A4) |
set_font( iv_name, iv_size ) | Sets the current font |
set_text_color( iv_r, iv_g, iv_b ) | Sets text color (RGB 0-255) |
set_draw_color( iv_r, iv_g, iv_b ) | Sets line/stroke color |
set_fill_color( iv_r, iv_g, iv_b ) | Sets fill color |
set_line_width( iv_width ) | Sets line width |
text( iv_x, iv_y, iv_text ) | Draws text at position |
line( iv_x1, iv_y1, iv_x2, iv_y2 ) | Draws a line |
rect( iv_x, iv_y, iv_width, iv_height, iv_style ) | Draws a rectangle |
circle( iv_x, iv_y, iv_radius, iv_style ) | Draws a circle |
render( ) | Returns PDF as string |
render_binary( ) | Returns PDF as xstring |
get_page_count( ) | Returns number of pages |
get_page_width( ) | Returns current page width |
get_page_height( ) | Returns current page height |
Constants
| Constant | Value | Description |
|---|---|---|
c_pt_per_mm | 2.83465 | Points per millimeter |
c_a4_width | 595.28 | A4 width in points |
c_a4_height | 841.89 | A4 height in points |
c_letter_width | 612 | Letter width in points |
c_letter_height | 792 | Letter height in points |
Shape Styles
| Style | Description |
|---|---|
D | Draw outline only (default) |
F | Fill only |
DF or FD | Draw outline and fill |
Supported Fonts
- Helvetica (default)
- Times-Roman
- Courier
Others providing
Compare all 8 on the Document output page →- abap2xlsxabap2xlsxA library that reads and generates .xlsx Excel workbooks directly from ABAP data, without exporting through a list viewer, installed through abapGit and tested from SAP_ABA 731.independent, abapLibrary that reads and generates Excel spreadsheets from ABAP
- zcl_docxzcl_docxAn ABAP class that fills a Word .docx template tagged with content controls, with a report, ZDOCX_GET_TYPES, that generates the ABAP types the template needs; the document opens in Word or returns as an xstring.independent, abapABAP class filling a tagged Word .docx template with data
- zcl_pdfzcl_pdfA standalone ABAP class that draws simple PDFs without Adobe Document Server: text in built-in fonts, text fitted into a box and rectangles, returned as a raw string to store, send or display.independent, abapStandalone ABAP class drawing PDFs without Adobe Document Server
- XTTXTTAn ABAP template engine that merges data, including nested structures, tables and trees, into Excel, Word, HTML and PDF templates prepared in ordinary editors with markers in curly brackets.independent, abapABAP template engine for Excel, Word, HTML and PDF
- SAP Forms Service by AdobeSAP Forms Service by AdobeAdobe Document Services on BTP: renders print and interactive PDF forms from stored templates, called over a REST API from a cloud application or connected to an ABAP system.sap official, btpAdobe Document Services on BTP for print and interactive PDFs
- HandlebarsABAPHandlebarsABAPA single-file Handlebars templating implementation for ABAP 7.40 SP02 and up that fills a template from an ABAP structure or table, with block helpers, partials and custom helpers.independent, abapSingle-file Handlebars templating for ABAP 7.40 SP02 and up
- SAP Spool PDFSAP Spool PDFAn ABAP class that submits a report to the spool, typically in the background, and converts the resulting spool request into a PDF it can return as an xstring, save, show or email.independent, abapSubmits an ABAP report to the spool and converts the output to PDF
Details
Sources
Sources are graph entities: the same page may back several entries, and an unreachable source flags every row that rests on it.
Compatibility and provenance
abaplint
Flavors
“Multi-target ABAP libraries. Run on ECC + Steampunk + Node.js” — open-abap.org
“Multi-target ABAP libraries. Run on ECC + Steampunk + Node.js” — open-abap.org
Contributors
History in the atlas
- First seen.
For your agent
- Ref
artifact:open-abap-open-abap-pdf- JSON
- /artifacts/open-abap-open-abap-pdf.json
- MCP
- Connecting an agent