The initial problem is still there - changes are not rendered in the document
until it is saved, so how do I commit inline changes to stream to the
browser?  This is a common problem I am sure, to stamp a document with a
watermark before rendering it to the browser, but without changing the
original document.  It is possible to work around by creating a temporary
file, then streaming that, but this causes potential file access conflicts
from users requesting the same file, and housecleaning and potential
permission problems that should not be there - plus it adds significant
overhead to an already memory intensive operation (it takes a while to read,
watermark, save, and re-read an 800 page PDF).

If anyone has any insight, please help out a Zend framework newb.

Regards,
Tim Everson



Tim Everson wrote:
> 
> 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-tp24850906p24866882.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to