Question

I'm trying to save a simple pdf with one page but it doesn't work. This is what I do:

try {
       // create PDF
       $pdf = new Zend_Pdf();

       // create A4 page
       $page = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_A4);

       // define font resource
       $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA);

       // set font for page
       // write text to page
       $page->setFont($font, 24)
           ->drawText('That which we call a rose,', 72, 720)
           ->drawText('By any other name would smell as sweet.', 72, 620);

       // add page to document
       $pdf->pages[] = $page;

       // save as file
       $pdf->save("/test.pdf");
       echo 'SUCCESS: Document saved!';
   } catch (Zend_Pdf_Exception $e) {
       die ('PDF error: ' . $e->getMessage());
   } catch (Exception $e) {
       die ('Application error: ' . $e->getMessage());
   }

I always get this error:

PDF error: Can not open '/test.pdf' file for writing.

I've found this stackoverflow topic but I didn't help me much. They say to change the save path, but change it to what? Let's say for example I want to download it to my Downloads folder, how can I do this?

My Downloads folder on mac is : /Users/myname/Downloads

Was it helpful?

Solution

try for save in Zend app directory

  $pdf->save("test.pdf");

or for save in Downloads

   $pdf->save("/Users/myname/Downloads/test.pdf");

OTHER TIPS

Ensure that you have write permissions on the folder with ls -ld. If you do not have write permission in the folder use chmod to give it to yourself.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top