Appending multiple documents issues - evaluating

The PDF Creator .NET Library enables you to create secure PDF documents on the fly and to view, print and process existing PDF documents. If you have any questions about PDF Creator .Net, please post them here.
Post Reply
jerwin
Posts: 1
Joined: Tue Dec 18 2007

Appending multiple documents issues - evaluating

Post by jerwin »

I am evaluating PDF Creator.NET for the first time. We are evaluating for a large scale web application where we would need it to combine multiple PDF documents into a single document. The smaller files to be combined will be stored as BLOBS in a SQL Server database.

So far, I have used an evaluation version I downloaded from Amyuni last week to create a single document by appending other multiple documents. While doing this append has worked, there are some issues I have run aross.

Issue 1:

In my tests, I have been creating a new document, then appending all of the existing documents into this one document. While this does work, the document always has a blank page before the begining of the first document appended. I have attempted to remove the first page prior to appending any documents, but still end up with a blank page for page 1 of the combined target document.

I have also tried removing the first page after appending the other documents. While this does work, there appears to be a performance hit for calling the code like this.

document.GetPage(1);
document.CurrentPage.Delete(false);

Is there a better way to approach this?

Issue 2:

The file size of the target combined document can end up MUCH larger than the combined size of the source documents. I see the potential for this to add significant bandwidth overhead when delivering these documents via the httpresponse stream to the client.

For example, when I combine three very simple 1 page PDF files with a size of 38KB into a single document, the resulting size is 165KB rather than close to the 114KB. This was the smallest test I could perform. For a larger test, I combined three larger files.

File 1: 480KB
File 2: 097KB
File 3: 061KB

The result file from PDFCreator.NET was a file size of 3160KB instead of somewhere closer to the approximately 650KB I expected. Is there something I can to to optimize the size.

Issue 3:

I don't have exact numbers on this issue yet, but my perception of appending 3 documents together at this point is that it is not a very speedy process. Is there a speedier approach to combining multiple PDF documents into one that I'm not doing at this point?

Here is the method I'm using to do most of the work for the process.

***************************************************

Code: Select all

        private void AppendPdfFiles(string saveTofile)
        {

            acPDFCreatorLib.Initialize();
            acPDFCreatorLib.SetLicenseKey("Visionpace", "Demo");

            FileStream sourceFile = null;
            FileStream targetFile = null;

            Amyuni.PDFCreator.IacDocument target = new Amyuni.PDFCreator.IacDocument();

            target.GetPage(1);
            target.CurrentPage.Delete(false);

            Amyuni.PDFCreator.IacDocument source = null;
            foreach (string fileName in FileList)
            {
                source = new Amyuni.PDFCreator.IacDocument();
                sourceFile = new System.IO.FileStream(fileName, System.IO.FileMode.Open, System.IO.FileAccess.Read,
                    System.IO.FileShare.Read);

                try
                {
                    source.Open(sourceFile, "");
                }
                catch (Exception ex)
                {
                    try
                    {
                        source.Open(sourceFile, PdfPassword);
                        Debug.WriteLine(String.Format("Password required for {0}", fileName));
                    }
                    catch (Exception nex)
                    {
                        throw nex;
                    }
                }
                

                target.Append(source);

                sourceFile.Close();
                source.Dispose();
            }

            if (target.PageCount > 1)
            {
                
                targetFile = new System.IO.FileStream(saveTofile, FileMode.Append, FileAccess.Write, FileShare.None);
                target.Save(targetFile);
                targetFile.Close();
                target.Dispose();
                FileList.Clear();
                
            }

            acPDFCreatorLib.Terminate();
            
        }

***************************************************

thanks,

JE
Jim Erwin
Software Development Practice Manager
Visionpace Software Development
http://www.visionpace.com
Joan
Amyuni Team
Posts: 2799
Joined: Wed Sep 11 2002
Contact:

Post by Joan »

Hello,

Issue 1:
You don't need to go to a given page to delete it, you an use:
pdfCreator1.Document.DeletePage (2, true);

Issue 2:
Please check if the fonts are embedded in the original documents and if these are embedded in the created pdf file.
If the fonts are being embedded after appending the files this might be the reason behind the additional file size.

Issue3:
Append shouldn't be time consuming, in your code you are using two objects source and target, you can use one object.
Here is a sample C# Append code

Code: Select all

{
// Open the first PDF document from file
System.IO.FileStream file1 = new System.IO.FileStream ("test1.pdf", FileMode.Open, FileAccess.Read);
IacDocument doc1 = new IacDocument (null);
doc1.Open (file1, "" );
// Open the second PDF document from file
System.IO.FileStream file2 = new System.IO.FileStream ("test2.pdf", FileMode.Open, FileAccess.Read);
IacDocument doc2 = new IacDocument (null);
doc2.Open (file2, "" );
// append the two documents
doc1.Append (doc2);
// save the result to a third file
System.IO.FileStream file3 = new System.IO.FileStream ("test3.pdf", FileMode.Create,
FileAccess.Write);
doc1.Save (file3);
}
Merry Christmas!
Custom Brand the Amyuni PDF Printer Driver http://www.amyuni.com/en/developer/branding/index.html

Amyuni PDF Converter tested for true PDF performance. View results - http://www.amyuni.com/benchmark
Post Reply