jorisschellekens / borb

borb is a library for reading, creating and manipulating PDF files in python.
https://borbpdf.com/
Other
3.4k stars 147 forks source link

Update page.py #135

Closed githobbes closed 1 year ago

githobbes commented 2 years ago

the list of annotations can sometimes contain an entry of type NoneType; these functions break in this instance

jorisschellekens commented 2 years ago

Hi there,

Thanks for spotting this bug!

Can you please send me a signed copy of the contributor agreement? Otherwise (from a legal perspective at least) it becomes difficult for me to retain ownership of the codebase.

Kind regards, Joris Schellekens

githobbes commented 2 years ago

borb Contributor License Agreement

In order for borb to have a clear understanding with respect to its ownership of and rights in the intellectual property rights associated with the borb software library (hereinafter “borb Project”) and to clearly determine the responsibilities and obligations associated with the Contributions (as defined hereinafter), borb must receive a signed borb Contributor License Agreement from the Contributor (as defined hereinafter) indicating the Contributor’s agreement with the terms and conditions set forth herein. This borb Contributor License Agreement (hereinafter “the Agreement”) intends to protect the Contributor as well as borb.

The Contributor hereby accepts and agrees to the following terms and conditions with regard to past, current and future Contributions submitted by the Contributor to borb.

Definitions

When used in this Agreement the following words and or expressions shall have the meaning as stated hereunder unless the context expressly requires otherwise:

1.1. “Contributor” means any individual and/or legal entity that voluntarily submits one or more Contribution to the borb Project.

1.2. “Contribution” means any original work of authorship, including any modification and/or addition to the existing work that is submitted for introduction in, or documentation of, any of the products owned or managed by borb, where such work originates from a Contributor. A Contribution may be submitted in any form of electronic, verbal and/or written communication or documentation, including without limitation, communication on electronic mailing lists, source code control systems and issue tracking systems that are managed by or on behalf of borb for the purpose of discussion and improving the results of the borb Project.

Article 2: Granted Rights - Representations

2.1. For the benefit of borb, the Contributor hereby agrees to the following:

2.2. Upon the assignment of the Proprietary Rights and the grant of the license as set forth in this article 2, borb hereby grants to the Contributor a perpetual, non-exclusive, worldwide, fully-paid up, royalty-free license to make, use, reproduce, distribute, modify and prepare derivative works based on the Contributions of the Contributor.

2.3. The Contributor hereby represents and warrants that:

2.4. In case under applicable law the Contributor retains the moral rights or other inalienable rights to the Contributions, the Contributor agrees not to exercise such rights without the prior written permission of borb. To the maximum extent permitted by law, the Contributor further waives and agrees not to assert such moral rights (if any) against borb or its successors in interest, or any of its licensees, either direct or indirect.

2.5. In order to ensure that borb will be able to acquire, use and protect its Proprietary Rights as detailed in this article 2, the Contributor will:

Article 3: Warranties

EXCEPT FOR THE EXPRESS WARRANTIES DETAILED IN ARTICLE 2, THE CONTRIBUTIONS ARE PROVIDED “AS IS” AND NEITHER THE CONTRIBUTOR NOR BORB MAKES ANY WARRANTIES OF ANY KIND TO THE OTHER PARTY, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION OF ANY WARRANTY OF MERCHANTAIBILITY OR FITNESS FOR A PARTICULAR PURPOSE.

Article 4: Miscellaneous

4.1. This Agreement shall enter into force upon execution of this document by the Contributor. This Agreement may be terminated by either party if the other party commits a breach of this Agreement, provided that if the breach is capable of remedy termination shall not occur if the breach shall have been remedied within 90 days of such other party having been given notice in writing specifying the breach and requiring it to be remedied. Notwithstanding any termination of this Agreement, this Agreement shall remain in full force and effect with respect to any Contribution submitted prior to the termination date of the Agreement.

4.2. This Agreement contains the entire agreement between the parties and supersedes all prior or contemporaneous agreements or understanding, whether written or oral, relating to its subject matter. If any provision of this Agreement shall be deemed invalid or unenforceable, the validity and enforceability of the remaining provisions of this Agreement shall not be affected and such provision shall be deemed modified only to the extent necessary to make such provision consistent with applicable law.

4.3. The Agreement is governed by the laws of Belgium, without reference to its conflict of law principles.

