Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to parse PDF document (line:24 col:934 offset=4584): No PDF header found #1713

Open
2 tasks done
AliYar-Khan opened this issue Dec 7, 2024 · 0 comments
Open
2 tasks done

Comments

@AliYar-Khan
Copy link

What were you trying to do?

I am getting a pdf document in unit8array as follows

[
   37,  80, 68,  70,  45,  49,  46,  52,  10,  37, 211, 235,
  233, 225, 10,  49,  32,  48,  32, 111,  98, 106,  10,  60,
   60,  47, 84, 105, 116, 108, 101,  32,  40,  97,  98, 111,
  117, 116, 58,  98, 108,  97, 110, 107,  41,  10,  47,  67,
  114, 101, 97, 116, 111, 114,  32,  40,  77, 111, 122, 105,
  108, 108, 97,  47,  53,  46,  48,  32,  92,  40,  88,  49,
   49,  59, 32,  76, 105, 110, 117, 120,  32, 120,  56,  54,
   95,  54, 52,  92,  41,  32,  65, 112, 112, 108, 101,  87,
  101,  98, 75, 105,
  ... 6013 more items
]

I am converting it to String using this below code

 const str = unit8array
          .map((code) => String.fromCharCode(code))
          .join('');

It contains this data

%PDF-1.4
%Óëéá
1 0 obj
<</Title (about:blank)
/Creator (Mozilla/5.0 \(X11; Linux x86_64\) AppleWebKit/537.36 \(KHTML, like Gecko\) HeadlessChrome/131.0.0.0 Safari/537.36)
/Producer (Skia/PDF m131)
...
trailer
<</Size 25
/Root 14 0 R
/Info 1 0 R>>
startxref
5536
%%EOF

How did you attempt to do it?

I tried to load the str

const pdfDoc = await PDFDocument.load(str, {
          ignoreEncryption: true,
        });

What actually happened?

generate-pdf-appwrite\node_modules\pdf-lib\cjs\core\errors.js:229
        _this = _super.call(this, msg) || this;
                       ^

Error: Failed to parse PDF document (line:24 col:934 offset=4584): No PDF header found

What did you expect to happen?

It should load the string as pdf document

How can we reproduce the issue?

Get a pdf in unit8array
convert it to string
Load it
const pdfDoc = await PDFDocument.load(str, {
ignoreEncryption: true,
});

Version

1.17.1

What environment are you running pdf-lib in?

Node

Checklist

  • My report includes a Short, Self Contained, Correct (Compilable) Example.
  • I have attached all PDFs, images, and other files needed to run my SSCCE.

Additional Notes

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant