Closed ekzobrain closed 1 year ago
This is what I see:
test.font.pdf
:
test.font.result.1.pdf
:
What exactly has moved? Could you provide sample images?
I think I did not express myself correctly. It seems like text baseline (or other text/font parameters) changes (if there is such concept in PDF forms) and text inside field moves a little down and left. This image illustrates this:
Left doc (test.font.pdf) is filled with Adobe Acrobat and rigth (test.font.result.1.pdf) with HexaPDF.
That is to be expected since there is no standard in how a text field is rendered. HexaPDF tries to mimick Adobe Reader as close as possible.
Here is the result from Okular:
Here from Evince:
Here from yet another PDF viewer:
As you can see all viewer fill out the PDF form but the alignment etc. are not the same.
You should probably remove the background from those fields, then there wouldn't be doubled points etc. Alternatively, it is possible to create "comb" text fields which might be what you want here.
In fact currenty when filling with Adobe Reader - it looks correct in contract with HexaPDF. Try this:
So currently HexaPDf styles actually differ from current Adobe Reader (version 2023.003.20215) styles. Could this be fixed? Attached test.font.result.2.pdf was filled with Adobe Reader.
Or maybe text position inside field box could be configurable some way? Like option to supply text offset from top-left / bottom-right /etc field bbox... Or options like CSS alignment - top/middle/bottom, left/center/right :)
As I see with my Adobe Reader - it aligns text by the top/right corner, while HehaPDF tries to center it both vertically and horizontally.
As I said before the HexaPDF form field appearance generator already tries to mimick what Adobe Reader does as closely as possible. If you find a way to get it more accurate, you are welcome to provide a pull request. Alas, as far as I know there is no written reference for this by Adobe.
Once an application that can create form field appearance streams fills out a form, it also generates the associated appearance streams (HexaPDF supports this). Then all viewers render the form fields the same since they have been pre-rendered by the form-filling application. This is what happens with the file you filled out with Adobe Reader. And also with the one filled out by HexaPDF.
[Sidenote: PDF2.0 actually specifies that all applications have to generate such appearance streams.]
If you want to customize the rendering of appearance streams, create a subclass of the appearance generator (see https://github.com/gettalong/hexapdf/blob/master/lib/hexapdf/type/acro_form/appearance_generator.rb) and then set the configuration option 'acro_form.appearance_generator' (see https://github.com/gettalong/hexapdf/blob/master/lib/hexapdf/configuration.rb#L148-L152).
Ok, we'll try custom appearance generator, thanks.
After filling AcroForm fields with HexaPDF fields move from their initial positions in any viewer. Reproduction script:
test font.pdf test font result 1.pdf
If we then open test font result 1.pdf with Adobe Acrobat, change font in field Date1 to another one, then return back original font and save document - field position becomes correct again.