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

Reading order after flatten method call #895

Closed
Foohx opened this issue May 26, 2021 · 6 comments
Closed

Reading order after flatten method call #895

Foohx opened this issue May 26, 2021 · 6 comments

Comments

@Foohx
Copy link

Foohx commented May 26, 2021

Hello everybody,

I have a template of a tagged PDF file, which has a reading order defined to be properly read by screen readers (Voice Over, NVDA, JAWS ..). The values I want to insert into the model are represented by inputs.

My test template : input.pdf

So I get the fields, add a value to them then I flatten the document before saving it.

import { readFileSync, writeFileSync } from "fs";
import { PDFDocument } from "pdf-lib";

const fileBytes = readFileSync("./input.pdf");
const pdf = await PDFDocument.load(fileBytes);

const form = pdf.getForm();
const fields = form.getFields();
fields.forEach((field) => {
  const type = field.constructor.name;

  if (type === "PDFTextField") {
    field.setText("Test");
  } else if (type === "PDFDropdown") {
    const options = field.getOptions();
    field.select(options[0]);
  }
});

form.flatten({ updateFieldAppearances: true });

const outputBytes = await pdf.save();
writeFileSync("./output.pdf", outputBytes);

The problem is with the output.pdf file.
When I try to read it through a screen reader, my flattened values are present instead of the template inputs, however they are unreadable by screen readers.

It's as if they don't exist..
Do I have to tag/do something or use another solution?

Thank you in advance.

@Hopding
Copy link
Owner

Hopding commented Sep 23, 2021

pdf-lib doesn't provide special support for tagged PDFs. This is something I'd like to improve though, so I've added it to the roadmap for tracking: #998.

@pablodenadai
Copy link

Hi @Foohx did you find a solution to this?

@pablodenadai
Copy link

@Hopding would you be able to point us in the right direction if we were to create a PR for this issue?

@Foohx
Copy link
Author

Foohx commented Dec 19, 2021

@pablodenadai not really, but I got around the problem.

I decided to no longer use forms directly within PDFs. I am using a web form and generating the final PDF accordingly.
This way, my reading order is always correct and I can validate all the datas before writing them in the document.

EDIT: I also use another library (more low level) allowing a finer control over the accessibility.

@LucianoGanga
Copy link

@Foohx , what's the library you used to get finer control over accessibility? I need to access and manipulate that part of the PDFs but I can't find a way to do it.

Thanks!

@Foohx
Copy link
Author

Foohx commented Mar 31, 2023

@Foohx , what's the library you used to get finer control over accessibility? I need to access and manipulate that part of the PDFs but I can't find a way to do it.

Thanks!

Hi,

I use the pdfkit lib.

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