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

Fillable PDF Forms #44

Open
eiden109 opened this issue Jun 22, 2023 · 6 comments
Open

Fillable PDF Forms #44

eiden109 opened this issue Jun 22, 2023 · 6 comments

Comments

@eiden109
Copy link

Loving the package - the only issue I've ran into so far is form fields that are filled out in a PDF are converted into blank fields after the PDF is converted into an image.

I was wondering if anyone knows of any fixes or work arounds for this - or if I'm just doing something wrong lol - thanks in advance!

@thomas-robinpowered
Copy link

Also ran into this problem...not sure yet what's going on.

@aaron-md
Copy link

aaron-md commented Aug 18, 2023

Also ran into this problem...not sure yet what's going on.

I've found that you need to flatten the PDF first in order to capture any annotations made to a pdf. This can be done manually with the PDF file or through a different npm package. I use the pdf-lib npm package to flatten the pdf first, and then convert it into an image. Hope this helps!!!!

EDIT: Actually using a different package. See reply below.

@thomas-robinpowered
Copy link

@aaron-md maybe you can help me understand what I'm doing wrong. I'm using that library and flattening the pdf but the resulting png file doesn't have the text field.

my minimal code example:

import { convert } from "pdf-img-convert";
import { PDFDocument } from "pdf-lib";

PDFDocument.load(file).then((pdf) => {
  const form = pdf.getForm();

  const textField = form.getTextField("TextBox1");

  textField.setText("Hey, please work.");

  form.flatten();

  pdf.save().then((pdfUint8Array) => {
    const buffer = Buffer.from(pdfUint8Array);
    convert(buffer).then((converted) => {
      writeFileSync("minimal.png", converted[0]);
    });
  });
});

@aaron-md
Copy link

@thomas-robinpowered My apologies - I had looked over my old code a bit too quickly and gave you a misleading response. I actually am using the pdf2pic npm package for converting pdf's to images. I believe this package automatically flattens the pdf before converting, so this should solve any annotation issues. Let me know if this helps!!

@thomas-robinpowered
Copy link

@aaron-md thank you for getting back to me, I'll give that library a try!

@kuang
Copy link

kuang commented Sep 26, 2023

Running into this problem too - is fixing this on the roadmap at all?

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

No branches or pull requests

4 participants