Fill form text fields with custom font in v.1.x.x
See original GitHub issueThis library is really great! I really appreciate your many efforts.
I could understand how to fill form in v.1.x.x by @gfb107’s helpful code. https://github.com/Hopding/pdf-lib/issues/185#issuecomment-529146128
I want to try to use custom fonts to fill form, because standard fonts do not include another languages like Japanese.
I already tried in v.0.6.4 example below, but it did not work.
https://github.com/Hopding/pdf-lib/issues/48#issuecomment-441111299
(It freezed at last line PDFDocumentWriter.saveToBytes
)
I searched documents but not found.
Could you show us example in v.1.x.x? With many thanks.
Issue Analytics
- State:
- Created 4 years ago
- Comments:18 (3 by maintainers)
Top Results From Across the Web
Setting custom attributes on form fields (e.g. font, point size ...
Q: I have everything up and running and the new demo is working fabulously - compiles wonderfully on XCode where I do my...
Read more >PDF form field properties, Adobe Acrobat
In Adobe Acrobat, how a form field behaves is determined by settings in the Properties dialog box for that individual field.
Read more >Text Input and Custom Fonts (Godot Retro Text Adventure ...
In this tutorial we add a LineEdit node so that we can collect text input from the player in our Zork-like retro text...
Read more >Text fields - Material Design
A mobile UI for a contacts app form with many filled text fields. Mobile form using filled text fields ... Input text, Subtitle...
Read more >font-face - CSS: Cascading Style Sheets - MDN Web Docs
Chrome Edge
@font‑face Full support. Chrome1. Toggle history Full support...
OpenType CBDT and CBLC rendering Full support. Chrome66. Toggle history Full support...
OpenType COLRv0 rendering Full...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Update (9/16/2020)
pdf-lib
now has form creation and filling APIs that should be used instead of the below example(s). They automagically handle creating the appearance streams for you. See the form filling JSFiddle for a working example. Additional information is available in the README and API docs. See also Creating and Filling Forms for an example of filling form fields with a custom font.Original
Hello @astanet!
In my experience, the most straightforward and flexible way to fill AcroForm text fields is to avoid writing your own appearance streams (that is what the HummusJS code you shared is doing). This is because the reader tends to be able to make things look nicer than custom pdf-lib/HummusJS code can. And perhaps more importantly, allowing the reader to construct its own appearance streams avoids the need to embed custom fonts and having to worry about the character sets they support.
I’ve documented how to do this here (along with an example script). It’s also worth noting that while it is possible to specify a custom font for readers to use while still constructing their own appearance streams, this is challenging to do right now in pdf-lib for embedded fonts (it’s easy for standard fonts though). This is because pdf-lib embeds all non-standard fonts as CID fonts, and the only reader I’ve found that can produce its own appearance streams for CID fonts is Adobe Acrobat.
However, there are certainly still many cases where it is most appropriate to write your own appearance streams. So I’ve created a script demonstrating how to do this: pdf-lib_custom_font_form_fill.zip
And here’s the gist of the script (in case you’d like to browse the code without downloading the ZIP file):
And here’s the output file: filled.pdf
<kbd>I hope this helps. Please let me know if you have any additional questions!
pdf-lib
now has form creation and filling APIs that should be used instead of the above example(s). They automagically handle creating the appearance streams for you. See the form filling JSFiddle for a working example. Additional information is available in the README and API docs. See also Creating and Filling Forms for an example of filling form fields with a custom font.