i've tried setting the lineHeight with different values but the output seems to be the same. I am not able to set the distance between each line. This works perfectly as a node service that would accept a pdf file and an array of key:values that represent field names and it's values. Calibri might imply that you just whipped up the document. The typeface choice depends both on how you want to present the document. Heading size really depends on your stylistic preferences. For body font size, use 1012 points (depends on your typefaces). Let ff = multiline ? PDFNumber.of(1 << 0 | 1 << 12) : PDFNumber.of(1) Īt(PDFName.of('V'), omText(text)) For a good typography primer, take a look at Butterick's 'Typography in Ten Minutes'. So I've created a script demonstrating how to do this: pdf-lib_custom_font_form_fill.zipĪnd here's the gist of the script (in case you'd like to browse the code without downloading the ZIP file):Ĭonst fillAcroTextField = ( acroField, text, font, multiline = false ) => )) Use an online PDF editor to get your perfect document in minutes. You can add text, drawings, highlights, and redact or annotate your document without affecting its quality. However, there are certainly still many cases where it is most appropriate to write your own appearance streams. PDF editing simplified with DocHub Seamless PDF editing Editing a PDF is as simple as working in a Word document. 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. 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). I've documented how to do this here (along with an example script). 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. This is because the reader tends to be able to make things look nicer than custom pdf-lib/HummusJS code can. Hello 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). See also Creating and Filling Forms for an example of filling form fields with a custom font. Additional information is available in the README and API docs. See the form filling JSFiddle for a working example. They automagically handle creating the appearance streams for you. Pdf-lib now has form creation and filling APIs that should be used instead of the below example(s).
0 Comments
Leave a Reply. |