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

Feature request: Need APIs to access Acroform resources (Acroform->DR) #106

Open
panneer opened this issue May 25, 2020 · 2 comments
Open

Comments

@panneer
Copy link

panneer commented May 25, 2020

Hey @corymickelson

I first thank you for your great work (nopodofo).

I need a feature to access the acroform defined resources (Acroform->DR). Could you tell me whether you have a plan for this feature in your road map and when I could expect it?

I could not share the PDF sample for privacy reasons.

My actual use case
PDF is defined

  1. With a Acroform dictionary as shown below

/CO: Array
/DA: /QuickPDFF6af2e376 0 Tf 0 0 0 rg
/DR: Dictionary
/Encoding: Dictionary
/Font: Dictionary
/Helv: 88 0 R
/QuickPDFF6af2e376: 158 0 R
/ZaDb: 89 0 R

  1. With a form field as shown below

/DA: /QuickPDFF6af2e376 11 Tf 0 0 0 rg
/F: 4
/FT: /Tx
/Ff: 8388608
/P: 95 0 R
/Q: 0
/Rect: Array
/Subtype: /Widget
/T: F4260
/TU:
/Type: /Annot
/V:
I would like to add value to this form field (with appropriate appearance dictionary)
I followed this reference (https://corymickelson.github.io/NoPoDoFo/documentation/cookbook/ap.html) for adding appearance stream

When adding the appearance stream for field, I don't want to create a new font for field value.
Instead, I wish to get 'QuickPDFF6af2e376' font from Acroform->DR. Like the font accessing APIs defined in Document object

getFont(name: string): Font
listFonts(): { id: string, name: string }[]

I am not sure whether nopodofo already has functionality to achieve my requirement.
Please give me some advise to meet my requirement

Thanks a lot in advance

@corymickelson
Copy link
Owner

Thank you @panneer the form class has an accessor to the dictionary resource via

const dr = form.DR

This returns a NoPoDoFo.Dictionary. Do you have an example of this not working for you? I understand the use case around getting fonts from this resource, I will look into this, but in the interim please try the DR property of the Form class.

@panneer
Copy link
Author

panneer commented May 28, 2020

I initially tried form.DR accessor to get the info about the font details and it works. Thanks

Still for my requirement, I need to get the Acroform->DR defined font as NFont object, so that I can assign this font in painter instance when creating appearance stream for the value. For example,
{code}font = form.getFont('Helv')
...
const painter = new nopodofo.Painter(doc)
...
painter.setPage(xobj)
...
painter.font = font // font object fetched from Form.getFont() API
painter.beginText({x: 2, y: 2})
...{code}

Basic idea is to use the field DA defined font for the field values.

> Do you have an example of this not working for you?
Yes, I have attached the sample program (with a PDF sample). Hope it helps you.
Attachment: sample-program.zip

> I understand the use case around getting fonts from this resource, I will look into this
Thank you so much

> but in the interim please try the DR property of the Form class.
Meanwhile, I took the liberty to extend the nopodofo source for my requirement and do achieved my requirement to certain extent. Please check the changes I made and let me know your opinion.
Attachment: form-font-access-changes.zip

Thanks a lot in advance and wish you nice day

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

2 participants