PDFlib Cookbook

cookbook

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 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 filled with different personalized data.
linked_textblocksLink multiple Textflow Blocks.
nested_blocksCreate nested Blocks.
override_block_rectangleFill 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.

Color

blendmodeDemonstrate all blend modes available in PDF.
blendmode_effectsDemonstrate all blend modes available in PDF.
colorAll_for_cropmarksCreate crop marks which will be visible on all color separations, using the special spot color "All".
color_gradientFill some area or text with a smooth transition from one color to another.
colorize_image_with_DeviceN_colorCreate a DeviceN color space based on two Pantone spot colors to colorize a 2-channel image in raw format.
devicen_colorDefine 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.
softmask_effectsCreate 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 all supported color spaces.
svg_color_extensionLoad SVG graphics using extended color and fit into a box.
web_colornamesCreate a list of all HTML 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 issues.
bidi_formattingCreate several variants of Bidirectional text output.
gaiji_eudcDemonstrate the use of SING and EUDC fonts for merging a Gaiji character into an existing font.
starter_shapingDemonstrate text shaping for Arabic, Hebrew, Hindi and Sanskrit scripts. Right-to-left text is reordered according to the Bidi algorithm.

Fonts

barcode_fontOutput text in a barcode font.
character_referencesDemonstrate character references.
font_infoQuery various properties of a font such as font name, font style, or encoding.
font_metrics_infoQuery various font-related metrics such as 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.
opentype_feature_testerDemonstrate all supported typographic OpenType features after checking whether a particular feature is supported in a font.
opentype_features_for_cjkDemonstrate the use of OpenType features for CJK fonts and text.
retain_fontPerformance benefits of keeping a font open across multiple documents.
simulated_fontstylesSimulate italic and bold text
starter_fallbackStarter sample for fallback fonts
starter_opentypeDemonstrate various typographic OpenType features after checking whether a particular feature is supported in a font.

Form Fields

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 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 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_synchronized_fieldsCreate multiple form fields of type 'textfield' with synchronized values
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 whether 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 specified rules
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.
starter_formfieldsCreate linearized PDF which is encrypted and contains some form fields.

General Programming

aes256_unicode_passwordCreate AES-256-encrypted document with a master password containing Unicode characters.
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 the 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 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.

Graphics

arrowsCreate an arrow using different methods.
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.
pdfclockCreate an analog clock with current time.
rounded_rectangleCreate a rectangle with rounded corners.
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_svgLoad SVG graphics and fit into a box.
transparent_graphicsCreate some transparent graphics objects.

Images

align_text_at_imageAlign text at an image.
alpha_channelDemonstrate 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 and apply a mask to it.
image_rounded_cornersPlace an image with rounded corners.
integrated_clipping_pathPlace an image and apply its integrated clipping path.
multi_page_tiffConvert a 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.
link_annotationsOn images and text lines, create links to open PDF files or Web pages, or to execute JavaScript.
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 JavaScript actions (except form fields).

Document Interchange

control_nexpress_traysFor NexPress digital color printing machines, create special 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.

Multimedia

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.
movie_annotationsDemonstrate a movie annotation in PDF.
starter_3dCreate a 3D model and load it into a U3D annotation.

Pagination

crop_pageCrop an A4 page to A5 format.
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 different 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.

Path Objects

aligned_path_objectsPath objects are attached at a line by an attachment point and with an alignment.
arrow_as_path_objectExample for a path object: arrow with rounded arrow head and two attachment points.
clippingDemonstrate the effect of different PDF clipping rules.
crop_marksCreate crop marks which specify the "cutting area".
import_path_from_imageImport a path object from an image file and use it for filling, stroking or clipping.
path_objectsCreate various shapes with path objects.
starter_pathStarter sample for path objects: create basic examples of path object construction and use.
svg_pathCreate a path object from a description in SVG path syntax.

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 place them on two layers on the same output page.
import_repeated_contentsIn order to keep the output file size small, handles to imported PDF pages or images should be reused for repeated contents.
rotate_pagesRotate the pages of an existing PDF document.
scale_down_imported_pagesPlace A4 pages from an imported PDF as A5 pages in the output document.
split_documentSplit PDF document in separate output documents where each output document contains a range of one or more pages from the input document.
stamp_pagesPlace a stamp on the pages of an existing PDF document.
starter_pcosDump information from an existing PDF document.
starter_pdfimposeImport all pages from one or more existing PDFs, and place c x r pages on each sheet of the output PDF (imposition).
starter_pdfmergeMerge pages from multiple PDF documents.

PDF/A

