Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8878083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:37:38+00:00 2026-06-14T19:37:38+00:00

In magento1.7, I have tried something like below in my custom controller. public function

  • 0

In magento1.7, I have tried something like below in my custom controller.

public function getPDF()
{
$imagePath=C:\Users\.........;
$image = Zend_Pdf_Image::imageWithPath($imagePath);
$page->drawImage($image, 40,764,240, 820);
.
.
.
$pdf->pages[] = $page;
$pdf->save("mydoc.pdf");
}

There’s no error in it. It generates PDF with image but the PDF document is saved in magento folder instead in My downloads folder. After doing some research, I found some following chunk of lines and added them after $pdf->pages[] = $page;.

  $pdfString = $pdf->render();
  header("Content-Disposition: attachment; filename=myfile.pdf");
  header("Content-type: application/x-pdf");
  echo $pdfString;

Now it generates PDF in My Downloads folder. When I try to open it. It throws error saying : Adobe reader couldn’t open myfile.pdf because it’s not either a supported file type or because the file has been damaged………… Do this happens,when we try to open PDF document generated on localhost or there’s some other reason. Please let me know, why this error occurs and also provide me a solution to resolve it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T19:37:40+00:00Added an answer on June 14, 2026 at 7:37 pm

    your problem is probably due to calling both save() and render() together.

    save() actually calls render(), the issue could be due to trying to render the PDF twice.

    This is also a waste of resources, if you need to save the file it’s probably best to just save the file first, and then serve this file directly to the user.

    You can do this in plain old PHP (using passthru or readfile), although there’s ways to do this inside Zendframework which are better you can look into 🙂

    // .. create PDF here.. 
    $pdf->save("mydoc.pdf");
    
    $file = 'mydoc.pdf';
    
    if (file_exists($file)) {
        header('Content-Description: File Transfer');
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename='.basename($file));
        header('Content-Transfer-Encoding: binary');
        header('Expires: 0');
        header('Cache-Control: must-revalidate');
        header('Pragma: public');
        header('Content-Length: ' . filesize($file));
        ob_clean();
        flush();
        readfile($file);
        exit;
    }
    ?>
    

    if your code is inside a Magento Controller:

        $this->getResponse()
            ->setHttpResponseCode(200)
            ->setHeader('Pragma', 'public', true)
            ->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true)
            ->setHeader('Content-type', $contentType, true)
            ->setHeader('Content-Length', filesize($file))
            ->setHeader('Content-Disposition', 'attachment; filename="'.$fileName.'"')
            ->setHeader('Last-Modified', date('r'));
    
        $this->getResponse()->clearBody();
        $this->getResponse()->sendHeaders();
    
        $ioAdapter = new Varien_Io_File();
        if (!$ioAdapter->fileExists($file)) {
            Mage::throwException(Mage::helper('core')->__('File not found'));
        }
        $ioAdapter->open(array('path' => $ioAdapter->dirname($file)));
        $ioAdapter->streamOpen($file, 'r');
        while ($buffer = $ioAdapter->streamRead()) {
            print $buffer;
        }
        $ioAdapter->streamClose();
        exit(0);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to generate Pdf of images. I have tried the following code public
hai I have a magento web site. In this the search function compare with
Building a custom adminhtml module. Im using a simple form. it looks like this
I have tried as following in magento 1.7 $pdf = new Zend_Pdf(); .... ....
I have tried to use the lastest version of magento connector on mule 3.2.
How can I add new products to Magento 1.6? I have tried this:- $product
I have already created a custom layout for my Magento theme which works fine.
I have added a custom category attribute to my Magento installation with the following
I have tried every tutorial on the internet , I have asked questions here
We have an established Magento store running Magento 1.4.2.0 and recently something happened to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.