php file to pdf - php

I was converting a HTML file to PDF using dompdf. I managed to get the desired result but a problem arose, the HTML file needs to be converted to PHP because it will receive data from a form (from another file)!
The dompdf in this case doesn't work and it not shows the result of what was written in the form.

I think what you search is a template Engine to replace values in a HTML file.
There are some Engines like Smarty, TWIG.
You can parse your HTML file and with the HTML return you can create your PDF file.
Perhaps its a bit oversized for your case but you could build your own short engine and parse your HTML file and replace your specified Tags with the form values.

You can create your html file automaticaly in temp. After request to your php file, your file generates automaticaly a .html file (in temp), then create your pdf from this file.

Related

wkhtmltopdf style table of contents

I'm wondering how i can go about reducing the font size on the generated table of contents.
I've read and reread their documentation here: https://wkhtmltopdf.org/usage/wkhtmltopdf.txt
The bit i'm confused on is:
The generated XML document can be viewed by dumping it to a file using the
--dump-outline switch. For example:
wkhtmltopdf --dump-outline toc.xml http://qt-project.org/doc/qt-4.8/qstring.html qstring.pdf
I'm having difficulty understanding how to translate to my own project, and what do they mean by this part of the command:
http://qt-project.org/doc/qt-4.8/qstring.html qstring.pdf
If you want to change the default table of content (HTML and / or CSS styles), you can use the xsl-style-sheet parameter to specify a custom XLS stylesheet.
In your custom XLS you can add any HTML tag you need.
You can find an example of the default XLS file here. For your information, le XLS is generated from the tocstylesheet.cc file (see here).

Downloaded .csv file contains Type HTML Document

i am having problem when downloading file using Php script, Problem is when csv generated it contains document type HTML.
"Which is: HTML document (5.9 KB)"
I tried everything like changes Content type etc but issue still persist.
Please suggest,
Thanks in advance.

Display XML in texteditor (eg. tinymce,Jquery Editor) PHP

I am using Jquery text editor. I copy and paste the XML as given below in texteditor
<shoes>
<shoe>
<shouename>Shoue</shouename>
</shoe>
</shoes>
Then I click on save and the XML saved in Mysql DB. Then when I edit the same I see "Shoue" in texteditor field. But i want to show it as it is as below in texteditor
<shoes>
<shoe>
<shouename>Shoue</shouename>
</shoe>
</shoes>
I think texteditor endering the XML with HTML.
How can I show XML as it is in texteditor using PHP. So that I could edit the XML and save.
try htmlspecialchars() and read about XSS - you should use this function always when you want output user's data on HTML page.
As variant, try Twig templates engine - very simple and have built-in escaping.

Creating a personalization engine with php

I am new to php and I want to create an php engine which changes the web content of a webpage with PHP with the use of data in mysql. For example (changing the order of navigation links on a webpage with the order of highest click count) I am not sure how PHP will read the HTML file and change the elements in the HTML file and also output the HTML file with the changes. Is this possible?
I am not quite sure why you would want to generate the html, read it, change it and then output it. It seems to be a lot easier to just generate it the way you want to in the first place.
I am not sure how PHP will read the HTML file and change the elements in the HTML file and also output the HTML file with the changes. Is this possible?
You could use file_get_contents:
$html = file_get_contents($url);
Then use a html-parser like Simple HTML DOM Parser, change what you want to do and output it.
If you want to modify HTML structure, use ganon - HTML DOM parser for PHP
include('path/ganon.php');
// Parse the google code website into a DOM
$html = file_get_dom('http://code.google.com/');
foreach($html('p[class]') as $element) {
echo $element->class, "<br>\n";
}

How can LiveDocx in PHP be used to read .doc & .docx files and read text inside it and save to HTML?

Let's say we have a .doc & .docx files. I want to use LiveDocx in PHP to load the files, read it's content and strip the text from inside it. Then save it to an HTML string.
Can this be done?
I've searched the documentation, and it seams that LiveDocx only loads .doc & .docx template files only!
You can save using external libraries and simply grab the text from the XML within the files:
http://www.webcheatsheet.com/PHP/reading_the_clean_text_from_docx_odt.php
I think you can find what you need in this example.
I might be wrong, but I think they call them "template" files because they act like a template but are still normal .doc/.docx documents. I suggest you simply try to run that example.
I think you can use TextControl that improves phpLiveDocx TextControl link
Using this you can also import pdf doc and docx
When you do document conversion on LiveDocX, you need to do a mailmerge and then retrieve the document. Even though you aren't inserting any new content, you need to do a mailmerge that replaces a dummy placeholder with dummy content.
So, the process I'd suggest is:
1) Set your source document as local template
2) Merge a dummy field with dummy content
3) Retrieve your document as HTML
4) Use a script server side to remove the html and leave only the content (Something like, remove everything between the HEAD tags, then strip_tags on the rest)
5) You should be left with your content as a simple string - I'm not sure it'll be too meaningful, but might be useful for building something like search indices.

Categories