clone_pdfaClone PDF/A and PDF/X standard documents.
facturx_add_xml_to_pdfa3bFactur-X: Add XML invoice to PDF.
facturx_invoice_pdfa3bCreate a PDF/A-3b Factur-X invoice from scratch.
images_to_pdfa2bConvert grayscale, CMYK or RGB image files in TIFF or JPEG format to PDF/A-2b, taking care of color space issues.
invoice_pdfa2aCombined PDF/UA-1 and PDF/A-2a invoice generation demo.
starter_pdfa1bCreate output conforming to PDF/A-1b.
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.
xmp_extension_schema_pdfa2bDemonstrate an XMP extension schema for PDF/A-1.
xmp_extension_schema_with_type_pdfa2bDemonstrate a complex XMP extension schema for PDF/A-1.
zugferd1_add_xml_to_pdfa3bZUGFeRD 1: Add XML invoice to PDF.
zugferd1_invoice_pdfa3bCreate a PDF/A-3b ZUGFeRD 1 invoice from scratch.
zugferd2_add_xml_to_pdfa3bZUGFeRD 2: Add XML invoice to PDF.
zugferd2_invoice_pdfa3bCreate a PDF/A-3b ZUGFeRD 2 invoice from scratch.

PDF/UA

clone_pdfuaClone PDF/A, PDF/UA and PDF/X standard documents.
form_fields_pdfua1Create accessible form field according to PDF/UA.
image_with_link_pdfua1Create PDF/UA-1 document where an image is used as background for a link.
invoice_pdfua1Create combined PDF/UA-1 and PDF/A-2a invoice.
list_pdfua1Demonstrate PDF/UA list tagging.
merge_and_stamp_pdfua1Merge PDF/UA documents including the document structure trees. Additional text is stamped onto each page and tagged as Artifact.
parallel_columns_pdfua1Demonstrate how to tag multiple columns in parallel with activate_item().
scan_with_ocr_pdfua1Tagging for invisible OCR text which accompanies a scanned page.
starter_pdfua1Create PDF/UA-1 document with various content types including structure elements, artifacts and interactive elements.
table_of_contents_pdfua1Demonstrate PDF/UA list tagging.
table_pdfua1Demonstrate automatic table tagging.
tag_out_of_order_pdfua1Demonstrate how to create Tagged PDF out of order.
textflow_pdfua1Create Tagged PDF containing a Textflow with appropriate structure elements on several pages.

PDF/VT

starter_pdfvt1Create a large number of invoices in a single PDF and make use of PDF/VT-1 features.

PDF/X

clone_pdfxClone PDF/A and PDF/X standard documents.
starter_pdfx3Create PDF/X-3-compliant output.
starter_pdfx4Create PDF/X-4 conforming output with layers and transparency.
starter_pdfx5nCreate PDF/X-5n conforming output with an image and DeviceN color.

Tables

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.
repeat_cell_contentsShow 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.
spread_text_over_cellsUse 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 formatter.
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 time sheet for the working hours of an employee.
vertical_text_alignmentDemonstrate vertical alignment of text lines and Textflows in a table cell.

Text Output

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.
leaders_in_textlineUse dot leaders to fill the space between text and page number such as in a table of contents.
shadowed_textCreate a shadowed text line with the 'shadow' option of fit_textline.
simple_stampCreate a stamp across the page which runs diagonally from one corner to the other.
starter_textlineDemonstrate various options for placing a text line.
text_as_clipping_pathOutput text filled with an image.
text_on_a_pathCreate text on a path.
transparent_textCreate some transparent text.
watermarkCreate an editable watermark.

Textflow

avoid_linebreakingCreate a Textflow and define various options for line breaking.
bulleted_listOutput numbered and bulleted lists.
continue_note_after_textInsert a dot sequence automatically at the end of a Textflow fitbox after the last word which can be shown 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 initial drop cap at the beginning of text.
fill_polygons_with_textDefine arbitrary polygons to be filled with text.
footnotes_in_textCreate footnotes (superscript text) in a Textflow provided with links to jump to the footnote text.
keep_lines_togetherControl the lines kept together on the page.
numbered_listOutput numbered lists with the numbers left- or right-aligned.
rotated_textCreate text output which does not run horizontally, but at some angle.
starter_textflowCreate multi-column text output which may span multiple pages.
tabstops_in_textCreate simple multi-column layout using tab stops.
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.
underlined_textCreate underlined text.
vertical_alignment_in_fitboxControl the vertical alignment of text in the fitbox.
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.

Type 3 Fonts

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_vectorlogoCreate a Type 3 font which contains a single logo derived from a PDF page.