Persits Software, Inc. Web Site
 Navigator:  Home |  Manual |  Chapter 12: Miscellaneous Features
Chapter 13: HTML to PDF Conversion Chapter 11a: Existing Form Fill-in
  Chapter 12: Miscellaneous Features
12.1 Barcodes
12.2 Document Stitching
12.3 Metadata
12.4 PDF/A Support

12.1 Barcodes

AspPDF contains the ability to generate printable, scannable barcodes. Various 1D (linear) and 2D barcodes are supported.

12.1.1 Linear Barcodes

Linear (one-dimensional) barcodes are provided by the DrawBarcode method of the PdfCanvas object. This method expects two parameters: a string indicating the data to encode as a barcode, and a PdfParam object or parameter string providing parameters.

The following code sample prints a UPC-A (Universal Product Code) barcode on a page.

VBScript
Set Pdf = Server.CreateObject("Persits.Pdf")
Set Doc = Pdf.CreateDocument
Set Page = Doc.Pages.Add

strParam = "x=72; y=696; height=96; width=144; type=1" 'Barcode type 1 is UPC-A
strData = "04310070524"
Page.Canvas.DrawBarcode strData, strParam
C#
IPdfManager objPDF = new PdfManager();
IPdfDocument objDoc = objPDF.CreateDocument(Missing.Value);
IPdfPage objPage = objDoc.Pages.Add(Missing.Value, Missing.Value, Missing.Value);

String strParams = "x=72; y=696; height=96; width=144; type=1"; //Barcode type 1 is UPC-A
String strData = "04310070524"
objPage.Canvas.DrawBarcode( strData, strParam );

Click the links below to run this code sample:

http://localhost/asppdf/manual_12/12_barcode.asp
http://localhost/asppdf/manual_12/12_barcode.aspx  Why is this link not working?

This will produce the following:

Note that AspPDF automatically calculated and added the UPC-A check digit (the 6.)

The DrawBarcode method will validate the data passed to it and throw an error exception if it is invalid for the specified type of barcode.

AspPDF also includes a sample of an HTML form page into which a user can enter data for a barcode. This code is not repeated here due to length. Click the links below to run this sample:

http://localhost/asppdf/manual_12/12_barcode_form.asp
http://localhost/asppdf/manual_12/12_barcode_form.aspx  Why is this link not working?

12.1.2 Required Barcode Parameters

Type - What type of barcode to draw. See below for a list of supported types.

X, Y - X and Y coordinates of the lower-left corner of the barcode.

Width, Height - Width and height of the barcode.

The X, Y, Width, and Height parameters only specify the size of the actual rectangular bars. Text associated with barcodes may extend slightly outside the specified area.

12.1.3 Optional Barcode Parameters

Color - Specifies the color of the bars and text. This can be a named color constant like "red" or a hex RGB value. Defaults to black.

tc, tm, ty, tk - Specify the CMYK color components of the bars and text. The values must be between 0 and 1. If these parameters are specified, Color is ignored. These parameters were introduced by version 2.2.0.2.

BgColor - Specifies the color of the spaces between the bars. If not specified, the spaces will be transparent. This can be useful to make the spaces in the barcode white if the page background is non-white. Note that very few scanners can scan barcodes in colors other than standard black and white.

FontSize - Specifies the size of the font used. This is not used for certain barcode types like UPC which prescribe all font sizes. This is a maximum limit on font size. AspPDF will shrink the font as necessary to make the text fit within the width of a particular barcode type.

BarWeight - Certain barcode types do not prescribe a constant width ratio between "thin" and "wide" bars, but allow this ratio to be specified. Using this parameter may improve the scannability of these barcode types with various scanners. Defaults to 2, meaning "wide" bars are twice as wide as "thin" bars.

DrawText - Some barcode types (such as UPC) usually include printed human-readable text. Others (such as Industrial 2/5) do not. This parameter allows you to override the default behavior. Can be set to True or False.

AddCheck - A few barcode types allow optional calculation and use of a check digit. Boolean parameter.

Compress - Only used by Code 128, see below. Boolean parameter.

Angle - Specifies an angle of counter-clockwise rotation (in degrees) of the barcode around its lower-left corner.

12.1.4 Supported Linear Barcode Types

