Magento order printing (PDF)

Source: Internet
Author: User

Magento order printing (PDF)

Magento itself includes: printing the invoice form, printing the packing list, and printing the refund form. These are based on the habits of Western countries. The company has a requirement to print the Order's quadruple order, in PDF format, which should be completed within one week. When I got this task, I thought it was too big, because I still had no idea how PHP generates PDF files and the magento printing system. In addition, this is a Chinese print, which is different from magento's built-in English Order printing.

The next step is to analyze the code. The first problem is how PHP generates PDF files by using the zend_pdf library. For zend_pdf Chinese garbled characters, it also found a solution through the cute Google; in addition, you are familiar with magento's built-in printing system through code analysis. Due to frequent meetings and other trivial tasks, it took several weeks to start programming. It took about five days to complete. First bask in the mature fruit:

Several Problems encountered:

1. magento prints Chinese PDF order garbled characters. You need to load Chinese fonts to solve this problem. I used simkai. TTF and msyhbd. TTF fonts. I originally wanted to use and found that zend_pdf has some problems with. The font of is also pretty nice, so she is used. Note: simkai. TTF and msyhbd. TTF can be found in the C:/Windows/fonts/directory. The following code creates a text file:

1 $fontyah = Zend_Pdf_Font::fontWithPath(Mage::getBaseDir() .‘/lib/ZhFont/msyhbd.ttf‘);
2 $fontkai = Zend_Pdf_Font::fontWithPath(Mage::getBaseDir() .‘/lib/ZhFont/simkai.ttf‘);

2. Draw the company logo in the upper left corner of the order. Zend_pdf_image is required. Code:

1 $logofile = Mage::getBaseDir() .‘/skin/frontend/default/default/images/print_logo.jpg‘;
3 if ($logofile) {
4     if (is_file($logofile)) {
5         $image = Zend_Pdf_Image::imageWithPath($image);
6         $page->drawImage($image, 25, 800, 125, 825);
7     }
8 }

3. Draw a bar code. The code is found online and slightly modified. The principle is to use php gd to generate a bar code image and then draw it on the order using Zend drawimage. The code is relatively complex, slightly.

4. Obtain the name of the ticket maker.

1 $user = Mage::getSingleton(‘admin/session‘)->getUser();
2 $user_name $user->getLastname() . $user->getFirstname();

5. Obtaining the magento order payment method is also complicated. After debugging for a long time, you can get the following code, which may be a problem, but most of the time it works properly:

01 $paymentInfo = Mage::helper(‘payment‘)->getInfoBlock($order->getPayment())
02     ->setIsSecureMode(true)
03     ->toPdf();
05 $payment explode(‘{{pdf_row_separator}}‘$paymentInfo);
07 foreach ($payment as $key=>$value){
08     if (strip_tags(trim($value))==‘‘){
09         unset($payment[$key]);
10     }
11 }
13 reset($payment);
15 $payment = trim($payment[0]);

It is a little difficult to remove these issues, and others are relatively easy to solve. After the function is completed, the work of ticket-making customer service mm is greatly reduced. Previously, it was made manually on the Word template, and errors are inevitable. In addition, copy and paste are very monotonous and mechanical boring, and every person is tired and dizzy every day can only make about one hundred sheets. Now thousands of tickets are ready in a few minutes. Later, the customer service mm smiled at me.



Magento order printing (PDF)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.