How to use php to generate pdf, word, and image files

Source: Internet
Author: User
Tags phpword
How to use php to generate pdf, word, and image files? which of the following components can generate files in the preceding centralized format, I want to embed the best style of the table in the above types of files. the font size is configurable, thanks to phpword, = & gt; generate a word file (if you only generate a table, you can directly generate it. you do not need to use such libraries to generate pdf, word, and image files using php.
You want to have a component that can generate files in the preceding centralized format,
Which of the following heroes gave a demo? I want to embed a table in the above types of files
It is best to set the style and font size of this table.
Thank you

------ Solution --------------------
Phpword, => generate a word file (if you only generate a table, you can directly generate it without using such a library)
Fpdf or pdflib.

------ Solution --------------------
The gd library can generate picture. Others are unknown.
------ Solution --------------------
This generates the word
Ob_start ();
Echo'';
?>
Directly use php to create word documents
By axgle



If you open Word.doc and see the introduction here, the word document is created successfully.


If you open Word.doc and see the introduction here, the word document is created successfully.


Print"";
$ Data = ob_get_contents ();
File_put_contents('d.doc ', $ data );
Ob_end_clean ();
?>
------ Solution --------------------
Php extension for processing images with GD. Discussion

Reference:

Does GD work?

What is GD?

------ Solution --------------------
PHP code
  AddPage (); $ pdf-> Output('a.pdf ', 'D');?>
------ Solution --------------------
Below is an example of creating a PDF file with FPDF and adding a page

Define ('fpdf _ fontpath', 'f0000152/font /');
Require ('f0000152/fpdf. php ');
$ Pdf = new FPDF;
$ Pdf-> AddPage ();
$ Pdf-> Output('a.pdf ', 'D ');
?>

You can also use $ pdf-> open (); to create a new pdf file.
But here, Addpage () contains open (), which completes two steps: Creating a PDF file and adding one page at the same time.

In the preceding example, define ('fpdf _ fontpath', 'f0000152/font/') defines the directory for storing the font files.
After downloading the compressed package, you can see the font folder. you just need to point to that folder.
The above program cannot display anything
Now let's add two sentences.

Define ('fpdf _ fontpath', 'f0000152/font /');
Require ('f0000152/fpdf. php ');
$ Pdf = new FPDF;
$ Pdf-> AddPage ();
$ Pdf-> SetFont ('arial ');
$ Pdf-> Text (5, 20, 'Test pdf ');
$ Pdf-> Output('a.pdf ', 'D ');
?>

SetFont () is used to set the font. this step must be used to call FPDF for the first time. otherwise, when the PDF file is opened, the system will prompt "no defined font" and nothing will be displayed.
We recommend that you define commonly used fonts, which are not supported in Chinese.
AddFont () is required to support Chinese characters or relatively biased fonts, but I have not passed the test. if you want to pass the test, please refer to ^
Text () prints a string. the x-axis is 5, the y-axis is 20, and the string content is "test pdf"
For more information about the parameter 'D' in the final Output (), see the manual.
In this way, the exported pdf file will display 'test pdf.
Add an image if you are interested.

Define ('fpdf _ fontpath', 'f0000152/font /');
Require ('f0000152/fpdf. php ');
$ Pdf = new FPDF;
$ Pdf-> AddPage ();
$ Pdf-> SetFont ('arial ');
$ Pdf-> Text (5, 20, 'Test pdf ');
$ Pdf-> Image('jianxin_mark.jpg ', 5, 30, 60, 50 );
$ Pdf-> Output('a.pdf ', 'D ');
?>

Image () can insert an Image in pdf. the file name must be prefixed. the path must be included. 5 is the horizontal coordinate, 30 is the vertical coordinate, 60 is the Image width, and 50 is the height.
OK, so that a PDF file with text and images is created ^
In fact, there are many other functions in the manual, but they are not very detailed. you need to study and explore them by yourself ^

------ Solution --------------------
Codeplex has such a set of things, such as PHPExecl, PHPWord, and PHPPowerpoint.

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.