Giter Site home page Giter Site logo

Comments (4)

GeorgRottensteiner avatar GeorgRottensteiner commented on June 11, 2024

Running into the exact same issue. Since my usage is automated extraction manual repairing of the file is not an option.

Edit: Simple skipping setting the reference does not help fully for me. The document ends up with zero pages, although shows up fine with any other PDF viewer. Unfortunately I cannot share the document as it contains private data.

from pdfsharpcore.

StLange avatar StLange commented on June 11, 2024

It seems that the PDF is formatted incorrectly and Acrobat can fix it.
We would like to fix this, but without the PDF file it is not possible. Please send the file to โ€œissues (at) pdfsharp.netโ€
We keep the PDF file secret and only use it to fix the bug.

from pdfsharpcore.

cacowen avatar cacowen commented on June 11, 2024

File has been sent. Issue still happens in PdfSharpCore. The file can be read in PdfSharp, PdfPig, and others. Thank you.

from pdfsharpcore.

StLange avatar StLange commented on June 11, 2024

I have received the file. The reason for the issue is that the reference to object 312 is mentioned twice in the file. In PDFsharp (not in PdfSharpCore) I fixed this by removing the first entry when an identical second entry occurred. See original source code from PDFsharp 6.1 below.

In PdfSharpCore just call ObjectTable.Remove(iref.ObjectID) if the object is already in the table. This is line 75 in PdfCrossReferenceTable.cs in PdfSharpCore. I did not test it, but Iโ€™m pretty sure that it works.

        /// <summary>
        /// Adds a cross-reference entry to the table. Used when parsing the trailer.
        /// </summary>
        public void Add(PdfReference iref)
        {
            if (iref.ObjectID.IsEmpty)
                iref.ObjectID = new(GetNewObjectNumber());

            // ReSharper disable once CanSimplifyDictionaryLookupWithTryAdd because it would not build with .NET Framework.
            if (ObjectTable.ContainsKey(iref.ObjectID))
            {
#if true_
                // Really happens with existing (bad) PDF files.
                // See file 'Detaljer.ARGO.KOD.rev.B.pdf' from https://github.com/ststeiger/PdfSharpCore/issues/362
                throw new InvalidOperationException("Object already in table.");
#else
                // We remove the existing one and use the latter reference.
                // HACK: This is just a quick fix that may not be the best solution in all cases.
                // On GitHub user packdat provides a PR that orders objects. This code is not yet integrated,
                // because releasing 6.1.0 had a higher priority. We will fix this in 6.2.0.
                // However, this quick fix is better than throwing an exception in all cases.
                PdfSharpLogHost.PdfReadingLogger.LogError("Object '{ObjectID}' already exists in xref table. The latter one is used.", iref.ObjectID);
                ObjectTable.Remove(iref.ObjectID);
#endif
            }
            ObjectTable.Add(iref.ObjectID, iref);
        }

from pdfsharpcore.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.