Glad it works,

In my real app I have headers that also work for inline viewing, however
I've been running the Win7rc and it and adobe pdf reader + browser does not
like to play nicely. The inline viewing crashes or launches the reader then
fails with an error message and after closing, it shows the pdf in the
browser. I'm hoping its just a rc glitch.

I haven't dug in to the code yet but I noticed in the example in the manual
they used the save/restore after every modification. 

However, I don't see a way to export a page to an image - which is what I
need also.

Happy it worked for you and thanks for sharing your code adjustments.

Terre


-----Original Message-----
From: Tim Everson [mailto:[email protected]] 
Sent: Friday, August 07, 2009 1:02 PM
To: [email protected]
Subject: RE: [fw-general] Zend_pdf doesn't commit changes


With a few tweaks, that did it!  Thanks!

To answer your question, my headers and streaming were done from a separate
calling program using 'passthru', but it will work to have all within a
single file.

Not sure if it was the try/catch block, or maybe your save/restore of GS
after each page, but it works your way.  I modified the headers a bit to
display inline in the browser instead of download, and to work in IE8
(worked as is in Firefox).

Here's my result code:
---

ini_set('include_path', '/library');
set_time_limit(0);

require_once("Zend/Exception.php");
require_once("Zend/Pdf.php");
require_once("Zend/Pdf/Exception.php");

//Quick and dirty example, that works:

// load pdf file
$pdf = Zend_Pdf::load('029044-02.pdf');

// Create new Style
$style = new Zend_Pdf_Style();
$font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA);
$style->setFont($font, 32);
$color = new Zend_Pdf_Color_Html('#000000'); //black


// Mark page as modified
foreach ($pdf->pages as $PDFpg){

    //calculate the fontsize to use based on the dimensions of the page
    $fontSize = intval($PDFpg->getHeight() / 10);
    $style->setFont($font, $fontSize);
    $PDFpg->saveGS()
          ->rotate(($PDFpg->getWidth() / 2), ($PDFpg->getHeight() / 2), 45)
          ->setStyle($style)
          ->setFillColor($color) //also sets font color
          ->setAlpha(0.2) 
          ->drawText('U N R E L E A S E D', ($PDFpg->getWidth() / 2) - (4 *
$fontSize), ($PDFpg->getHeight() / 2) - ($fontSize / 2) )
          ->restoreGS();
}
$tmp = $pdf->render();

// send to browser as embedded pdf
header("Content-type: application/pdf");
header("Content-Disposition: inline; filename=result.pdf;");

echo $tmp; 

---

Thanks again for your help, vRandom
Tim
--
View this message in context:
http://www.nabble.com/Zend_pdf-doesn%27t-commit-changes-tp24850906p24868483.
html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to