I am trying to modify a document in memory and then render the result to the
browser without actually changing the document.  This sounds easy, with
Zend_pdf->render(), but I am finding that my changes to the document are not
in the rendered document.  So to workaround, I assume I must save the
document to a temporary file, then open THAT file in a new zend_pdf object
and render it to the browser, right?  Wrong again.  I am baffled to find
that the originally opened document is actually rendered instead, no changes
applied.  After the script runs, if I manually open the temporary PDF file
it created, my changes are there.

Is there some sort of commit action that must be performed to get the
changes to render before the script ends?  I cannot find an instance of
anyone talking about this before - maybe its just me.  Here's my code:

if(isset($argv[1])){
  $srcPDF = $argv[1];
  
  try{
    $ZendPDF = & new Zend_Pdf($srcPDF, 0, true);
    /**
     *  Stamp each page "UNRELEASED" in transparent gray Helvetica
     */
    
    $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA);
    $color = new Zend_Pdf_Color_Html('#000000'); //black
    
    foreach($ZendPDF->pages AS $PDFpg){
      //calculate the fontsize to use based on the dimensions of the page
      $fontSize = intval($PDFpg->getHeight() / 10);
      $PDFpg->rotate(($PDFpg->getWidth() / 2), ($PDFpg->getHeight() / 2),
45)
            ->setFont($font, $fontSize)
            ->setFillColor($color) //also sets font color
            ->setAlpha(0.2) //half opaque
            ->drawText('U N R E L E A S E D', ($PDFpg->getWidth() / 2) - (4
* $fontSize), ($PDFpg->getHeight() / 2) - ($fontSize / 2) );
    }
    
    
    //page changes are NOT committed at this point
    echo $ZendPDF->render(); //renders string data back to caller
    unset($ZendPDF);

  } 
  catch (Zend_Exception $e) {
    die("Caught exception: " . get_class($e) . "\n" . "Message: " .
$e->getMessage() . "\n");  
  }
} else {
  die("No source file");
}
-- 
View this message in context: 
http://www.nabble.com/Zend_pdf-doesn%27t-commit-changes-tp24850906p24850906.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to