(Some images shortened vertically for space)

1. UPC-A - The most common type of barcode. Used in retail applications. Requires 11 or 12 numeric digits; if 11 are given, AspPDF calculates and adds the 12th digit which is a check digit.
2. UPC-E - A shortened form of UPC-A. Requires 8 numeric digits.
3. EAN-13 - A superset of UPC-A, with one additional digit. Requires 12 or 13 numeric digits; the 13th is a check digit in the same manner as UPC-A.
4. EAN-8 - A shortened form of EAN-13. Requires 7 or 8 numeric digits; the 8th is a check digit.
5. UPC-A with supplemental - A UPC-A code, plus either a 2-digit or 5-digit supplemental code. Requires 14 numeric digits for the 2-digit version and 17 digits for the 5-digit version. If the 12th character is a space, AspPDF will calculate a check digit for that space and encode it.
6. UPC-E with supplemental - Similar to UPC-A with supplemental. Requires 10 or 13 numeric digits.
7. EAN-13 with supplemental - Similar to UPC-A with supplemental. Requires 15 or 17 numeric digits. Calculates a check digit if the 13th character is a space.
8. EAN-8 with supplemental - Similar to UPC-A with supplemental. Requires 10 or 13 numeric digits. Calculates a check digit if the 8th character is a space.
9. 2-digit supplemental - The 2-digit supplemental barcode can be drawn by itself without an accompanying main barcode.
10. 5-digit supplemental - See previous.
None of the UPC or EAN barcode types use the FontSize or BarWeight parameter. All other barcodes do use FontSize, and use BarWeight unless otherwise specified.
11. Industrial 2 of 5 - Can encode any quantity of numeric characters. AspPDF adds the start and stop bars.
12. Interleave 2 of 5 - Similar to Industrial 2 of 5 with a more compact encoding scheme.
13. Interleave 2 of 5 Special - Same as Interleave 2 of 5 but with different spacing. Does not use BarWeight.
14. DataLogic 2 of 5 - Similar to Industrial 2 of 5 but with a different compact encoding scheme.
15. Plessey - Can encode any quantity of numeric characters. AspPDF adds the start and stop bars. This image illustrates the use of the BarWeight parameter set to 3. Note that the wide bars are much thicker than the thin bars.
16. Codabar - Can encode any quantity of these characters:
0123456789-$:/.+
Requires a matched pair of start and stop characters which must be the letters A, B, C, or D. Does not use BarWeight.
17. Code 39 - A common encoding scheme for alphabetic text. Can encode numbers, uppercase letters, and these characters:
-. $/+%
AspPDF encodes lowercase characters as uppercase, and adds start and stop bars.
18. Code 11 - Can encode any quantity of numeric characters.
20. Code 39 Extended - Can encode the entire ASCII set (characters 0 to 127). Can optionally add a check digit with the AddCheck parameter.
21. Code 93 - Can encode the entire ASCII set (characters 0 to 127). Does not use BarWeight.
22. Code 128 - Can encode the entire ASCII set (characters 0 to 127). Does not use BarWeight. Must use a check digit via the AddCheck=true parameter. Automatically selects between Code-128 encoding schemes as necessary. Implements the Code-C encoding scheme to compactly encode pairs of digits; this is done if the optional parameter Compress is set to True.

NOTE: as of Version 3.1.0.2, this barcode is replaced by a more readable Type=24 barcode described below.

23. Code 128 Raw - Provides access to advanced features of Code-128 encoding; AspPDF does not do any processing of the data passed to it, except for adding the stop bars and optionally adding the check digit. You must provide the start code character; in VB or ASP, this would be ChrW(135) for Code A, ChrW(136) for Code B, and so on. Consult a Code 128 reference for full information on specifications such as function and shift characters.
24. Code 128 Auto - An improved version of Code 128 (Type=22) described above. Can encode the entire ASCII set (characters 0 to 127). Does not use BarWeight. Ignores AddCheck and Compress parameters. Introduced in version 3.1.0.2 to replace barcode Type=22. Uses an alternative encoding algorithm which provides better scannability than the old Type=22 barcode.
30. US Postal Code - Printed on mail by the US Postal Service. AspPDF calculates and adds a check digit. Does not use BarWeight.
31. UK/Canada Postal Code - Printed on mail by the UK and Canada mail services. Does not use BarWeight.
32. Intelligent Mail Code - Used by US Postal Service. Also known as the USPS OneCode Solution or USPS 4-State Customer Barcode. Requires 20 digits of tracking information followed by 0, 5, 9, or 11 digits of routing (zip code) information. The 2nd digit of the tracking code must be in the range 0 to 4. Introduced by AspPDF 2.4. Does not use BarWeight.

