PDFlib Cookbook


All Topics Overview

Block Handling and PPS

block_below_contentsFill PDFlib blocks so that they are placed below the imported page.
business_cardsOutput an imported PDF page several times, with its blocks being filled with different personalized data.
clone_blocksClone Blocks from another document. Use POCA to copy a modified Block.
create_blocks_with_pocaCreate PDFlib Blocks with the POCA interface.
dump_block_propertiesDump block information from an existing PDF document.
duplicate_blockDuplicate a PDFlib block to any number of pages.
fill_converted_formfieldsOutput an imported PDF page with its blocks being filled with different personalized data.
linked_textblocksLink multiple Textflow blocks.
nested_blocksCreate nested blocks.
override_block_rectangleFill some blocks of an imported PDF page while changing the rectangle coordinates.
pdfvt1_with_blocksCreate a large number of invoices in a single PDF and make use of PDF/VT-1 features.
query_block_colorQuery the background color of blocks.
query_block_propertiesImport a PDF page containing blocks, and query various block properties.
starter_blockImport a PDF page containing blocks, and process all blocks.


blendmodeDemonstrate all blend modes which are available in PDF.
color_gradientFill some area or text with a smooth transition from one color to another.
colorAll_for_cropmarksCreate crop marks which will be visible on all color separations, using the special color "All".
colorize_image_with_DeviceN_colorCreate a DeviceN color space based on two Pantone spot colors to colorize a 2-channel image in raw format.

Define and use several DeviceN colors.

iccprofile_to_imageAssign an ICC profile to an image.
overprintDemonstrate overprint controls using CMYK and DeviceN colors or blend modes.
recombine_color_channelsColorize images and place all colorized images on top of each other.
softmaskCreate a soft mask based on arbitrary geometric objects.
spot_colorDefine and use several spot colors.
spot_color_shadingDefine and use several spot colors as shading.
starter_colorDemonstrate the basic use of supported color spaces.
svg_color_extensionLoad SVG graphics using extended color and fit into a box.
web_colornamesView a list of all cross-browser colors including the color name and hexadecimal color value as well as the corresponding RGB color values used in PDFlib.

Complex Scripts

arabic_formattingArabic formatting issue.

How to create several variants of Bidi output.

gajij_eudcDemonstrate the use of SING and EUDC fonts for merging a Gaiji character into an existing font.
starter_shapingDemonstrate text shaping for Arabic, Hebrew, Devanagari, and Thai scripts. Right-to-left text is reordered according to the Bidi algorithm.

Document Interchange

control_nexpress_traysFor NexPress digital color printing machines, create some special kind of annotations to control the input tray.
embed_xmpEmbed custom XMP metadata in a document.
import_xmp_from_pdfRetrieve the XMP metadata from an imported document and write all document-level XMP metadata to the output PDF.

Fonts and Encodings

barcode_fontOutput text in a barcode font.
character_referencesDemonstrate the usefulness of character references, using a suitable font.
escape_sequencesUse escape sequences in text lines to output octal or hexadecimal values.
font_infoGet various properties of a font such as font name, font style, or encoding.
font_metrics_infoGet various font related metrics such as the ascender or descender.
font_resourcesConfigure font resources and search for fonts.
glyph_availabilityCheck the availability of glyphs in a font.
glyph_replacementShow the effects of glyph substitution in case of glyphs missing in the font.

Demonstrate the use of OpenType features for CJK fonts and text.

opentype feature testerDemonstrate all supported typographic OpenType features after checking whether a particular feature is supported in a font.
retain_fontPerformance benefits of keeping a font open across multiple documents.
simulated_fontstylesCreate simulated italic or bold text output.
starter_fallbackStarter sample for fallback fonts

Demonstrate various typographic OpenType features after checking whether a particular feature is supported in a font.

starter_type3fontCreate a simple Type 3 font from vector data.
type3_bitmaptextCreate a simple Type 3 font from image data.
type3_rasterlogoCreate a Type 3 font which contains a single logo derived from an image.
type3_subsettingDemonstrate Type 3 font definition, use, and subsetting.
type3_turkish_characterCreate a Type 3 font by cloning another font and adding a further glyph.
type3_vectorlogoCreate a Type 3 font which contains a single logo derived from a vector based PDF page.

General Programming


Produce an AES-256-encrypted document with a master password that contains Thai characters and ligatures.

