Prince
  • Buy Prince
  • Samples
  • Documentation
  • Forum
  • Download
  • Installation Guide
  • User Guide
  • Reference Guide

Contents

  • 1. Getting Started
    • Installing Prince
      • Installing Prince on Windows
      • Installing Prince on MacOS X
      • Installing Prince on Linux
        • Debian and Ubuntu
        • Redhat and CentOS
        • OpenSUSE
        • FreeBSD, Solaris and Generic Linux
      • Installing a license file
      • Installation Layout
        • Windows installation layout
        • MacOS X installation layout
        • Linux installation layout
    • Your First Document
      • The lab report
      • Processing the document
      • Styling the document
  • 2. Styling
    • Fonts
      • Defining a font family
      • Generic font families
      • OpenType Features in Prince
      • Redefining the generic font families
    • Layout
      • Text formatting
      • Paragraph formatting
      • Writing Mode
      • CSS Box Model
        • Margin
        • Padding
        • Border
        • Background
      • Tables
        • Automatic table layout
        • Fixed table layout
        • Separated table borders
        • Collapsing table borders
        • Cells that span columns
        • Cells that span rows
        • Numbering table rows
        • Running table headers and footers
        • Table captions
      • Lists
        • List marker position
        • List marker type
        • List marker style
      • Columns
      • Floats
        • Prince extensions to floats
      • Footnotes
        • Footnote calls
        • Footnote markers
        • Styling footnotes
    • Paged Media
      • Page size
      • Page style
      • Trimming marks
      • Page regions
        • Generated content in page regions
      • Selecting pages
        • Blank pages
      • Controlling pagination
        • Page breaks
        • Widows and orphans
  • 3. Scripting
    • JavaScript in Printed Media
    • Logging
    • Console access
    • Event handling
    • Document statistics
    • PDF properties
    • Unsupported DOM properties
  • 4. Graphics
    • Color
      • RGB
      • RGBA
      • CMYK
      • Spot colors
    • Color Management
      • Introduction
      • Color Management and PDF Profiles
      • Color Management in Prince
      • Color conversion
      • Rich black and true black
      • Page color space
    • Filters
    • Images
      • Images in XHTML
      • Images in DocBook
      • Images in Arbitrary XML
      • CSS and Images
        • Image Size in Print
    • Scalable Vector Graphics (SVG)
      • Viewbox and viewport
      • Rectangles
      • Circles
      • Ellipses
      • Lines
      • Masks
      • Polylines
      • Polygons
      • Paths
      • Text
      • Images
      • Links
      • Transformations
      • Style Properties
    • Rasterization
  • 5. Prince Tips and Tricks
    • Generated Content
      • Page headers and footers
      • List markers
      • Footnote markers
      • Before and After pseudo-elements
      • Counters and Numbering
        • Counter reset and increment
        • Nested counters
        • Counter styles
      • Cross-references
        • Using target-counter
        • Using target-content
      • Script Functions
        • Accessing the current date and time
        • User-defined counter styles
      • Using generated content in page regions
      • Copying text content from the document
      • Taking elements from the document
    • Advanced paged media examples
      • Named pages
      • Page groups
      • Page breaks and decoration
      • Printing wide content sideways
    • Hyphenation
    • Typographic Ligatures
    • Watermarks
    • Rotating content in table cells
    • The "Two-Pass" Solution
  • 6. Help
    • Troubleshooting
      • Missing glyphs or fonts
      • Fontconfig
      • Image formats
      • Shared library trouble
      • PATH issues
      • The capture/replay system
      • Running the debug script
    • Frequently Asked Questions
  • 7. Prince Input
    • Applying Style Sheets in Prince
      • Importing Style Sheets
      • Conflicting Declarations
      • Priority Determination
    • Applying JavaScript in Prince
    • XML Input
      • XML Input
        • Validation
        • xml:lang
        • xml:id
        • xml:base
      • XML Styling
      • XML Inclusions (XInclude)
        • Including XML files
        • Including text files
        • Fallback
  • 8. Prince Output
    • PDF Profiles
      • PDF/A
      • PDF/X
    • PDF Output Options
      • PDF Links
      • PDF Actions
      • PDF Pages
      • PDF Printing
      • PDF Compression
      • Font Embedding
      • Creating PostScript output
    • PDF Bookmarks
      • Bookmark levels
      • Bookmark labels
      • Bookmark targets
    • PDF Metadata
      • XMP Metadata
  • 9. Server Integration
    • Security and performance
    • Prince Wrappers
      • Third-Party Wrappers
      • Using Prince from Java
      • Using Prince from .NET with C#
      • Using Prince from .NET with VB.NET
      • Using Prince from Python
      • Using Prince from Perl
      • Using Prince from PHP
      • Using Prince from ASP
      • Using Prince from ColdFusion
      • Using Java
      • Using ActiveX/COM
      • Using Prince from ActiveX / COM / Visual Basic
    • Advanced Command Line Options
      • Prince Control Protocol
      • Structured Log

