Giter Club home page Giter Club logo

Comments (12)

galkahana avatar galkahana commented on July 20, 2024

Probably not cause by that time some content is already written to the file and its a bit contrary to how pdfwrite doesnt things to go back.
How about you tell me more about why copying failes? Do you have a sample?

(Alternatively you could always work with two pdfs. Do action first on one, if doesnt fail, do on the other one)

from pdf-writer.

magicboker avatar magicboker commented on July 20, 2024

Please check this sample PDF
There is a missing object whose object ID = 16, but is referenced by an annotation object whose object ID = 19, in its "Parent" entry so CopyObject failed in copying source object ID = 19.
Is there any way that i can skip the failed object without writing a temp file (to rollback if failed) for every object copy?

from pdf-writer.

galkahana avatar galkahana commented on July 20, 2024

Well, this is something that PDFWriter should be corrected to handle. i mean, it is a valid possibility.

Gal.

from pdf-writer.

magicboker avatar magicboker commented on July 20, 2024

The ideal result is to skip the object copying on missing objects only.
i.e. for the missing object ID = 16, referenced by the other object (ID = 19) in its "Parent" entry, just skip copying the object whose ID = 16 and keep the destination exactly the same with the source is ideal although the missing condition will still preserve in the destination.

from pdf-writer.

galkahana avatar galkahana commented on July 20, 2024

I could make it into copying a null in this case, or create a deleted object entry. We will have to see which would be a more reliable recreation of the origin

from pdf-writer.

magicboker avatar magicboker commented on July 20, 2024

Do you mean to assign a deleted object ID (marked as unused in the xRefTable) for a missing object?

from pdf-writer.

galkahana avatar galkahana commented on July 20, 2024

that's a good option - if that's what makes 16 missing. is 16 marked as such? is it simply null? whatever it is in the source document...it's probably best to do the same in the target. i'm taking a look now

from pdf-writer.

magicboker avatar magicboker commented on July 20, 2024

What did you mean copying a null? (did you mean to replace the missing object ID with 0 ?) I am not as familiar with PDF spec as you. You are the PDF expert!!!

from pdf-writer.

galkahana avatar galkahana commented on July 20, 2024

yap. committed a solution along this line now. you can try it out. for me it worked well on the sample file, copying the annotation, and i also tried to append a page and it seemed to create a PDF is fine.

from pdf-writer.

magicboker avatar magicboker commented on July 20, 2024

It worked for the sample pdf.
Thank you very much for the solution!

However, do you have a solution for the case that a missing object has no associated deleted entry in the xRefTable?

from pdf-writer.

galkahana avatar galkahana commented on July 20, 2024

Look, it's valid to have deleted elements. the lib should take care of this case. it didn't and thanks to your note it's ok now.
anything else is just invalid. there are plenty possible exceptions. we could have an element pointing to an element it shouldn't (just having a wrong xref). xref table could be providing wrong positions (someone sent me a PDF like that recently). i think failing is a good policy then.

we could be writing another version of the copying method to handle all possible cases and fill up things with deleted elements (for instance, it could just do what i did for all "else" cases), but i feel that sometimes its ok to just fail if the file is invalid.

If you have an actual PDF that bothers you and you think we can figure out a good way out, we can tailor something around it together.

Gal.

from pdf-writer.

magicboker avatar magicboker commented on July 20, 2024

You are right!

from pdf-writer.

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.