Persits Software, Inc. Web Site
 Navigator:  Home |  Manual |  Chapter 14: Document Stitching and Other Features
Chapter 15: HTML to PDF Conversion Chapter 13: Barcodes
  Chapter 14: Document Stitching and Other Features
14.1 Document Stitching
14.2 Metadata

14.1 Document Stitching

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

14.1.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 document) 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:

C#
PdfManager objPDF = new PdfManager();

// Open Document 1
PdfDocument objDoc1 = objPDF.OpenDocument( Server.MapPath("doc1.pdf") );

// Open Document 2
PdfDocument objDoc2 = objPDF.OpenDocument( Server.MapPath("doc2.pdf") );

// Append doc2 to doc1
objDoc1.AppendDocument( objDoc2 );
VB.NET
Dim objPDF As PdfManager = New PdfManager()

' Open Document 1
Dim objDoc1 As PdfDocument = objPDF.OpenDocument(Server.MapPath("doc1.pdf"))

' Open Document 2
Dim objDoc2 As PdfDocument = objPDF.OpenDocument(Server.MapPath("doc2.pdf"))

' Append doc2 to doc1
objDoc1.AppendDocument(objDoc2)

Click the links below to run this code sample:

http://localhost/asppdf.net/manual_14/14_stitch.cs.aspx
http://localhost/asppdf.net/manual_14/14_stitch.vb.aspx  Make sure AspPDF.NET is installed on your local machine and IIS is running for these links to work.

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

C#
...
// Create empty document
PdfDocument objDoc = objPdf.CreateDocument();

// Open Document 1
PdfDocument objDoc1 = objPdf.OpenDocument( Server.MapPath("doc1.pdf") );

// 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 objDoc, use pdfFull permission by default
objDoc.Encrypt( "abc", "", 128 );

// Append doc1 to doc
objDoc.AppendDocument( objDoc1 );
...
VB.NET
...
' Create empty document
Dim objDoc As PdfDocument = objPdf.CreateDocument()

' Open Document 1
Dim objDoc1 As PdfDocument = objPdf.OpenDocument(Server.MapPath("doc1.pdf"))

' 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 objDoc, use pdfFull permission by default
objDoc.Encrypt("abc", "", 128)

' Append doc1 to doc
objDoc.AppendDocument(objDoc1)
...

Click the links below to run this code sample:

http://localhost/asppdf.net/manual_14/14_applysecurity.cs.aspx
http://localhost/asppdf.net/manual_14/14_applysecurity.vb.aspx  Make sure AspPDF.NET is installed on your local machine and IIS is running for these links to work.

14.1.3 Making Changes to Documents Being Appended

As mentioned earlier, a document being appended must be an existing document opened via OpenDocument. 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:

PdfDocument objDoc1 = objPDF.OpenDocument(...);
PdfDocument objDoc2 = objPDF.OpenDocument(...);
// Make changes to objDoc2

PdfDocument objDoc3 = objPDF.OpenDocument( objDoc2.SaveToMemory );
objDoc1.AppendDocument( objDoc3 );

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

14.2 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.NET 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:

PdfDocument objDoc = objPDF.OpenDocument(@"c:\path\somedoc.pdf");
Response.Write( objDoc.MetaData );

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

Chapter 15: HTML to PDF Conversion Chapter 13: Barcodes
Search AspPDF.net

Newsletter Signup

Other Products
AspPDF
AspUpload
AspJpeg
AspEmail
AspEncrypt
AspGrid
AspUser
  This site is owned and maintained by Persits Software, Inc. Copyright © 2003 - 2009. All Rights Reserved.