Reference Guide

  • A1. Command-line Reference
    • Examples
    • Specifying input and output
    • Options
      • General Options
      • Logging Options
      • Input Options
      • Network Options
      • JavaScript Options
      • CSS Options
      • PDF Output Options
      • PDF Metadata Options
      • PDF Encryption Options
      • Raster Output Options
      • Utility Options
      • Advanced Control and Log Options
  • A2. CSS References
    • CSS Features
    • Length Units
      • Absolute Length Units
      • Font Length Units
      • Pixel Unit
  • A3. CSS Properties
    • alternate-color
    • background
    • background-attachment
    • background-clip
    • background-color
    • background-image
    • background-origin
    • background-position
    • background-repeat
    • background-size
    • baseline-shift
    • border
    • border-bottom
    • border-bottom-color
    • border-bottom-left-radius
    • border-bottom-right-radius
    • border-bottom-style
    • border-bottom-width
    • border-clip
    • border-collapse
    • border-color
    • border-left
    • border-left-color
    • border-left-style
    • border-left-width
    • border-radius
    • border-right
    • border-right-color
    • border-right-style
    • border-right-width
    • border-spacing
    • border-style
    • border-top
    • border-top-color
    • border-top-left-radius
    • border-top-right-radius
    • border-top-style
    • border-top-width
    • border-width
    • bottom
    • box-decoration-break
    • box-sizing
    • caption-side
    • clear
    • clip
    • clip-path
    • clip-rule
    • color
    • column-break-after
    • column-break-before
    • column-count
    • column-fill
    • column-gap
    • column-rule
    • column-rule-color
    • column-rule-style
    • column-rule-width
    • column-span
    • column-width
    • columns
    • content
    • counter-increment
    • counter-reset
    • direction
    • display
    • dominant-baseline
    • empty-cells
    • fill
    • fill-opacity
    • fill-rule
    • filter
    • float
    • font
    • font-family
    • font-size
    • font-stretch
    • font-style
    • font-variant
    • font-weight
    • footnote-display
    • footnote-style-position
    • height
    • hyphens
    • left
    • letter-spacing
    • line-height
    • line-stacking-strategy
    • list-style
    • list-style-image
    • list-style-position
    • list-style-type
    • margin
    • margin-bottom
    • margin-inside
    • margin-left
    • margin-outside
    • margin-right
    • margin-top
    • marker-end
    • marker-mid
    • marker-start
    • marks
    • mask
    • max-height
    • max-width
    • min-height
    • min-width
    • opacity
    • orphans
    • overflow
    • overflow-wrap
    • padding
    • padding-bottom
    • padding-left
    • padding-right
    • padding-top
    • page
    • page-break-after
    • page-break-before
    • page-break-inside
    • position
    • prince-background-image-resolution
    • prince-bleed
    • prince-bookmark-label
    • prince-bookmark-level
    • prince-bookmark-state
    • prince-bookmark-target
    • prince-caption-page
    • prince-fallback-cmyk-profile
    • prince-filter-resolution
    • prince-flow
    • prince-footnote-policy
    • prince-forced-breaks
    • prince-hyphenate-after
    • prince-hyphenate-before
    • prince-hyphenate-character
    • prince-hyphenate-lines
    • prince-hyphenate-patterns
    • prince-image-magic
    • prince-image-resolution
    • prince-linebreak-magic
    • prince-link
    • prince-mark-length
    • prince-mark-offset
    • prince-mark-width
    • prince-page-group
    • prince-pdf-color-conversion
    • prince-pdf-color-options
    • prince-pdf-destination
    • prince-pdf-duplex
    • prince-pdf-link-type
    • prince-pdf-open-action
    • prince-pdf-output-intent
    • prince-pdf-page-colorspace
    • prince-pdf-page-label
    • prince-pdf-page-layout
    • prince-pdf-page-mode
    • prince-pdf-paper-tray
    • prince-pdf-print-scaling
    • prince-pdf-profile
    • prince-pdf-script
    • prince-pdf-xmp
    • prince-rotate-body
    • prince-shrink-to-fit
    • prince-text-justify
    • prince-text-replace
    • prince-tooltip
    • prince-trim
    • prince-wrap-inside
    • right
    • size
    • src
    • stop-color
    • stop-opacity
    • string-set
    • stroke
    • stroke-dasharray
    • stroke-dashoffset
    • stroke-linecap
    • stroke-linejoin
    • stroke-miterlimit
    • stroke-opacity
    • stroke-width
    • table-baseline
    • table-column-span
    • table-layout
    • table-row-span
    • text-align
    • text-align-last
    • text-anchor
    • text-decoration
    • text-indent
    • text-line-through
    • text-line-through-color
    • text-line-through-style
    • text-overflow
    • text-overline
    • text-overline-color
    • text-overline-style
    • text-transform
    • text-underline
    • text-underline-color
    • text-underline-style
    • top
    • transform
    • transform-origin
    • unicode-bidi
    • unicode-range
    • vertical-align
    • visibility
    • white-space
    • widows
    • width
    • word-break
    • word-spacing
    • writing-mode
    • z-index
  • A4. CSS Selectors
    • Terminology and Definitions
    • Logical Combinations
    • Elemental Selectors
    • Attribute Selectors
    • Linguistic Pseudo-classes
    • Location Pseudo-classes
    • Tree-Structural pseudo-classes
    • Combinators
    • Tree-Abiding Pseudo-element Selectors
    • Typographic Pseudo-element Selectors
    • Footnote Pseudo-element Selectors
    • Page Selectors
  • A5. CSS Media Queries
    • Media Queries
    • Media Query Modifiers
    • Media Types
    • Media Features
    • Dimension Media Features
    • Display Quality Media Features
    • Color Media Features
    • Interaction Media Features
    • Scripting Media Features
  • A6. CSS Functional Expressions
    • CSS Functions
    • Prince Specific Functions
  • A7. CSS At-rules
    • Initial At-Rules
    • Nested At-Rules
  • A8. Page Size Keywords
  • A9. Character Entities
    • Accented Letters
    • Symbols
    • Quotes
    • Accents
    • Miscellaneous
  • A10. Acknowledgements

Advanced Command Line Options

Prince offers two command line options useful for integrating Prince with other software: the Prince Control Protocol and the Structured Log. See the Server Integration section for some examples of Prince wrappers.

Prince Control Protocol

prince --control

The Prince Control Protocol, accessible through the command-line option --control, is a synchronous bidirectional protocol that consists of a sequence of "chunks" sent via the standard input and output streams.

Each chunk contains a sequence of bytes with a length and a three letter tag. Here is an example "version" chunk to demonstrate the syntax:

ver 15
Prince 20161219

This chunk has a tag ver (all tags are three ASCII characters) followed by a space, then the length of the data expressed as a decimal number, then a newline character, then the data itself (15 bytes), then another newline (not part of the data).

This "version" chunk is emitted by Prince when the control protocol begins and can be used to check the Prince version and confirm that communication is functioning as expected. Prince will then wait for jobs to be submitted.

If a chunk contains no data then the length is zero and the chunk ends with the newline immediately following the length. In fact the length itself may be omitted, making this a perfectly valid chunk:

end

This end chunk consists of three letters and a newline character and can be used to terminate the Prince process when there are no further jobs to process.

Currently the control protocol includes the following chunk types sent by Prince:

  • ver, sent at startup
  • pdf, a generated PDF file
  • log, the complete output log for the job including all errors and warnings
  • err, errors relating to the control protocol itself

And these chunks sent by the caller:

  • job, the description of a requested conversion job, expressed in JSON
  • dat, a file resource needed by the job
  • end, to terminate the control connection

A typical interaction looks like this:

Prince: ver
Caller: job
Caller: dat
Caller: dat
Prince: pdf
Prince: log
Caller: end

Instead of sending the final end chunk the caller may choose to submit another job chunk and continue converting documents. The protocol is synchronous so replies simply match requests in order.

The job chunk contains a description of the conversion job represented in JSON format, which can be followed by an optional sequence of dat chunks containing file data which is needed by the job, eg. HTML documents, style sheets, PDF attachments, or whatever.