error_handlingDemonstrate different strategies with respect to exception handling.
initial_viewDefine the initial viewing properties for a document, such as zoom, page number, navigation tab, or title bar.
license_keyApply your PDFlib license key using various methods to get rid of the demo stamp.
metric_topdown_coordinatesOutput text using metric coordinates in a topdown coordinate system.
permission_settingsChange the permission settings so that only commenting the PDF is allowed.
repeated_contentsCreate contents which are used identically on multiple pages, such as fixed headers or footers.
starter_basicCreate some simple text, vector graphics and image output.
starter_pvfCreate a PVF file which holds an image or PDF, and import the data from the PVF file.

Geospatial PDF

georeferenced imageAttach geospatial reference data to an image.
starter_geospatialImport an image with a map and add geospatial reference information.



Path object like an arrow, electrical symbol etc. is attached at a line by an attachment point and with an alignment.

arrowsCreate an arrow using different methods.

Example for a path object: An arrow with rounded arrow head, with two attachment points.

clippingDemonstrate the effect of the different PDF clipping rules.
crop_marksCreate crop marks which specify the "cutting area".
dashed_linesCreate some dash patterns to be used as line styles.
fill_patternDefine some hatching patterns and use them to fill arbitrary shapes.
fill_rulesDefine some overlapping vector graphics and fill them using various methods.
hierarchical_layersDefine a layer hierarchy using the parent and child options.
layers_and_bookmarksDefine two layers and hide or show them via bookmarks.
overprinting_textCreate text which will overprint other page contents instead of knocking it out.
path_objectsCreate various shapes with path objects.
rounded_rectangleCreate some rectangle with the corners being rounded.
stamp_on_print_layerPlace a stamp on a layer which is only visible upon printing.
starter_graphicsCreate some basic examples of vector graphics.
starter_layerDefine several layers, output images and text into them and define particular layers to be visible when opening the document.
starter_pathStarter sample for path objects: Create some basic examples of path object construction and use.
starter_svgLoad SVG graphics and fit into a box.
transparent_graphicsCreate some transparent graphics objects.


align_text_at_imageAlign text at an image.

Demonstrates the use of an integrated alpha channel in TIFF and/or PNG images.

center_image_on_cardPlace an image on an imported PDF card.
display_image_partiallyDisplay an image partially.
frame_around_imageDraw a frame around an image.
image_dimensionsGet the dimensions of an image for various purposes.
image_from_urlRead an image from an URL and place it in a PDF document.
image_maskPlace an image with a mask applied to it.
image_rounded_cornersPlace an image with rounded corners.
integrated_clipping_pathPlace an image with its integrated clipping path being applied to it.
multi_page_tiffConvert an input TIFF image containing one or more frames to PDF.
starter_imageLoad and place an image using various options for scaling and positioning.
tiling_patternDefine a tiling pattern containing an image and use it to cover the page background with tiles.
transparent_imagesCreate transparent images.

Interactive Elements

acrobat_menu_itemsUpon opening the page, create a full list of all menu item names in Acrobat.
barcode_fieldCreate the three types of barcode fields that Acrobat supports.
form_and_layersDefine two layers for English or German contents and hide or show them via form field buttons.
form_checkboxCreate four form fields of type "checkbox".
form_comboboxCreate a form field of type "combobox" for choosing an item from a list or changing an existing item.
form_listboxCreate a form field of type "listbox" for choosing an item from a list.
form_multiline_textfieldCreate a form field of type "textfield" for entering multiline text.
form_pushbuttonCreate two form fields of type "pushbutton" for executing the "Print" and "Save As" commands.
form_radiobuttonCreate a field group with three form fields of type "radiobutton".
form_tab_orderDefine the position of each form field in the tab order, i.e. when the user presses the "Tab" key.
form_textfield_fill_with_jsFill a form text field with a value using JavaScript.
form_textfield_heightDetermine the height of a form field of type "textfield" with respect to the font size and vice versa.
form_textfield_input_checkCheck if the date entered in a form field of type "textfield" has been formatted correctly.
form_textfield_input_formatFormat the data entered in a form field of type "textfield" according to the rules defined.
form_textfield_layoutSpecify the layout of a form field of type "textfield" for displaying a date.
form_triggers_js_actionsDemonstrate all possibilities to trigger a JavaScript action from a form field.
link_annotationsOn images and text lines, create links to open PDF files or Web pages, or to execute a JavaScript.
movie_annotationsDemonstrate the use of a movie annotation in PDF.
nested_bookmarksCreate bookmarks which are nested in several levels.
starter_portfolioPackage multiple PDF and other documents into a PDF portfolio.
triggers_for_javascript_actionsDemonstrate all possibilities to trigger a JavaScript action (except of form fields).


