Pdf-lib: A simple browser example

Created on 11 Apr 2019  路  3Comments  路  Source: Hopding/pdf-lib

The example documentation says it "contains detailed examples of how to use pdf-lib to both create and modify documents in Node, Browser, and React Native environments."

AFAI can see, it only contains examples for Node. If not, where are they hidden? :smile_cat:

In any case, what I was wondering was how to get the bytes needed from a browser File object into pdf-lib, which I through some searching in the issues saw was already answered.

response.arrayBuffer()
  .then(function(buffer) {
    const existingPdfDocBytes = new Uint8Array(buffer);
    const pdfDoc = PDFLib.PDFDocumentFactory.load(
      existingPdfDocBytes
    );

I think having a super-simple example in the example folder with an index.html, a test pdf and the above code would be sufficient for most to get working. I could supply it as a PR, unless it already exists?

enhancement

All 3 comments

Hello @fatso83! Unfortunately no such example exists in this repo at the moment. I was working on some browser and React Native examples awhile ago, but got busy with other issues. So I鈥檝e never had a chance to finish and commit them. I鈥檇 greatly appreciate PRs for this if you鈥檙e willing to help out!

Done :) #92

v1.0.0 was just released. It includes multiple browser examples (inspired by your work in #92), so I think it's reasonable to close this now.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

faxemaxee picture faxemaxee  路  6Comments

lepidotteri picture lepidotteri  路  3Comments

jboxxx picture jboxxx  路  4Comments

ihmc3jn09hk picture ihmc3jn09hk  路  4Comments

kevinswartz picture kevinswartz  路  8Comments