The number of dat chunks is specified by the job-resource-count field in the job description, and these files can be accessed via a special job-resource URL scheme, eg. job-resource:0 will access the content of the first dat chunk, then job-resource:1, job-resource:2, etc. This allows any number of resources to be provided inline with the request and removes the need to create actual temporary files.

The JSON job description has several nested objects with fields corresponding to Prince options:

{
    "input": { <input options> },
    "pdf": { <pdf options> },
    "metadata": { <metadata options> },
    "raster": { <raster options> },
    "job-resource-count": <int>
}

The input options and job-resource-count are mandatory, the rest are optional and will default to the normal values.

The input options object includes these fields:

{
    "src": <single URL or list of URLs>,
    "type": <string>,
    "base": <string>,
    "media": <string>,
    "styles": [ <list of URLs> ],
    "scripts": [ <list of URLs> ],
    "default-style": <bool>,
    "author-style": <bool>,
    "javascript": <bool>,
    "xinclude": <bool>,
    "xml-external-entities": <bool>
}

Only the src field is required, the rest can be left as defaults.

Now we can make some simple job descriptions, eg. to convert a single HTML file:

{
    "input": {
        "src": "/path/to/input.html"
    },
    "job-resource-count": 0
}

This can be sent as a single job chunk and Prince will respond with a pdf chunk if the conversion succeeded and a log chunk.

Or you can convert a HTML document without saving it to a temporary file:

{
    "input": {
        "src": "job-resource:0"
    },
    "job-resource-count": 1
}

This requires the job chunk to be followed by a dat chunk that contains the HTML and then Prince will respond as before.

The pdf options object includes these fields:

{
    "color-options": "auto" | "use-true-black" | "use-rich-black",
    "embed-fonts": <bool>,
    "subset-fonts": <bool>,
    "artificial-fonts": <bool>,
    "force-identity-encoding": <bool>,
    "compress": <bool>,
    "encrypt": {
        "key-bits": 40 | 128,
        "user-password": <string>,
        "owner-password": <string>,
        "disallow-print": <bool>,
        "disallow-modify": <bool>,
        "disallow-copy": <bool>,
        "disallow-annotate": <bool>
    },
    "attach": [ <list of URLs> ],
    "pdf-profile": <string>,
    "pdf-output-intent": <URL>,
    "fallback-cmyk-profile": <URL>,
    "color-conversion": "none" | "full"
}

The metadata options object includes these fields:

{
    "title": <string>,
    "subject": <string>,
    "author": <string>,
    "keywords": <string>,
    "creator": <string>
}

The raster options object includes these fields:

{
    "dpi": <integer>
}

Structured Log

--structured-log=LEVEL

This option is designed to make it easier to integrate other software with Prince. It takes these values:

  • --no-structured-log
  • --structured-log=normal
  • --structured-log=quiet
  • --structured-log=progress
  • --structured-log=buffered

The default is --no-structured-log, in which case error and warning messages will be written to the terminal (stderr stream) as they occur in a human readable format, eg.

prince: foo.html: error: can't open input file: No such file or directory
prince: foo.html: error: could not load input file
prince: error: failed to load all input documents

Specifying --structured-log=normal writes the log messages in an alternate format with fields separated by | characters, in order to make it easier to parse by other software:

msg|err|foo.html|can't open input file: No such file or directory
msg|err|foo.html|could not load input file
msg|err||failed to load all input documents
fin|failure

Specifying --structured-log=quiet suppresses all log messages, except for the final fin message, indicating success or failure:

fin|failure

This allows other software to read the stdout stream from Prince containing the PDF file in its entirety, then read the final status from the stderr stream, without worrying about blocking due to deadlocks.

Specifying --structured-log=progress prints percentage log messages for use in GUI applications:

prg|94
prg|96
prg|99
prg|100
fin|success

Specifying --structured-log=buffered is the same as normal, but all log messages will be delayed until after the full PDF has been written to the stdout stream, again so that other software can read from stdout and then read the log from stderr without deadlocking.

The deadlock problem happens when Prince writes log messages to stderr and blocks, waiting for the other software to read them, but the other software is blocked waiting for Prince to write the PDF to stdout, leading to a deadlock where both processes hang indefinitely.

By omitting log messages, or by delaying them until after the PDF is written, this deadlock can be avoided. Another option is to use the Prince Control Protocol, which also avoids this problem.

Copyright © 2002 – 2019 YesLogic Pty. Ltd.
  • About Us
  • Privacy Policy
  • Contact Us