javascript_for_3d_animationLoad a PRC 3D model and animate it with JavaScript.
javascript_for_3d_cameraJavaScript for 3D camera: Load a PRC 3D model and align camera with JavaScript.
starter_3dCreate a 3D model and load it into a U3D annotation.


crop_pageCrop an A4 page to an A5 page.
insert_tocCreate some pages, assign labels to them and insert a table of contents at the beginning of the document.
page_sizesCreate some pages with various page sizes.
page_x_of_yCreate a running footer "Page x of y" on each page of the document.
reverse_page_orderCreate pages in reverse page order.


clone_pdfaClone PDF/A and PDF/X standard documents.
images_to_pdfa2bConvert grayscale, CMYK or RGB image files in TIFF or JPEG formats to PDF/A-2b, taking care of color space issues.
pdfa2a_invoiceCombined PDF/UA-1 and PDF/A-2a invoice generation demo.
pdfa_extension_schemaDemonstrate the use of an XMP extension schema as defined in PDF/A-1.
pdf_extension_schema_with_typeDemonstrate the use of a complex XMP extension schema as defined in PDF/A-1.
starter_pdfa1bCreate a PDF/A-compliant output.
starter_pdfa2bCreate PDF/A-2b conforming output with layers, transparency and PDF/A attachments.
text_to_pdfa2bOutput text conforming to PDF/A-2b, taking care of color space and font issues.
transparent_stamp_for_pdfa1Apply a transparent stamp to an existing PDF/A-1 document while maintaining PDF/A-1 conformance.
zugferd_invoiceCreate a PDF/A-3b ZUGFeRD invoice from scratch.
zugferd_add_xml_to_pdfaZUGFeRD: Add XML Invoice to PDF.


clone_pdfuaClone PDF/A, PDF/UA and PDF/X standard documents.
merge_and_stamp_pdfuaMerge PDF/UA documents including the document structure trees. Additional text is stamped onto each page and tagged as Artifact.

Create PDF/UA-1 document with various content types including structure elements, artifacts, and interactive elements.

tag_out_of_orderDemonstrate how to create Tagged PDF out of order.
tag_parallel_columnsDemonstrate how to tag multiple columns in parallel with activate_item().
tagged_form_fieldsCreate accessible form field according to PDF/UA.
tagged_invoiceDemonstrate combined PDF/UA-1 and PDF/A-2a invoice generation.
tagged_listDemonstrate list tagging.
tagged_pdf_with_textflowCreate a Tagged PDF containing a Textflow with appropriate structure elements on several pages.
tagged_scan_with_ocr_textTagging for invisible OCR text which accompanies a scanned page.
tagged_tableDemonstrate automatic table tagging.


starter pdfvt1Create a large number of invoices in a single PDF and make use of PDF/VT-1 features.
starter pdfvt2Create a large number of invoices in a single PDF and make use of PDF/VT-2 features.
starter pdfvt2sThis variation of the starter_pdfvt2 wraps the data into a PDF/VT-2s-compliant MIME package, according to ISO 16612-2:2010 specification, Annex A



clone_pdfxClone PDF/A and PDF/X standard documents.
starter_pdfx3Create a PDF/X-3-compliant output.
starter_pdfx4Create PDF/X-4 conforming output with layer variants and transparency.
starter_pdfx5gCreate PDF/X-5g conforming output with a reference to an external page.
starter_pdfx5nCreate PDF/X-5n conforming output with an image and DeviceN color.

PDF Import

