question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: A PDF file must end with an EOF line.

See original GitHub issue

I had some problems when reading the pdf file from the buffer, since once called the function .sign (), this throws the following error:

/Users/iopazo/Develop/uno/transmision-api/node_modules/node-signpdf/dist/helpers/removeTrailingNewLine.js:40
     throw new _SignPdfError.default (
     ^

Error: A PDF file must end with an EOF line.

Imagine the problem was with one of my PDF files, but checking these if they have the final line.

Here is my integration:

    const signer = require('node-signpdf').default;

    let pdfBuffer = fs.readFileSync(file);

    const signedPdf = signer.sign(pdfBuffer, fs.readFileSync(signature));
    console.log(signedPdf);

comprobante_incorporacion.pdf

From already thank you very much!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
PedroS11commented, Oct 3, 2019

So how should I solve this problem ? All my pdf’s have that null byte in the end and I can’t trim a buffer.

1reaction
ValZapodcommented, Mar 16, 2022

This 0x00 is added by some dumb network app. See this for example: https://doc.lagout.org/science/0_Computer Science/3_Theory/Mathematics/Exploring Abstract Algebra with Mathematica [Hibbard %26 Levasseur 1999-02-19].pdf

the file has 0x00 in the end and yet otherwise bitperfect file from libgen does not have it! WTF. https://libgen.li/edition.php?id=139704336

As for 0D 0A I suppose the standard is vague enough.

Considering that all lines end with \r, \n or both

That is wrong. Last line ends with nothing. If it ends with those, there is now a new line. But here the pdfs created by Acrobat are the reference, both docx printed to pdf and .ps files to pdf by Distiller end in 0D 0A.

**Back in the Adobe 1.3 specification, in Appendix H (Implementation notes), you’ll find this little snippet about the properties of the Acrobat viewer (not the file format):

3.4.4, “File Trailer”

Acrobat viewers require only that the %%EOF marker appear somewhere within the last 1024 bytes of the file.**

Source: https://stackoverflow.com/questions/11896858/does-the-eof-in-a-pdf-have-to-appear-within-the-last-1024-bytes-of-the-file

Read more comments on GitHub >

github_iconTop Results From Across the Web

Does the %%EOF in a PDF have to appear within the last ...
Acrobat viewers require only that the %%EOF marker appear somewhere within the last 1024 bytes of the file. In other words, it's saying...
Read more >
Re: end-of-file (EOF) marker as required by the PD... - 11937490
I'm trying to upload a PDF to a site but, no matter what I do, I keep getting the following error message: This...
Read more >
Bug #168263 (eofpdf) “Any chars after %%EOF break the pdf ...
NO! The message of pdfopt was right. There are no chars allowed after the end of file sign %%EOF. The file corner45.pdf has...
Read more >
'Fixing PDF EOF Errors with PyPDF' - MARC
Yet all of those files can be open successfully with Adobe Acrobat Reader. ... line-height: 18px; white-space: \ nowrap; ">def fixPdf(pdfFile):<br ...
Read more >
PDF file format: Basic structure [updated 2020]
The last line of the PDF document contains the end of the “%%EOF” file string. ... We must remember that the initial structure...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found