PHP excel export PDF file garbled characters

Source: Internet
Author: User
Tags php excel
Phpexcel exports the PDF file garbled code. The process is to read the template.xls template file. Write the corresponding content and export the PDF file. The content of the template.xls file contains tables and Japanese. I personally think there is no font, but I hope you can tell me what to do !!!
Require_once 'Excel/PHPExcel. php '; $ objPHPExcel = PHPExcel_IOFactory: load ("template.xls"); $ objPHPExcel-> setActiveSheetIndex (0); $ objWorksheet = $ objPHPExcel-> getActiveSheet (); // write the content $ objWorksheet-> getCell ("C1")-> setValue ("test"); // fake film $ objDrawing = new PHPExcel_Worksheet_Drawing (); $ objDrawing-> setName ('stamp'); $ objDrawing-> setDescription ("aaaa"); $ objDrawing-> setPath ("images/p1.jpg "); $ objDrawing-> setCoordinates ('M1 '); $ objDrawing-> setOffsetX (25); $ objDrawing-> setRotation (36); $ objDrawing-> setHeight (73 ); $ objDrawing-> getShadow ()-> setVisible (true); $ objDrawing-> getShadow ()-> setDirection (45); $ objDrawing-> setWorksheet ($ objWorksheet ); $ objWorksheet-> setTitle ('simple'); ob_end_clean (); header ('content-Type: application/pdf '); header ('content-Disposition: attachment; filename = "detailinto" '); header ('cache-Control: max-age = 0'); $ objWriter = PHPExcel_IOFactory: createWriter ($ objPHPExcel, 'PDF '); $ objWriter-> save ('php: // output'); exit;


Reply to discussion (solution)

Exported PDF file with a thick border and garbled Japanese content

? OK? What is the UTF-8 encoding ?? If not, use iconv ????.

There is no encoding problem, and the garbled problem is solved.
Simplified Chinese display, font to arialunicid0-chinese-simplified
Japanese display, font to arialunicid0-japanese

I hope it will be useful to you.
But why is there no solution to the problem of displaying the black box ~~~

? OK? What is the UTF-8 encoding ?? If not, use iconv ????.


No encoding problem.
Simplified Chinese display, font to arialunicid0-chinese-simplified
Japanese display, the font can be set to arialunicid0-japanese.

Phpexcel has a major defect in generating pdf files: if there are images in excel, the generated pdf files will not be retained, so using this to generate pdf files is not the best solution!

Phpexcel has a major defect in generating pdf files: if there are images in excel, the generated pdf files will not be retained, so using this to generate pdf files is not the best solution!


Many of the predefined content remains unchanged and the format requirements are complex. Therefore, the content and format are converted into a template xls file. This function does not involve images.

Is there a good solution, instead of writing all the content, but importing the template first, modifying the content based on the template and saving it as a PDF file? Recommend a solution for prawns ~~


Phpexcel has a major defect in generating pdf files: if there are images in excel, the generated pdf files will not be retained, so using this to generate pdf files is not the best solution!


Many of the predefined content remains unchanged and the format requirements are complex. Therefore, the content and format are converted into a template xls file. This function does not involve images.

Is there a good solution, instead of writing all the content, but importing the template first, modifying the content based on the template and saving it as a PDF file? Recommend a solution for prawns ~~



You can use the code above to save the images that are dynamically written into cells to the pdf file.



Phpexcel has a major defect in generating pdf files: if there are images in excel, the generated pdf files will not be retained, so using this to generate pdf files is not the best solution!


Many of the predefined content remains unchanged and the format requirements are complex. Therefore, the content and format are converted into a template xls file. This function does not involve images.

Is there a good solution, instead of writing all the content, but importing the template first, modifying the content based on the template and saving it as a PDF file? Recommend a solution for prawns ~~



You can use the code above to save the images that are dynamically written into cells to the pdf file.



However, I am not sure about the display format. I will upload an image later.

Is an excel template file


The following figure shows the generated PDF file. why is the format different from the excel template file?

I did a test with version 2.1. in the generated pdf, the support for cell borders is not very good. somehow there will be some bold borders, the specific cause at the code level has not been well analyzed; maybe this is one of its defects.

I personally feel that you use it to process pdf files, just like you use a bicycle to drive a car at the same speed. after all, this is not its major. its major is its excel operations.

I personally feel that you use it to process pdf files, just like you use a bicycle to drive a car at the same speed. after all, this is not its major. its major is its excel operations.


Thank you!

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: info-contact@alibabacloud.com 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.