wxPdfDocument: wxPdfDocument

# wxPdfDocument 0.9.2

wxPdfDocument

## What is wxPdfDocument?

wxPdfDocument is a C++ class which allows wxWidgets applications to generate PDF files. The code is a port of FPDF - a free PHP class for generating PDF files - to C++ using the wxWidgets library. wxPdfDocument does not make use of any libraries like PDFlib or ClibPDF which require a fee at least for commercial usage. wxPdfDocument is published under the wxWidgets (formerly wxWindows) license. This means you may use it for any kind of usage and modify it to suit your needs.

wxPdfDocument offers all advantages of FPDF. Several add-on PHP scripts found on the FPDF web site are incorporated into wxPdfDocument. The main features are:

- Choice of measure unit, page format and margins
- Page header and footer management
- Automatic page break
- Automatic line break and text justification
- Image support (GIF, JPEG, PNG and WMF)
- Colours (Grayscale, RGB, CMYK, Spot colours)
- Links (internal and external)
- 14 Adobe standard fonts
- TrueType and Type1 fonts (with or without embedding) and encoding support
- TrueType Unicode and Type0 fonts (for Chinese, Japanese and Korean) support in the Unicode build
- OpenType Unicode fonts support in the Unicode build
- Page compression
- Graphics primitives for the creation of simple drawings
- Definition of clipping areas
- Bookmarks for outlining the document
- Rotation
- Protecting the document by passwords and/or access permissions
- Text annotations
- PDF forms (supported field types: text, combo box, check box, radio button, push button)
- JavaScript
- Fill gradients
- Templates
- Layers (optional content groups)
- Simple bitmap patterns as draw and fill colours

The class can produce documents in many languages other than the Western European ones: Central European, Cyrillic, Greek, Baltic and Thai, provided you own TrueType or Type1 fonts with the desired character set. In the Unicode build Chinese, Japanese and Korean are supported, too.

A Reference Manual showing all available methods in alphabetical order is provided. A sample application including more than 20 examples demonstrates the different features. Separate detailed descriptions are available for the MakeFont Utility and the ShowFont Utility. The chapter Styling text using a simple markup language describes the supported tags of the simple XML markup language used by the method wxPdfDocument::WriteXml.

wxPdfDocument is hosted as a component of wxCode. For any remark, question or problem, you can leave a message on the appropriate wxCode tracker accessible from the wxCode support page. Or you can send a mail to me directly .

## Version history

0.9.2 - September 2011

  wxPdfDocument is compatible with wxWidgets version 2.8.12 and version 2.9.2. Compatibility with older wxWidgets versions is not guaranteed, but it should work with all 2.8.x versions.

  General changes:

  - added method wxPdfDC::GetPdfDocument for builds based on wxWidgets 2.9.x
  - added method wxPdfDocument::WriteXml for direct handling of wxXmlNode instances
  - added support for optionally activating/deactivating message translation (msg tag) in XML output method
  - added optional document id parameter for method wxPdfEncrypt::GenerateEncryptionKey

  Fixed bugs:

  - fixed a bug in method wxPdfDocument::CalculatePageSize
  - fixed a bug in wxPdfFontDataCore::ConvertCID2GID
  - fixed several scaling bugs in wxPdfDC
  - fixed several warnings in pdfkernel regarding formatted output of size_t variables
  - fixed minor issues with Bengali font

0.9.1 - January 2011

  wxPdfDocument is compatible with wxWidgets version 2.8.11 and version 2.9.1. Compatibility with older wxWidgets versions is not guaranteed, but it should now work with all 2.8.x versions.

  Added features:

  - added support for Apple Unicode TrueType fonts
  - added the ShowFont Utility

  General changes:

  - optimized the processing speed of VOLT rules
  - modified the code for wxMac support
  - modified the sample tutorial7 to test the new wxMac font loading code
  - added check for valid 'cmap' table in wxPdfFontParserTrueType
  - added call to method wc_str for wxString parameters in calls to FromWChar
  - implemented method RegisterSystemFonts for wxMac
  - samples changed to set the executable path as the current working directory

  Fixed bugs:

  - fixed a memory leak on registering a font identified by a wxFont object
  - fixed a bug in method ShowGlyph
  - fixed several wxMac compile time bugs (missing includes, some typos)
  - changed the wxMac print dialog includes in the printing sample

