[Solved] Having problems dealing with corrupt PDF file.

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
justjoh
Posts: 3
Joined: Tue Jul 15 2008

[Solved] Having problems dealing with corrupt PDF file.

Post by justjoh » Wed Jan 28 2009

We're using PDF Creator .NET to add some text to existing PDF files. (Recieved on: 9999/99/99, and the like).

My customer preseted me with 3 PDF files that cannot be opened in Adobe, Foxit Reader, Spicer Imagenation, or by an open source PDF library.
Each of these tools report that the source PDF file is corrupt.

When using PDF Creator .NET (acPDFCreatorLib.Net.dll version 3.0.3.4), however, the followng code snippet executes without any errors.
(number of pages reported is 1, and PDF Version is reported as 1.2)

Code: Select all

            using (var pdf = new IacDocument(null))
            {
                Inform("Open file: {0} for stamping.", inputFile);
                using (var fs = File.Open(inputFile, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    pdf.Open(fs, string.Empty);
                }

                pages = pdf.PageCount;
                Inform("Number of pages to stamp = {0}.", pages);
            }
I need to be able to detect up front if the source file I'm going to stamp is corrupt.

Any guidance anyone can give would be most helpful.

Thanks,

Nick

Joan
Amyuni Team
Posts: 2799
Joined: Wed Sep 11 2002
Contact:

Re: Having problems dealing with corrupt PDF file.

Post by Joan » Thu Jan 29 2009

Hello,

You mean the files are supported by our PDF Creator but not by other PDF viewers?

You can use a method called GetWarningLevel. It is used to read any warnings generated when opening a document. However the warnings are related to features not supported by the PDF Creator.

Hope this helps, if not I suggest that you send your sample files to support@amyuni.com to have your files checked.
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

justjoh
Posts: 3
Joined: Tue Jul 15 2008

Re: Having problems dealing with corrupt PDF file.

Post by justjoh » Thu Jan 29 2009

No, I wouldn't say they're supported, rather that the corruption is going undetected.

The end result is that what should have been an 11 page PDF ends up as a single page that is blank, except for my stamp.

I tried using the debugger to see if any exceptions were being suppressed, but that doesn't seem to be the case. I'll have a look at GetWarningLevel and see if it indicates anything (Like maybe y'all are treating the corruption as an unsupported feature?)

I need to get customer's permission before sending any files (even corrupt ones), but I'll start that process now.

Thanks.

weswagner
Posts: 4
Joined: Tue Feb 03 2009

Re: Having problems dealing with corrupt PDF file.

Post by weswagner » Mon Feb 09 2009

I have this exact same issue! I can insert an image into an existing PDF fine the first time, but if I try to add a second image to the document, the PDF document says it only contains one page and the outcome is a single page with the second image on it. I've posted on two different message boards and haven't heard back yet. Have you found out why this is happening?

Thanks in advance,
Wes

justjoh
Posts: 3
Joined: Tue Jul 15 2008

Re: Having problems dealing with corrupt PDF file.

Post by justjoh » Wed Feb 11 2009

I did find my solution in the proudct documentation, and that was to examine the return code from the IacDocument.Open call. The original develoepr didn't use the return code, so at first I assumed there wasn't one.

In any case the snippet below correctly identified my 3 corrupt documents as having issues.

Code: Select all

using (var pdf = new IacDocument(null))
{
    Tracer.Inform(Resources.OpeningSourceFile, inputFile);
    using (var fs = File.Open(inputFile, FileMode.Open, FileAccess.Read, FileShare.Read))
    {
        if (!pdf.Open(fs, string.Empty))
        {
            if (0 != pdf.Protected)
                throw new Exception(Resources.PasswordProtected);
            else
                throw new Exception(Resources.CorruptPDF);
        }
    }
    pages = pdf.PageCount;
    Inform("Number of pages to stamp = {0}.", pages);
}

Post Reply