The barcode functionality is demonstrated by Live Demo #8a.

12.1.5 Two-Dimensional Barcodes

AspPDF supports four popular 2-dimensional barcodes: PDF417, Data Matrix, QR Code and Aztec. (PDF417 and DataMatrix were added in version 1.8, QR Code was added in service release 2.0.0.7, and Aztec was added in service release 3.4.0.7.) 2D barcode symbols are drawn via the method DrawBarcode2D of the PdfCanvas object. This method has two required arguments: the text to be encoded, and an instance of the PdfParam object or parameter string. If binary data is to be encoded, the binary array with the data is to be passed via the 3rd optional argument. If the 3rd argument is specified, the text argument is ignored.

The barcode's appearance is controlled via parameters passed as the 2nd argument. The only two required parameters are X and Y which specify the position of the lower-left corner of the symbol on the page. The Type parameter specifies which of the four barcode types to draw. The valid Type values are 1 (PDF417, default), 2 (Data Matrix), 3 (QR Code) and 4 (Aztec). The four 2D barcode types and their parameters are described below.

The 2D barcode functionality is demonstrated by Live Demo #8b.

12.1.5.1 PDF417

In the context of the PDF417 barcode, "PDF" stands for Portable Data File and has nothing to do with the Adobe PDF file format. A PDF417 barcode symbol is essentially a stack of 1D barcodes. A single symbol can contain far more information than a 1D barcode (up to 1.1 KB) in a space no larger than a traditional barcode. This format allows you to store not only text and numbers but binary data as well. In addition, PDF417 has a built-in error correction system so that a symbol can be read even if it is partially damaged or destroyed. The following code snippet draws the barcode symbol shown above:

Page.Canvas.DrawBarcode2D "AspPDF Rules!", "X=10; Y=20"

A PDF417 symbol has a columnar pattern. The leftmost and rightmost columns of every symbol always look the same and they are called start and stop patterns. These are abutted by row indicator columns, and the actual data columns are squeezed in the middle. The symbol above has 3 data columns. Each data column is a stack of "codewords" which are sequences of 4 bars and 4 spaces arranged on 17 available slots. That is where the number 417 comes from. A symbol can contain 1 to 30 data columns and 3 to 90 rows.

The appearance and properties of a PDF417 symbol are controlled by the following parameters (all optional):

As of Version 3.2.0.1, the following parameters have been added to enable the creation of US Government-compliant barcodes on official USCIS forms:

Filling out PDF417 barcode-equipped government forms is covered in detail in Section 11a.8 - Barcode-equipped Government Forms.

The following code snippet encodes binary data from a BLOB recordset field. It specifies the error correction level of 5 and bar width of 2:

Page.Canvas.DrawBarcode2D "", "X=10; Y=20; ErrorLevel=5; BarWidth=2", rs("blob).Value

Unlike the DrawBarcode method described in the previous subsection, the DrawBarcode2D method returns a value -- an instance of the PdfParam object populated with the barcode's width, height, number of rows, number of columns and error level. For example, the following code snippet draws a barcode and then prints out its width and height:

Set Param = Page.Canvas.DrawBarcode2D( "data", "X=10; Y=20;" )
Response.Write "Width=" & Param("Width")
Response.Write "Height=" & Param("Height")

The number of rows, number of columns and error level are retrieved via Param("Rows"), Param("Columns") and Param("ErrorLevel"), respectively.

12.1.5.2 Data Matrix

Data Matrix is another very popular 2D barcode. Its symbols are usually square and sometimes rectangular. A single symbol can encode up to 2335 characters. The required parameters are X, Y, and Type (the latter must be set to 2.) This barcode uses the same error correction system as PDF417, but the error level is determined automatically, therefore the ErrorLevel parameter is not used. The symbol shown above was drawn using the following code:

Page.Canvas.DrawBarcode2D "DataMatrix is also supported!", "Type=2; X=10; Y=20"

The BarWidth parameter specifies both the width and height of an individual cell of the symbol (in user units.) AspectRatio is not used since the cells are always square.

By default, the number of cell columns and rows in a symbol is determined automatically. You can specify the desired size via the Columns and Rows parameters. You must either specify both parameters, or neither. The following [Rows x Columns] combinations are valid: 10x10, 12x12, 14x14, 16x16, 18x18, 20x20, 22x22, 24x24, 26x26, 32x32, 36x36, 40x40, 44x44, 48x48, 52x52, 64x64, 72x72, 80x80, 88x88, 96x96, 104x104, 120x120, 132x132, 144x144, 8x18, 8x32, 12x26, 12x36, 16x36, and 16x48.

All the other parameters have the same meaning as with PDF417. The return values are also the same except that there is no ErrorLevel value.

12.1.5.3 QR Code

The QR Code barcode is used in commercial tracking applications as well as advertisements and signs aimed at mobile-phone users. It was invented in Japan in 1994. "QR" stands for "quick response." The three prominent corner boxes give the QR Code symbols a very distinctive look. The symbols are always square.

A single symbol can encode up to 7,089 numeric symbols, up to 4,296 alpha-numeric symbols, up to 2,953 binary bytes, or up to 1,817 Kanji/Kana characters. The required parameters are X, Y, and Type (the latter must be set to 3.) There are 4 error correction levels, from 0 to 3, 0 being the lowest, specified via the optional ErrorLevel parameter (0 by default.) The symbol shown above was drawn using the following code:

Page.Canvas.DrawBarcode2D "QR is scannable art", "Type=3; X=10; Y=20"

By default, the size of the symbol is determined automatically. To make the symbol larger than necessary, use the Version parameter. The valid values are 0 (auto) and 1 to 40 to specify a larger size.

The BarWidth parameter specifies both the width and height of an individual cell of the symbol (in user units.) AspectRatio is not used since the cells are always square. Columns and Rows are not used since the size is determined automatically or specified via the Version parameter.

All the other parameters have the same meaning as with PDF417 and DataMatrix. CodePage is not used as QR Code always uses UTF-8 encoding. The return values are also the same except that there is no ErrorLevel value.

12.1.5.4 Aztec

Aztec code was invented by Andrew Longacre, Jr. and Robert Hussey in 1995. It can encode 3832 digits, 3067 letters, or 1914 bytes of data. Aztec symbols have a recognizable "bull's eye" pattern in the center.

The required parameters are X, Y, and Type (the latter must be set to 4.) The symbol shown above was drawn using the following code:

Page.Canvas.DrawBarcode2D "Aztec has a bull's eye", "Type=4; X=10; Y=20"

There are 4 error correction levels, from 1 to 4, specified via the optional ErrorLevel parameter (2 by default.)

Aztec symbols are always square. By default, the size of the symbol is determined automatically. To make the symbol larger than necessary, use the Version parameter. The valid values are 0 (auto) and 1 to 36 to specify a larger size. The following table maps the Version values to the corresponding symbol size. The symbols marked with an asterisk (*) in the table below are "compact" symbols, meaning they have a smaller bulls-eye pattern at the center of the symbol.

VersionSizeVersionSizeVersionSizeVersionSizeVersionSizeVersionSize
115x15*219x19*323x23*427x27*519x19623x23
727x27831x31937x371041x411145x451249x49
1353x531457x571561x611667x671771x711875x75
1979x792083x832187x872291x912395x9524101x101
25105x10526109x10927113x11328117x11729121x12130125x125
31131x13132135x13533139x13934143x14335147x14736151x151

The BarWidth parameter specifies both the width and height of an individual cell of the symbol (in user units.) AspectRatio is not used since the cells are always square. Columns and Rows are not used since the size is determined automatically or specified via the Version parameter. The return values are Width, Height, Rows and Columns.

12.2 Document Stitching

AspPDF is capable of joining together two or more PDFs to form a new document. This process is often referred to as document stitching.

12.2.1 AppendDocument Method

Document stitching is performed via the AppendDocument method provided by the PdfDocument object. This method expects a single argument: an instance of the PdfDocument object representing another document to be appended to the current document. The AppendDocument method can be called more than once to append multiple documents to the current one.

The PdfDocument object to which other documents are appended (the master) can either be a new or existing document. The PdfDocument objects that get appended must be all existing documents. A document cannot be appended to itself.

The master document determines the general and security properties of the resultant document.

The following code sample appends the file doc2.pdf to the end of the document doc1.pdf:

VBScript
Set Pdf = Server.CreateObject("Persits.Pdf")

' Open document 1
Set Doc1 = Pdf.OpenDocument( Server.MapPath("doc1.pdf") )

' Open document 2
Set Doc2 = Pdf.OpenDocument( Server.MapPath("doc2.pdf") )

' Append doc2 to doc1
Doc1.AppendDocument Doc2

' Save document, the Save method returns generated file name
Filename = Doc1.Save( Server.MapPath("stitch.pdf"), False )

C#
IPdfManager objPdf = new PdfManager();

// Open Document 1
IPdfDocument objDoc1 = objPdf.OpenDocument(Server.MapPath("doc1.pdf"), Missing.Value);

// Open Document 2
IPdfDocument objDoc2 = objPdf.OpenDocument(Server.MapPath("doc2.pdf"), Missing.Value);

// Append doc2 to doc1
objDoc1.AppendDocument(objDoc2);

// Save document, the Save method returns generated file name
String strFilename = objDoc1.Save( Server.MapPath("stitch.pdf"), false );

Click the links below to run this code sample:

http://localhost/asppdf/manual_12/12_stitch.asp
http://localhost/asppdf/manual_12/12_stitch.aspx  Why is this link not working?

12.2.2 Applying and Removing Security

A cumulative document produced by appending one or more PDFs to a master document inherits the master document's security properties. For example, if a master document is encrypted and the documents appended to it are not, the resultant PDF will be encrypted with the same passwords and permission flags as the master document. Conversely, if the master document is unencrypted and encrypted documents are appended to it, the result document will be unencrypted.

This feature can be used to apply security to unsecure documents, as well as modify or remove security from encrypted documents. The idea is to create an empty document, call the Encrypt method on it if necessary, then append the PDF that needs security added or removed.

To be in compliance with Adobe PDF licensing requirements, AspPDF performs security removal only if the document being appended is opened using the owner password. Otherwise, an error exception is thrown.

The following code sample applies security to the file doc1.pdf. Note that various document properties are being copied from the original document (doc1.pdf) to the new one, because by default the resultant PDF would inherit document properties of the master PDF (in our case, an empty document) and the original document's properties would be lost.

VBScript
Set Pdf = Server.CreateObject("Persits.Pdf")

' Create empty document
Set Doc = Pdf.CreateDocument

' Open document to apply security to
Set Doc1 = Pdf.OpenDocument( Server.MapPath("doc1.pdf") )

' Copy properties
Doc.Title = Doc1.Title
Doc.Creator = Doc1.Creator
Doc.Producer = Doc1.Producer
Doc.CreationDate = Doc1.CreationDate
Doc.ModDate = Doc1.ModDate

' Apply security to Doc
Doc.Encrypt "abc", "", 128

' Append doc1 to doc
Doc.AppendDocument Doc1

' Save document, the Save method returns generated file name
Filename = Doc.Save( Server.MapPath("apply.pdf"), False )

C#
IPdfManager objPdf = new PdfManager();

// Create empty document
IPdfDocument objDoc = objPdf.CreateDocument( Missing.Value );

// Open Document 1
IPdfDocument objDoc1 = objPdf.OpenDocument( Server.MapPath("doc1.pdf"), Missing.Value );

// Copy properties
objDoc.Title = objDoc1.Title;
objDoc.Creator = objDoc1.Creator;
objDoc.Producer = objDoc1.Producer;
objDoc.CreationDate = objDoc1.CreationDate;
objDoc.ModDate = objDoc1.ModDate;

// Apply security to Doc
objDoc.Encrypt( "abc", "", 128, Missing.Value );

// Append doc1 to doc
objDoc.AppendDocument( objDoc1 );

// Save document, the Save method returns generated file name
String strFilename = objDoc.Save( Server.MapPath("apply.pdf"), false );

Click the links below to run this code sample:

http://localhost/asppdf/manual_12/12_applysecurity.asp
http://localhost/asppdf/manual_12/12_applysecurity.aspx  Why is this link not working?

12.2.3 Making Changes to Documents Being Appended

As mentioned earlier, a document being appended must be an existing document opened via OpenDocument or OpenDocumentBinary. Changes made to a document being appended will not propagate to the resultant compound document.

If you need to make changes to a document being appended, the following workaround is recommended:

Set Doc1 = Pdf.OpenDocument(...)
Set Doc2 = Pdf.OpenDocument(...)
' Make changes to Doc2

Set Doc3 = Pdf.OpenDocumentBinary( Doc2.SaveToMemory )
Doc1.AppendDocument Doc3

This code fragment uses an intermediary memory-based document Doc3 to hold the modified version of Doc2.

12.2.4 Creating Multi-Page Documents Based on a Template

AppendDocument is not a very efficent way to create multi-page documents based on a single-page PDF template. We recommend that the method CreateGraphicsFromPage described in Section 9.6 be used for this task instead. For a code sample, see our KB Article PS130905190.

12.3 Metadata

All major Adobe products share a common technology that enables you to embed data describing a file, known as metadata, into the file itself. This technology, called Extensible Metadata Platform (XMP), uses XML as the syntax for metadata description. For more information on XMP, go to http://www.adobe.com/products/xmp.

XML tags used in an XMP data block are described by the Resource Description Framework (RDF) available at http://www.w3.org/RDF.

A typical metadata string may look as follows:

<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#' xmlns:iX='http://ns.adobe.com/iX/1.0/'>

 <rdf:Description about='' xmlns='http://ns.adobe.com/pdf/1.3/' xmlns:pdf='http://ns.adobe.com/pdf/1.3/'>
  <pdf:CreationDate>2002-12-24T07:48:28Z</pdf:CreationDate>
  <pdf:ModDate>2003-02-28T19:39:16+09:00</pdf:ModDate>
  <pdf:Producer>Acrobat Distiller 5.0.1 for Macintosh</pdf:Producer>
  <pdf:Title>Technical Specifications</pdf:Title>
  <pdf:Author>John Smith</pdf:Author>
 </rdf:Description>

 <rdf:Description about='' xmlns='http://ns.adobe.com/xap/1.0/' xmlns:xap='http://ns.adobe.com/xap/1.0/'>
  <xap:CreateDate>2002-12-24T07:48:28Z</xap:CreateDate>
  <xap:ModifyDate>2003-02-28T19:39:16+09:00</xap:ModifyDate>
  <xap:MetadataDate>2003-02-28T19:39:16+09:00</xap:MetadataDate>
  <xap:Title>
   <rdf:Alt>
    <rdf:li xml:lang='x-default'>Technical Specifications</rdf:li>
   </rdf:Alt>
  </xap:Title>
  <xap:Author>John Smith</xap:Author>
 </rdf:Description>

 <rdf:Description about='' xmlns='http://purl.org/dc/elements/1.1/' xmlns:dc='http://purl.org/dc/elements/1.1/'>
  <dc:title>Technical Specifications</dc:title>
  <dc:creator>John Smith</dc:creator>
 </rdf:Description>

</rdf:RDF>

AspPDF enables you to retrieve and specify metadata associated with a PDF document via the MetaData property of the PdfDocument object. The following code fragment extracts and prints out metadata from an existing PDF file:

Set Doc = Pdf.OpenDocument("c:\path\somedoc.pdf")
Response.Write Doc.MetaData

AspPDF provides no functionality for parsing out individual metadata items. Any XML parser object can be used for that, such as Microsoft XML DOM.

12.4 PDF/A Support
12.4.1 PDF/A: PDF for Archiving

The PDF/A format is a subset of the regular PDF format with certain features, deemed incompatible with long-term archival and storage of documents, removed. PDF/A-compliant documents must be completely self-contained, with no reliance on external resources. The single most important requirement for PDF/A files is that all fonts must be embedded. Other requirements include:

  • Encryption is not allowed;
  • Documents must contain standards-based metadata;
  • Links to other documents and URLs are not allowed.
  • Use of device-dependent color spaces such as DeviceRGB is only allowed with some restrictions.
  • Certain other PDF features, such as JavaScript, XML Forms Architecture (XFA), LZW compression, and others, are not allowed.

There are currently three levels of PDF/A conformance: PDF/A-1, PDF/A-2 and PDF/A-3, with Level 1 subdivided into sublevels A and B.

For more information on PDF/A, see http://www.pdfa.org.

12.4.2 AspPDF's Support for PDF/A

As of Version 3.3, AspPDF is capable of producing PDF documents compliant with PDF/A-1b, the basic conformance level which ensures reliable reproduction of the visual appearance of the document. Even prior to Version 3.3, AspPDF embedded all TrueType fonts and allowed metadata to be specified, thus meeting the most important PDF/A requirements. Version 3.3 bridges the remaining gap to full PDF/A-1b compliance by implementing the following features and enhancements:

  • The new PdfDocument.AddOutputIntent method enables mapping from a device-dependent color space such as DeviceRGB to a device-independent color space via an International Color Consortium (ICC) profile, thus satisfying the media-independent visual color reproduction requirement.
  • The entries /CIDToGIDMap and /CIDSet have been implemented for embedded TrueType fonts.
  • A bug has been fixed responsible for certain stream objects to lack the required end-of-line character before the keyword endstream.

The AddOutputIntent method expects 4 arguments: the output condition, the output condition indentifier, the path to the .icc profile file, and the number of color components in the device-dependent color space used by the document (1 for DeviceGray, 3 for DeviceRGB and 4 for DeviceCMYK.) The output condition is a string concisely identifying the intended output device or production condition in human-readable form. The output condition identifier is a string that identifies the output device or production condition as it appears in an industry-standard registry, and can be set to "Custom".

The metadata format is XML-based and similar to that described in the previous section of this chapter, but must contain additional tags. The following example is a minimal metadata string required for PDF/A-1b compliance:

<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>

   <x:xmpmeta x:xmptk="Adobe XMP Core 4.2.1-c041 52.342996, 2008/05/07-20:48:00" xmlns:x="adobe:ns:meta/">
      <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">

         <rdf:Description rdf:about="" xmlns:pdfaid="http://www.aiim.org/pdfa/ns/id/">
            <pdfaid:part>1</pdfaid:part>
            <pdfaid:conformance>B</pdfaid:conformance>
         </rdf:Description>

         <rdf:Description rdf:about="" xmlns:pdf="http://ns.adobe.com/pdf/1.3/">
            <pdf:Producer>Persits Software AspPDF - www.persits.com</pdf:Producer>
            <pdf:Keywords></pdf:Keywords>
         </rdf:Description>

      </rdf:RDF>
   </x:xmpmeta>

<?xpacket end="w"?>

There are several components of this metadata string that are worth noting:

  • The metadata must be enclosed within the <?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?> and <?xpacket end="w"?> tags.
  • The PDF/A level of conformance must be specified via the <pdfaid:part> and <pdfaid:conformance> tags (1 and B for AspPDF's level of conformance.)
  • The Producer value must match the current value for the PdfDocument.Producer property which is set to "Persits Software AspPDF - www.persits.com" by default.

In addition to the tags shown above, PDF/A metadata almost always contains "Dublin Core" (DC) tags as well, such as <dc:title> and <dc:description>, for example:

<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>

   <x:xmpmeta x:xmptk="Adobe XMP Core 4.2.1-c041 52.342996, 2008/05/07-20:48:00" xmlns:x="adobe:ns:meta/">
      <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">

         ...

         <rdf:Description rdf:about="" xmlns:dc="http://purl.org/dc/elements/1.1/">
            <dc:title>
               <rdf:Alt>
                  <rdf:li xml:lang="x-default">Sunset on the beach</rdf:li>
                  <rdf:li xml:lang="de-DE">Sonnenuntergang am Strand</rdf:li>
               </rdf:Alt>
            </dc:title>

            <dc:description>
               <rdf:Alt>
                  <rdf:li xml:lang="x-default">Hello, World</rdf:li>
                  <rdf:li xml:lang="de-DE">Hallo, Welt</rdf:li>
               </rdf:Alt>
            </dc:description>

         </rdf:Description>

      </rdf:RDF>
   </x:xmpmeta>

<?xpacket end="w"?>

12.4.3 Code Sample

The following code sample creates a PDF/A-1b compliant document by importing the URL http://www.asppdf.com, attaching the metadata from the text file metadata.txt located in the same folder as the code sample, and adding an output intent based on the color profile AdobeRGB1998.icc located in the sibling folder manual_15 of the installation.

The content of the file metadata.txt is as follows:

<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>

<x:xmpmeta x:xmptk="Adobe XMP Core 4.2.1-c041 52.342996, 2008/05/07-20:48:00" xmlns:x="adobe:ns:meta/">
	<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">

		<rdf:Description rdf:about="" xmlns:pdfaid="http://www.aiim.org/pdfa/ns/id/">
			<pdfaid:part>1</pdfaid:part>
			<pdfaid:conformance>B</pdfaid:conformance>
		</rdf:Description>

		<rdf:Description rdf:about="" xmlns:pdf="http://ns.adobe.com/pdf/1.3/">
			<pdf:Producer>Persits Software AspPDF - www.persits.com</pdf:Producer>
			<pdf:Keywords></pdf:Keywords>
		</rdf:Description>

		<rdf:Description rdf:about="" xmlns:dc="http://purl.org/dc/elements/1.1/">
			<dc:title>
				<rdf:Alt>
					<rdf:li xml:lang="x-default">@@@title@@@</rdf:li>
				</rdf:Alt>
			</dc:title>
		</rdf:Description>

	</rdf:RDF>
</x:xmpmeta>
	
<?xpacket end="w"?>
	

Note that this metadata file is actually a template, it contains the placeholder @@@title@@@ where the actual title should be. The code sample replaces the placeholder with the value of the PdfDocument.Title property (which is not known in advance since ImportFromUrl sets it based on the HTML content it imports) to ensure that the document's Title entry and the value of the <dc:title> tag in the metadata match.

VBScript
Set PDF = Server.CreateObject("Persits.PDF")
Set Doc = PDF.CreateDocument

' Convert HTML to PDF
Doc.ImportFromUrl "http://www.asppdf.com", "landscape=true; scale=0.75"

' Add metadata from a file
strMetadata = PDF.LoadTextFromFile( Server.MapPath("metadata.txt") )

' Replace placeholder with actual document title
strMetadata = Replace( strMetadata, "@@@title@@@", Doc.Title )

Doc.MetaData = strMetadata

' Add output intent using an RGB color profile. Borrow .icc file from Chapter 15
strProfilePath = Server.MapPath(".") & "\..\manual_15\AdobeRGB1998.icc"
Doc.AddOutputIntent "AdobeRGB", "Custom", strProfilePath, 3

'Save document
Path = Server.MapPath( "pdfa.pdf")
FileName = Doc.Save( Path, false)

C#
IPdfManager objPdf = new PdfManager();

// Create empty document
IPdfDocument objDoc = objPdf.CreateDocument(Missing.Value);

// Convert HTML to PDF
objDoc.ImportFromUrl( "http://www.asppdf.com", "landscape=true; scale=0.75", Missing.Value, Missing.Value );

// Add metadata from a file
string strMetadata = objPdf.LoadTextFromFile( Server.MapPath("metadata.txt") );

// Replace placeholder with actual document title
strMetadata = strMetadata.Replace( "@@@title@@@", objDoc.Title );

objDoc.MetaData = strMetadata;

// Add output intent using an RGB color profile. Borrow .icc file from Chapter 15
string strProfilePath = Server.MapPath(".") + @"\..\manual_15\AdobeRGB1998.icc";
objDoc.AddOutputIntent( "AdobeRGB", "Custom", strProfilePath, 3 );

// Save document
string strPath = Server.MapPath( "pdfa.pdf");
string strFileName = objDoc.Save( strPath, false);

Click the links below to run this code sample:

http://localhost/asppdf/manual_12/12_pdfa.asp
http://localhost/asppdf/manual_12/12_pdfa.aspx  Why is this link not working?

Chapter 13: HTML to PDF Conversion Chapter 11a: Existing Form Fill-in
Search AspPDF.com

  This site is owned and maintained by Persits Software, Inc. Copyright © 2003 - 2014. All Rights Reserved.