0.9.0 - December 2010

  wxPdfDocument is compatible with wxWidgets version 2.8.11 and version 2.9.1. Compatibility with older wxWidgets versions is not guaranteed.

  This is the first release of wxPdfDocument containing a PDF drawing context (wxPdfDC). There are implementations for wxWidgets 2.8.x and 2.9.x; the matching implementation is selected automatically at compile time. Please report your experiences with wxPdfDC to the author of wxPdfDocument, be it bug reports, contributions or feature requests.

  Note: A PDF graphics context is planned for one of the next releases of wxPdfDocument. Most likely only wxWidgets 2.9.x will be supported since the internals of the base class wxGraphicsContext differ considerably between wxWidgets 2.8.x and 2.9.x.

  Added features:

  - methods to draw Bezier splines through a list of points; the drawing sample has been extended to show the new functionality
  - PDF drawing context (wxPdfDC); not yet all methods are implemented
  - support for fonts with VOLT (Visual Ordering and Layout Tables) data (currently visual ordering only, preprocessing of the fonts required); fonts for 9 Indic scripts are included to demonstrate this feature

  General changes:

  - increased output speed for method SaveAsFile (if large graphics files are involved)
  - all currently supported CJK font families are now registered automatically at startup of the font manager
  - MS CJK fonts aren't automatically registered as Type0 fonts, since this conflicts with registering these fonts as TrueType Unicode fonts
  - handling of image masks has been improved

  Fixed bugs:

  - opening font files could fail if the file path contained non-latin characters Now wxFileSystem::FileNameToURL is used to create valid file names for use in method OpenFile of wxFileSystem
  - invalid format codes in method wxPdfUtility::Double2String could cause problems in MinGW environment
  - registering half-width CJK fonts didn't work
  - bug in page size handling
  - no file was written when Close was called before SaveAsFile
  - bug in the handling of transparency for image masks
  - uninitialized member variables in layer objects possibly causing invisibility of layers
  - cleaned up output formatting codes for building on 64-bit systems
  - compile time bugs for wxWidgets built with wxUSE_STL
  - several minor bugs

0.8.5 - October 2009

  wxPdfDocument is compatible with wxWidgets version 2.8.10. Some preparations were done to make wxPdfDocument compatible with version 2.9.x and above, too.

  Added features in all builds:

  - support for individual page sizes
  - support for setting fill rule to odd/even or winding
  - support for setting the text render mode
  - support for layers (optional content groups)
  - support for patterns as draw and fill colours
  - support for Code 128 barcodes

  Added features in Unicode build:

  - support for kerning
  - support for different encodings for Type1 and TrueType fonts
  - support for using TrueType and OpenType fonts loaded directly from .ttf or .otf file
  - support for using Type1 fonts loaded directly from .pfb and .afm file
  - support for using TrueType and OpenType fonts defined by a wxFont object
  - font subsetting for OpenType Unicode fonts (experimental, currently non-CID fonts only)
  - direct positioning and writing of glyph numbers for TrueType/OpenType Unicode fonts
    this may be used in conjunction with tools for writing complex scripts like ICU

  Added features in ANSI build:

  - support for fonts defined by a wxFont object (mapped by family, weight and style to the Adobe core fonts)

  General changes:

  - coordinate transformation (location of origin and y axis orientation) is now done directly in PDF. This was a prerequisite to add wxGraphicsContext support in an upcoming version. User unit scaling is done programmatically.
  - unified the naming of all methods manipulating colours. Now always the British spelling is used, i.e. colour instead of color.

  Fixed bugs:

  - line style measurements did not use user units
  - encryption support for big endian platforms.
  - method wxPdfDocument::ClippingText.

0.8.0 - December 2006

  Added features:

  - support for external templates: pages of existing PDF documents may be imported and used as templates
  - font subsetting for TrueType and TrueType Unicode fonts, often resulting in much smaller PDF file sizes
  - support for using and embedding OpenType Unicode fonts
  - enhanced support for password based encryption, encryption key length freely definable between 40 and 128 bits (Attention: Adobe Reader supports only keys with 40 or 128 bits.)
  - support for AES encryption (additional standard encryption method in PDF version 1.6 and above)

  wxPdfDocument is compatible with wxWidgets version 2.8.0 as well as with version 2.6.x.

  As an add-on preprocessed font files for the free DejaVu fonts (version 2.12) are provided in the file release wxPdfDocument Add-Ons.

  Attention: For supporting font subsetting for ordinary non-Unicode TrueType fonts the format of the font definition files has been extended. Font definition files created with prior versions of the MakeFont Utility are still usable, but do not support font subsetting. It is recommended to regenerate own font definition files. Unfortunately common AFM font metric files do not contain glyph information which is required by the MakeFont Utility to create the character-to-glyph mapping. Therefore the utility `ttf2ufm` had to be changed. The modified version including a Windows executable is available in the file release wxPdfDocument Add-Ons.

