Php script for converting html to pdf


















Perhaps we want to save the generated PDF document to disk instead of sending it to the browser. Instead of calling stream like in the previous example, we use output which returns the PDF as a string. It too accepts an optional options array, but the only option available is compress the default is true.

We can add text, lines, images, rectangles, etc. The script is embedded directly into the HTML markup, and first opens an object so we can affect the rendering. All drawing will be recorded into that object and we can add this object to all or selected pages though there are limitations.

Next we fetch the actual width and height of the page to calculate the coordinates of the footer we intend to add. Also, we need to provide a font object while we add text contents. The line method draws a line from point X1,Y1 to X2,X2. Notice that the color value we provided is not an actual RGB value. In this example, I will just create a simple invoice document. We will name the file as file. The code above will require the library in our file so that we can initialize the TCPDF class in the library.

The last line has two 2 parameters, the first parameter will be the filename of our PDF file while the second parameter is the action that we are going to do with the file. There are many types of action that we can choose from for the second paramter. The I action is it will send the file inline with the browser, allowing it to be viewed in the browser without actually saving the file.

The D action means the file will be forced to be downloaded on the local machine given the filename in the first parameter. The F action means the file will be saved on the local server that can be retrieved and downloaded later. The S action will return the document as a string where the filename is ignored. The FI action is the combination of F and I action. Ask a question Contribute an article Questions Articles.

Login or Register to comment. Related Articles



0コメント

  • 1000 / 1000