How to generate Pdf,word, picture files with PHP

Source: Internet
Author: User
Tags phpword
How to generate Pdf,word, image files with PHP
You want to have a component that can generate files that are formatted in the
Which heroes give a demo, I want to embed a table in the above several types of files
The best style of the table, the size of the font can be configured
Million Xie

------Solution--------------------
Phpword,=> generate Word files (directly generated if you just generate a table, you do not need to use this type of library)
Fpdf or Pdflib.

------Solution--------------------
GD library can generate picture, others do not know
------Solution--------------------
This can generate word
Ob_start ();
Echo '';
?>

Create a Word document directly with PHP


Author: axgle



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


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


Print "";
$data = Ob_get_contents ();
File_put_contents (' D.doc ', $data);
Ob_end_clean ();
?>
------Solution--------------------
GD handles the PHP extension of the picture. discuss

Reference:

Can GD do that?

What do you mean GD?

------Solution--------------------
PHP Code
  AddPage (); $pdf->output (' a.pdf ', ' D ');? >
------Solution--------------------
Here is a simple example of creating a PDF file with fpdf and adding a page

Define (' Fpdf_fontpath ', ' fpdf152/font/');
Require (' fpdf152/fpdf.php ');
$pdf = new FPDF;
$pdf->addpage ();
$pdf->output (' a.pdf ', ' D ');
?>

Of course, you can also use $pdf->open (); To create a new PDF file
But here, Addpage () contains open (), he also completed a new PDF file and added 1 pages two steps

The Define (' Fpdf_fontpath ', ' fpdf152/font/') in the above example defines the directory where the font files are stored
After downloading the compressed package, you will see the font folder, just point to that folder.
The above program doesn't show anything yet.
Now, let's add two sentences.

Define (' Fpdf_fontpath ', ' fpdf152/font/');
Require (' fpdf152/fpdf.php ');
$pdf = new FPDF;
$pdf->addpage ();
$pdf->setfont (' Arial ');
$pdf->text (5,20, ' Test pdf ');
$pdf->output (' a.pdf ', ' D ');
?>

SetFont () Set the font, this step in the 1th call Fpdf must, otherwise the PDF file opens will be prompted "No font defined" and nothing to display
It is better to define more commonly used fonts, and Chinese is not supported.
To support the Chinese or support the comparison of the font to use the AddFont (), but I did not pass the test, I hope that the passage can be pointed out ^^
Text () prints a string with a horizontal axis of 5, an ordinate of 20, and a string content of "test PDF"
The parameter ' D ' in the final output () can be referenced in the manual and is clearly written.
The exported PDF file will display the ' Test PDF '.
If you have a good interest, add a picture

Define (' Fpdf_fontpath ', ' fpdf152/font/');
Require (' fpdf152/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 a picture in a PDF, preceded by a file name, to include the path, 5 is the horizontal axis, 30 is the ordinate, 60 is the picture width, 50 is the height
OK, so a PDF file with text and pictures is created ^^
In fact, there are many functions, the manual is written, but not very detailed, you need to study to explore the ^^

------Solution--------------------
CodePlex has such a set of things, called phpexecl,phpword,phppowerpoint you search, it is easy to search
  • 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.