Is there a way to get the PdfField's inside a fillable pdf in a specific order?? #1490
-
Is there a variable to store the order of When I am using below code snippet for the attached file,
I am getting the fields in different order then they are in the pdf. Any help how to get the fields in the order as in the file? |
Beta Was this translation helpful? Give feedback.
Answered by
satyajitnayk
Jul 31, 2023
Replies: 1 comment
-
Found the solution: import {PDFDocument} from 'pdf-lib';
const fields = pdfDocument
.getForm()
.getFields()
.sort((f1, f2) => {
// sort by y coordinate value(y value more means the text is on top)
const y1 = f1.acroField.getWidgets()[0].getRectangle().y;
const y2 = f2.acroField.getWidgets()[0].getRectangle().y;
return y1 < y2 ? 1 : y1 > y2 ? -1 : 0;
}); |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
satyajitnayk
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Found the solution:
using
y coordinate
(vertical position) we can sort the fields.