4.4. borb shall have the right to assign its rights and obligations hereunder, including (without limitation) to any successor or assignee of its business or assets to which this Agreement relates, whether by merger, establishment of a legal entity, acquisition, operation of law or otherwise without the prior written consent of the Contributor. The Contributor may not assign its rights and obligations under this Agreement, including by operation of law, without the prior written consent of borb, and as a condition to any such assignment, the Contributor's assignee must agree in writing to abide by all of the rights and obligations of the Contributor set forth in the Agreement. Please execute two (2) original copies of the above document and send this to the following recipient:

The recipient:
Joris Schellekens
Gentbruggestraat 76
9040 Sint-Amandsberg
BELGIUM

The Contributor:
Name: Michael Phillips Date: Oct 25, 2022 Signature: Michael J. Phillips

githobbes commented 2 years ago

Is this what you needed? I've never "contributed" before, so I'm a bit new to this.

jorisschellekens commented 2 years ago

Not a problem.

This is almost what I need. Where it says "signature" I expect your actual signature. I'm sure you can understand that a plaintext document with your name isn't exactly going to convince anyone that it wasn't forged :smile:

You can simply take screenshot(s) of the markdown file, take a picture of your signature on a white piece of paper, and use image editing software to paste your signature on each page.

If that's too much of a hassle for you, I completely understand. In which case I'll make sure to implement these changes myself.

Kind regards, Joris Schellekens

githobbes commented 2 years ago

I'm sending over three PDFs. One of them is the signed Contributor License Agreement (the printwithme-scan file).

The other two are related to the issue that manifested my issues, in case you wanted to see them. I edited sample_page_0.pdf using Adobe's Edit Forms software to create front_page.pdf. I'm not sure what led to a NoneType annotation, but that's life, I guess.

Thanks, Joris!!

front_page.pdf sample_pa [printwithme-scan-8940759.pdf](https://github.com/jorisschellekens/borb/files/9872328/printwithme-scan-8940759.pdf) ge_0.pdf

jorisschellekens commented 2 years ago

It's been such a busy week. My apologies that I haven't gotten around to checking out this bug any sooner. I'll try to look into it next Tuesday (which is a holiday in Belgium).

Kind regards, Joris Schellekens

githobbes commented 2 years ago

Since I've got a reliable line on you, I wanted to ask how I would go about splitting the content in front_page.pdf (a file I shared above) onto two separate pages. I want to be able to print the contents of front_page.pdf onto two separate standard sheets of paper.

Thanks! Hope you're well.

githobbes commented 2 years ago

I've spotted something. There's the right number of annotations; the first annotation is supposed to correspond (at least in front_page.pdf) to the Form Field that I inserted just to the right of the text that reads "Acct:" near the top of the page.

I'm not sure why this is happening...

jorisschellekens commented 2 years ago

Hi there,

I do not want to encourage off-topic discussions on GitHub issues. If people start doing that, soon important information might get lost in a "I think it was in a GitHub thread somewhere". Let's stick to 1 bug/feature request per issue.

Also, these issues are meant for:

Your question is more of a "How do I do X with borb?" You can use StackOverflow for that.

We also offer a paying support plan, should you so desire.

Kind regards, Joris Schellekens

githobbes commented 2 years ago

My apologies, Joris. Have you figured out why the getter function is reading one of the annotations as None?

jorisschellekens commented 2 years ago

No, I haven't. But it doesn't really matter. In PDF syntax, you are allowed to create an object and then mark it as deleted (using the so-called cross-reference table). So regardless of this particular issue, a None-check should be in place.

Kind regards, Joris Schellekens

githobbes commented 2 years ago

Joris,

I think it absolutely should matter. If I make 10 TextFields using Adobe Acrobat, then load the PDF using borb and read out the list of annotations, there are 10 annotations (the correct number) but where the data for one of the annotations should be, there's nothing.

jorisschellekens commented 2 years ago

Your XRef table has 215 entries, only 183 of those are currently marked as in_use. All those (not in use) entries should (according to the spec) be treated as if they weren't there (to put it simply), hence the None.

I can't imagine another reason why borb would generate None. I would expect either an empty Dictionary or an empty Array (or perhaps an error when failing to create such an object). None can only come from the XRef reading an object that is not in use.

snippet from xref.py

        # reference points to an object that is not in use
        assert isinstance(indirect_reference, Reference)
        if not indirect_reference.is_in_use:
            obj = None

I am not responsible for other PDF libraries/programs creating malformed PDF documents.

Kind regards, Joris Schellekens