2

I am using php pdftk to take data out of a mysql database and put it in a bunch of different fields on a PDF. My issue is a few of the fields potentially have long text however instead of then showing an up/down scroll bar or even being able to scroll up or down to read all the text it seems to just get cutoff. I am wondering if there is a specific pdftk tag or something I should use to ensure if the field has multiple rows that I can see a scroll bar to scroll up and down to ready all that would be entered in.

Here is how the pdf looks. when I load it via an iframe in the browser notice the textarea labeled HPI as multiple rows of text but no scroll bar or indication you can scroll up or down. enter image description here However if I open the template pdf file in adobe and type a bunch into that field see screenshot below you can then see a up/down scroll bar in the field labeled HPI enter image description here

Here is the code

   namespace Classes;
   use mikehaertl\pdftk\Pdf;

   class GeneratePDF {


       public function generate($data, $patientid)
       {      

              try {

                    $filename = "$patientid.pdf";

                    $pdf = new Pdf('./imports/the_template.pdf');
                    $pdf->fillForm($data)
                    ->saveAs( './imports/generated_consults/' . $filename);
                    //->send( $filename . '.pdf');

                    return $filename;

              }
              catch(Exception $e)
              {
                    return $e->getMessage();
              }
  

         }
     }
Jayreis
  • 253
  • 1
  • 7
  • 28
  • 2
    Would you be able to upload some code? (Just the bare minimum to recreate the issue) – Greg Jun 25 '20 at 23:58

1 Answers1

0

I assume your textarea is a text field of an interactive form. The content of interactive forms can be updated using the fill_form operation of pdftk.

Interactive forms are described in the PDF Reference, version 1.7 at section 8.6 – Interactive Forms. Available options and flags for text fields are described in tables 8.69, 8.70, 8.71, and 8.77.

As I understand the reference, you have to set the Multiline flag (bit position 13) and clear the DoNotScroll flag (bit position 24). Beside that, there does not seem to be another option for that. However, I would also try if using a RichText (bit position 26) makes a difference.


If you don't modify the values of fields in a form but directly inject text objects into the PDF (I'm not sure if pdftk can even do this), then there might be no easy solution. From the PDF Reference, version 1.7, chapter 2:

A page’s appearance is described by a PDF content stream, which contains a sequence of graphics objects to be painted on the page. This appearance is fully specified; all layout and formatting decisions have already been made by the application generating the content stream.

This means there is no automatic line breaking (aka. word wrapping) in PDFs. I could also not find the ability to include scroll bars within the document. After all, a goal of PDF is to achive a consistent appearance on all devices.

JojOatXGME
  • 3,023
  • 2
  • 25
  • 41