clone_page_boxesClone the ArtBox, TrimBox, BleedBox, CropBox, and MediaBox entries of an imported PDF page.
crop_imported_pagesCrop the pages of an existing PDF document.
import_in_reverse_orderRead the pages of an input PDF document and output them in reverse order.
import_pages_into_layersImport two pages and output them on two layers on the same page.
import_repeated_contentsIn order to keep the output file size as small as possible handles to imported PDF pages or images can and should be reused for repeated contents.
split_documentSplit PDF document in separate output documents where each output document contains a range of one or more pages from the input document.
import_pages_into_layersImport two pages and output them on two layers on the same page.
starter_pdfmergeMerge pages from multiple PDF documents.
starter_pcosDump information from an existing PDF document.
rotate_pagesRotate the pages of an existing PDF document.
stamp_pagesPlace a stamp on the pages of an existing PDF document.
pdfimposeImport all pages from one or more existing PDFs, and place c x r pages on each sheet of the output PDF (imposition).
scale_down_imported_pagesPlace A4 pages from an imported PDF as A5 pages in the output document.

PDF on the Web Server

starter_webformCreate a linearized PDF which is encrypted and contains some form fields.


align decimalsAlign decimal numbers in a table.
colorize_cellsProvide some table cells with a colored background.
fit_formfield_into_cellFit a form field into a table cell, e.g. to create a pushbutton in the cell.
mixed_table_contentsDemonstrate how to place various kinds of contents in table cells spanning one or more columns or rows.
nested_tablesPlace a sub-table in one table cell.

Show how table cell contents will be repeated on the next table instance if a cell or a row is split.

spread_oversized_tableOutput a table on 2 x m pages as it is needed to fit it completely.

Use the continue option of add_table_cell() to continue a Textflow in another cell.

starter_tableCreate table which may span multiple pages.
table_contact_sheetCreate a contact sheet with photos and their labels.
table_invoiceCreate an invoice using the table feature.
table_rotated_textCreate a table containing rotated text.
table_row_heightDefine the height of the rows in a table.
table_scheduleCreate a weekly booking plan for the meeting rooms of a company.
table_timesheetCreate a monthly time sheet for the working hours of an employee.
vertical_text_alignmentDemonstrate the vertical alignment of text lines and Textflows in a table cell.

Text Output

avoid_linebreakingCreate a Textflow and define various options for line breaking.
bulleted_listOutput numbered and bulleted lists.

Insert a dot sequence automatically at the end of a textflow fitbox after the last word which can be showed together with the dots completely inside the fitbox.

create_interactive_indexIn a Textflow define some terms to be indexed and create a sorted index from the indexed terms.
current_text_positionDemonstrate how the current text position can be used to output simple text, text lines, or Textflows next to one another.
distance_between_paragraphsControl the distance between adjacent paragraphs.
dot_leaders_with_tabsUse leaders to fill the space defined by tabs between left-aligned and right-aligned text, such as in a table of contents.
drop_capsCreate an initial drop cap at the beginning of some text.
footnotes_in_textCreate footnotes (superscript text) in a Textflow provided with links to jump to the footnote text.
image_as_text_fill_colorCreate outline text and fill the interior of the glyphs with an image.
invisible_textOutput invisible text on top of an image.
keep_lines_togetherControl the lines kept together on the page.
leaders_in_textlineUse dot leaders to fill the space between text and a page number such as in a table of contents.
numbered_listOutput numbered lists with the numbers left- or right-aligned.
process_utf8Read text in the UTF-8 format and output it.
rotated_textCreate text output which does not run  horizontally, but at some angle.

Create a shadowed text line with the shadow option of fit_textline.

simple_stampCreate a stamp across the page which runs diagonally from one edge to the other.
starter_textflowCreate multi-column text output which may span multiple pages.
starter_textlineDemonstrate various options for placing a text line.
tabstops_in_textCreate a simple multi-column layout using tab stops.
text_as_clipping_pathOutput text filled with an image.
text on a pathCreate text on a path.
text_on_colorPlace a text line and a Textflow on a colored background.
text_with_image_clipping_pathUse the clipping path from a TIFF or JPEG image to shape text output.
textflow_with_shadingCreate multi-column output with text and use a shading where the geometry of each shading matches the respective text column.
transparent_part_of_textUse gstate in Textflow, e.g. for transparency/opacity.
transparent_textCreate some transparent text.
underlined_textCreate underlined text.
vertical_alignment_in_fitboxControl the vertical alignment of text in the fitbox.
watermarkCreate an editable watermark.
weblink_in_textCreate a Textflow and integrate colorized Web links in the text.
widows and orphansCreate multi-column text output which may span multiple pages.
wrap_text_around_imagesPlace images within a Textflow.
wrap_text_around_polygonsUse arbitrary polygons as wrapping shapes for text to wrap around.