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.1 Barcodes

AspPDF contains the ability to generate printable, scannable barcodes.

12.1.1 Using Barcodes

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.

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 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.
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.
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.

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.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.

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. All Rights Reserved.