1

I'm trying to use iTextSharp to rotate a page & have it read by ghostscript to generate the pages as images. This is how I'm rotating the pages:

    byte[] retVal = null;
    using (MemoryStream oOutput = new MemoryStream())
        {
            PdfReader oPDFReader = new PdfReader(BaseFile);
            PdfStamper stamper = new PdfStamper(oPDFReader, oOutput );

            for (var pageNum = 1; pageNum <= oPDFReader.NumberOfPages; pageNum++)
            {
                var oDocumentPage = DocumentPages.Where(page => page.PageNumber == pageNum && page.RotationDegree != 0).FirstOrDefault();
                if (oDocumentPage != null )
                {
                    if (oDocumentPage.RotationDegree < 0)
                        oDocumentPage.RotationDegree = oDocumentPage.RotationDegree + 360; //make sure this is a positive value.
                    int desiredRot = oDocumentPage.RotationDegree;
                    PdfDictionary oPageDict = oPDFReader.GetPageN(pageNum);
                    PdfNumber rotation = oPageDict.GetAsNumber(PdfName.ROTATE);
                    if (rotation != null)
                    {
                        desiredRot += rotation.IntValue;
                        desiredRot %= 360; // must be 0, 90, 180, or 270
                    }

                    oPageDict.Put(PdfName.ROTATE, new PdfNumber(desiredRot));
                }
            }
            stamper.FormFlattening = true;
            stamper.Writer.CloseStream = false;
            stamper.Close();
            retVal = oOutput.ToArray();
            oOutput.Close();
        }
        return retVal;

But when I run this in ghostscript, I get the following error:

    **** Warning: An error occured while reading an XREF table.
    **** The file has been damaged.  This may have been caused
    **** by a problem while converting or transfering the file.
    **** Ghostscript will attempt to recover the data.
    ****
    **** This file had errors that were repaired or ignored.
    **** The file was produced by:
    **** >>>> Adobe LifeCycle Designer ES 8.2; modified using iTextSharp 4.1.6 by 1T3XT <<<<
    **** Please notify the author of the software that produced this
    **** file that it does not conform to Adobe's published
    **** PDF specification.

I'm currently referencing ghostscript in a WCF project, so this console.out message actually crashes my program. Ideally I want to generate the PDF without the program throwing this error, but alternatively I'm looking into hosting this WCF in a console so it can throw out repairable errors to its heart's content.

Any idea?

E S
  • 23
  • 5
  • What is your gs version? And can you provide a sample problem result pdf. – mkl Nov 21 '13 at 19:31
  • There doesn't appear to be any error, just a warning, and Ghostscript is repairing the file. As mk1 says, we'd need to see a smaple file to have any chance of telling you what's wrong. Possibly you will end up having to report a bug against iTextSharp (are you using the latest version of this ?) – KenS Nov 21 '13 at 21:07

0 Answers0