0.7.6 - October 2006

  Added features (thanks to Stuart Smith):

  - setting/getting the default path used for loading font files
  - getting the description of the current font
  - loading images from a wxInputStream (in addition to loading from file or wxImage)

  Attention: The structure of the font definition files has changed due to the addition of the font attribute `xHeight`. It is necessary to regenerate own font definition files using the MakeFont Utility . To support the `xHeight` attribute the utility `ttf2ufm` had to be changed.

  wxPdfDocument is now compatible with wxWidgets version 2.7.1 and above as well as with version 2.6.x.

  Fixed several bugs

0.7.5 - September 2006

  Added or enhanced features:

  - support for tables in simple XML markup spanning more than a page
  - support for internal links in simple XML markup
  - support for transparency
  - support for image masks
  - support for internal templates
  - support for polygon and shape clipping
  - support for printing text along a path
  - extended support for fill gradients (API changed!)
  - internal colour management reworked

  Fixed some minor bugs

0.7 - April 2006

  Added features:

  - support for CMYK and spot colours
  - support for named colours (486 predefined names for RGB colours) (wxPdfColour)
  - support for colour names in HTML notation (#rrggbb) (wxPdfColour)
  - text annotations
  - additional font decorations: overline, strikeout
  - PDF forms
  - JavaScript at the document level
  - Simple XML markup language for styling and structuring text

  Added or modified methods:

  - wxPdfDocument::LineCount, wxPdfDocument::TextBox and several getter methods were added for convenience
  - wxPdfDocument::MultiCell now respects a maximal line count
  - wxPdfDocument::WriteXml allows to print text containing simple XML markup

0.6 - November 2005

  Added features:

  - gradients
  - transformations
  - barcodes
  - MakeFont Utility

  Changed API of graphics primitives: line style and fill colour parameters deleted, line style and fill colour have to be set using wxPdfDocument::SetLineStyle and wxPdfDocument::SetFillColour.

0.5 - September 2005

  First public release

0.4 - August 2005

  Support for embedding fonts

0.3 - July 2005

  Support for embedding images

0.2 - June 2005

  Several add-ons implemented

0.1 - May 2005
  Planning and basic PDF features implemented

Author:
  Ulrich Telle (ulrich DOT telle AT gmx DOT de)

## Known issues

Currently there are no known issues regarding the functionality of the wxPdfDocument component. All features were thoroughly tested individually, but it's almost impossible to check all potential combinations. If you find bugs please report them to the author!

## Acknowledgements

I'm very grateful to Bruno Lowagie, the main author of the iText Java library (http://www.lowagie.com/iText), for allowing to take lots of ideas and inspirations from this great Java PDF library. Especially the font handling and font subsetting was influenced in that way.

Many thanks go to Ben Moores who provided code for layers and patterns he wrote for his PDF extension for Mapnik (http://www.mapnik.org). This code has been extended based on ideas from the iText Java library and was incorporated into wxPdfDocument.

Support for Indic scripts is based on the efforts of Ian Back, creator of the PHP library mPDF (http://mpdf.bpm1.com); special thanks to K Vinod Kumar of the Centre for Development of Advanced Computing, Mumbai (http://www.cdacmumbai.in), for clearing license issues of the Raghu font series.

Since wxPdfDocument is based on the great FPDF PHP class and several of the contributions to it found on the FPDF website I would like to thank

- Olivier Plathey (FPDF, Barcodes, Bookmarks, Rotation),
- Maxime Delorme (Sector)
- Johannes Guentert (JavaScript)
- Martin Hall-May (WMF images, Transparency)
- Emmanuel Havet (Code39 barcodes)
- Shailesh Humbad (POSTNET barcodes)
- Matthias Lau (i25 barcodes)
- Pierre Marletta (Diagrams)
- Laurent Passebecq (Labels)
- David Hernandez Sanz (additional graphics primitives)
- Valentin Schmidt (Transparency, Alpha channel)
- Jan Slabon (FPDI)
- Klemen Vodopivec (Protection)
- Moritz Wagner (Transformation)
- Andreas Wuermser (Clipping, Gradients, Transformation)

The wxPdfDocument encryption methods use the RSA Data Security, Inc. MD5 Message Digest Algorithm (RSA Data Security license) and the Rijndael cipher implementation of Szymon Stefanek (Public Domain). For detailed license information

See also:
  files pdfencrypt.cpp and pdfrijndael.h.