Comments (4)
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.
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.
File has been sent. Issue still happens in PdfSharpCore. The file can be read in PdfSharp, PdfPig, and others. Thank you.
from pdfsharpcore.
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)
- Watermark Stream with negative height
- System.ArgumentException is thrown when creating XFont object with a custom font resolver
- Pdf Document Metadata and Properties are incorrect when adding UserPassword or OwnerPassword
- a release in .NET 7+ HOT 1
- Does it support adding electronic seals in PDf?
- ๐ Still alive? HOT 3
- pdfsharpcore file size grows thrice after edit and save for header and footer
- pdfsharpcore is missing NuGet package README file
- Does not extract images from PDF HOT 4
- Dependency issue with new version of the ImageSharp HOT 18
- Base package without ImageSharp
- Non ascii characters are not correctly displayed when created on Linux (Openshift)
- Visual Studio detecting Venerability with SixLabours.ImageSharp dependencies HOT 6
- Cannot insert image. HOT 10
- Can we take latest SixLabors / ImageSharp version which is v3.1.4 HOT 1
- Add Attachment to PDF-File (.xml File)
- System.IndexOutOfRangeException: Index was outside the bounds of the array.
- Problem adding grayscale jpeg file to pdf document with ImageSharp 2.x HOT 1
- Trailer: ID is not space-separated. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pdfsharpcore.