1

I face one issue with createAttachment method. This method attached pdf but pdf not open and its size is zero kb.

     $html .= "
         <html>
         <head>
         </head>
         <body>
           Test pdf
         </body>
         </html>";

     $attachment = $emailTemp->getMail()->createAttachment($html);
     $attachment->type = 'application/pdf';
     $attachment->filename = 'test.pdf';
     $attachment->disposition = Zend_Mime::DISPOSITION_ATTACHMENT;
     $attachment->encoding = Zend_Mime::ENCODING_BASE64;

     $emailTemp->send($useremail,$Username,$emailTempVariables);

Please help me ASAP. what is wrong here? I want to attached pdf with custom HTML in magento.

1
  • First you have to write pdf and after you can send it as attachment. see my bellow answer for create pdf file. Oct 26 '16 at 7:32
0

First you have to create a pdf file, You can create pdf file using below code, suggested code is just for create sample pdf file. you can change it as per your requirement.

$pdf = new Zend_Pdf();
$page = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_A4);
//var_dump($page);
$font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA);

define('FONT_SIZE'      , 12);
define('MARGIN_LEFT'    , 40);
define('MARGIN_TOP'     , 40);
define('COL_WIDTH'      , 100);
define('COL_LEFT_MARGIN', 10);
define('COL_SEPARATOR'  , '|');
define('ROW_HEIGHT'     , 20);

$row = 1;
$x = MARGIN_LEFT;
$y = MARGIN_TOP;

$page->setFont($font, FONT_SIZE);

$page->drawText('ABCD', $x, $page->getHeight() - $y);
$x += COL_WIDTH;
$x += COL_LEFT_MARGIN;
$x = MARGIN_LEFT;
$y += ROW_HEIGHT;

$pdf->pages[] = $page;
$pdf->save('data.pdf', true);

After generating PDF file, try with your attachment code with proper PDF file which you have created.

0
0

you attach the file but not his content you have to get content of file file_get_contents($pdf).

$pdf=Mage::getBaseDir().'media/test.pdf';
    $attachment = $template->createAttachment(
                    file_get_contents($pdf),
                    'application/pdf',
                    Zend_Mime::DISPOSITION_ATTACHMENT,
                    Zend_Mime::ENCODING_BASE64,
                    'test.pdf' 
                );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.