mikehaertl / php-pdftk

A PDF conversion and form utility based on pdftk
MIT License
939 stars 124 forks source link

add line break when filling data #296

Closed neutralchung closed 2 years ago

neutralchung commented 2 years ago

Hello, I would like to ask about how to add a line break when filling form? I tried '\n' and <'br'>. But it is not working. It is any way to insert a line break? Thanks.

mikehaertl commented 2 years ago

Have you tried \r\n? If that doesn't work I have no idea either.

neutralchung commented 2 years ago

I tried but still no use. Hope others can find the solution.

mikehaertl commented 2 years ago

Have you tried if you can enter a linebreak when you use some PDF reader to fill the form? I think you can restrict input fields in PDF so that they don't allow linebreaks.

In any case I don't think this is an issue we can fix here, so I'm closing this.

neutralchung commented 2 years ago

The input fields can only multiline input. So there is no problem with the field. Only using code cannot insert linebreak.

mikehaertl commented 2 years ago

Can you fill the form in a reader program and somehow save the form data as Xfdf file? That's the XML format that is used to store and load form data. It should look something like this: https://github.com/mikehaertl/php-pdftk/blob/master/tests/files/XfdfFileTest.xfdf

Then you could check what the reader writes to that file for a linebreak.

mikehaertl commented 2 years ago

I just did a quick test myself:

I've also added this to the tests:

https://github.com/mikehaertl/php-pdftk/blob/c856d2da0749df07354696801261465fba563a9c/tests/XfdfFileTest.php#L30

https://github.com/mikehaertl/php-pdftk/blob/c856d2da0749df07354696801261465fba563a9c/tests/files/XfdfFileTest.xfdf#L68-L72

So I can't find any issue. The only thing I had to make sure: You really need to enable the multiline option when you create the PDF.