Hopding / pdf-lib

Create and modify PDF documents in any JavaScript environment
https://pdf-lib.js.org
MIT License
7.02k stars 676 forks source link

On pdf.flatten() check mark getting removed from flattened pdf #1574

Open satyajitnayk opened 11 months ago

satyajitnayk commented 11 months ago

What were you trying to do?

Trying to flatten the pdf!

How did you attempt to do it?

form_to_flatten.pdf

import fs from 'fs';
import { PDFDocument } from 'pdf-lib';

const flattenPDF = async () => {
  const pdfDocument = await PDFDocument.load(
    fs.readFileSync('form_to_flatten.pdf')
  );
  const pdfForm = pdfDocument.getForm();

  pdfForm.flatten();
  const pdfBytes = await pdfDocument.save();

  fs.writeFileSync('flattened.pdf', pdfBytes);
};

flattenPDF();

What actually happened?

the flattened pdf is missing check mark in check boxes.

Visuals

original pdf flattened pdf
image image

What did you expect to happen?

the flattened pdf should not have missing check mark in check boxes. They should be intact.

How can we reproduce the issue?

we can reproduce this using pdf & script provided in How did you attempt to do it? section.

Version

1.17.1

What environment are you running pdf-lib in?

Node

Checklist

Additional Notes

No response

satyajitnayk commented 11 months ago

referenced in https://github.com/cantoo-scribe/pdf-lib/issues/41