Module Vgr_pdf

Vg PDF renderer.

Renders a sequence of renderables as a multi-page PDF 1.7 document. Each renderable defines a page of the document.

Bug reports. PDF being an insane standard, rendering abilities of PDF readers vary wildly. No rendering bug report for this renderer will be considered if it cannot be reproduced in the latest Adobe Acrobat Reader.

v0.9.4 - homepage

Font resolution

Font resolution happens during the rendering of Vg.I.cut_glyphs images through the font callback given to the PDF rendering target. See Text rendering for more details.

type otf_font

The type for OpenType fonts.

val otf_font : string -> ([> `Otf of otf_font ]Otfm.error) result

otf_font bytes is an OpenType font from the OpenType byte serialization bytes.

type font = [
| `Otf of otf_font
| `Serif
| `Sans
| `Fixed
| `Helvetica
| `Times
| `Courier
]

The type for font resolution results. Any case different from `Otf ends up using the PDF standard fonts. See Text rendering for details.

val font : Vg.font -> font

font is the default font resolver. Given a Vg.font f it performs the following resolutions according to value of f.Font.name:

  • "Helvetica", returns `Sans
  • "Times", returns `Serif
  • "Courier", returns `Fixed
  • Any other, returns `Sans

See Text rendering for understanding what this entails.

PDF render targets

val target : ?font:(Vg.font -> font) -> ?xmp:string -> unit -> Vg.Vgr.dst_stored Vg.Vgr.target

target font xmp () is a PDF render target for rendering to the stored destination given to Vg.Vgr.create.

  • font is the font resolver, defaults to font, see Text rendering for details. Note that font results are cached by the renderer.
  • xmp is an optional UTF-8 encoded XML XMP metadata packet describing the PDF document (see ISO 16684-1 or the equivalent Adobe spec.). The convenience function Vg.Vgr.xmp can be used to generate a packet.

Multiple image. Multiple image render is supported. Each image defines a page of the resulting PDF file.

Text rendering

Text rendering depends on the way fonts are resolved by the function specified in the rendering target. Given a glyph cut:

Vg.I.cut_glyphs ~text ~blocks ~advances font glyphs

First, if the optional text and blocks arguments are specified, they are always used to map the rendered glyphs to text for PDF text extraction. Then the following happens according to the resolution of the font argument by the render target:

So what should be used ? In general clients should use a font resolution mechanism independent from Vg in order to get an OpenType font otf for font. Using this otf font is should compute, using again a mechanism independent from Vg, a glyph layout resulting in advances and glyphs to use with Vg.I.cut_glyphs and finally resolve font in the target with `Otf otf. This means that font resolution should:

Render warnings and limitations

The following render warnings are reported.

The following limitations should be taken into account: