note 86063 added to function.pdf-add-textflow

[email protected]
Newsgroups php.notes
Message-ID <[email protected]>
If you get an error like this:

PHP Fatal error:  Allowed memory size of 16777216 bytes exhausted (tried to allocate 3072 bytes) in /var/www/html/pdf/starter_textflow.php on line 70

It is because you are sending too much data to the "add_textflow" function.  Increasing the memory in the php.ini file won't fix the problem.  The solution is to try buffering the data you send to the function.

For example, if this fails:

///////////////////begin code///////////////////////////////
$text=
"Lorem ipsum dolor sit amet, consectetur adi&shy;pi&shy;sicing elit, sed do eius&shy;mod tempor incidi&shy;dunt ut labore et dolore magna ali&shy;qua. Ut enim ad minim ve&shy;niam, quis nostrud exer&shy;citation ull&shy;amco la&shy;bo&shy;ris nisi ut ali&shy;quip ex ea commodo con&shy;sequat. Duis aute irure dolor in repre&shy;henderit in voluptate velit esse cillum dolore eu fugiat nulla pari&shy;atur. Excep&shy;teur sint occae&shy;cat cupi&shy;datat non proident, sunt in culpa qui officia dese&shy;runt mollit anim id est laborum. ";

//send lots of data all at once
$max=100;
for($i=0;$i<$max;$i++)
   $text .= $text;

$tf = $p->add_textflow($tf, $text, $optlist1);

//////////////////end code/////////////////////////////////

Try something like this instead:

///////////////////begin code///////////////////////////////
$text=
"Lorem ipsum dolor sit amet, consectetur adi&shy;pi&shy;sicing elit, sed do eius&shy;mod tempor incidi&shy;dunt ut labore et dolore magna ali&shy;qua. Ut enim ad minim ve&shy;niam, quis nostrud exer&shy;citation ull&shy;amco la&shy;bo&shy;ris nisi ut ali&shy;quip ex ea commodo con&shy;sequat. Duis aute irure dolor in repre&shy;henderit in voluptate velit esse cillum dolore eu fugiat nulla pari&shy;atur. Excep&shy;teur sint occae&shy;cat cupi&shy;datat non proident, sunt in culpa qui officia dese&shy;runt mollit anim id est laborum. ";

//send chunks of data
$max=100;
for($i=0;$i<$max;$i++)
   $tf = $p->add_textflow($tf, $text, $optlist1);

//////////////////end code/////////////////////////////////

In the second example we send less data, but we call the function more often.  With the first example, I could only generate 3 or 4 pages of a PDF; with the latter example I could generate 200+ page PDF's.

This took me a while to debug; hope it saves someone else some time. :)
----
Server IP: 209.41.74.194
Probable Submitter: 205.232.70.82
----
Manual Page -- http://www.php.net/manual/en/function.pdf-add-textflow.php
Edit        -- https://master.php.net/note/edit/86063
Del: integrated  -- https://master.php.net/note/delete/86063/integrated
Del: useless     -- https://master.php.net/note/delete/86063/useless
Del: bad code    -- https://master.php.net/note/delete/86063/bad+code
Del: spam        -- https://master.php.net/note/delete/86063/spam
Del: non-english -- https://master.php.net/note/delete/86063/non-english
Del: in docs     -- https://master.php.net/note/delete/86063/in+docs
Del: other reasons-- https://master.php.net/note/delete/86063
Reject      -- https://master.php.net/note/reject/86063
Search      -- https://master.php.net/manage/user-notes.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.