Opening HTML as Word or PDF using PHP/Laravel - php

I'm a little confused about PHPWord w/ DomPDF. If I generate HTML using Laravel/PHP/Blade, store it in a text file saving it with .html extension, and open it with Word (open Word, select File open, etc), I see the page as I would like to see it in Word.
But if I use PHPWord to write the HTML to a file and then open it as Word2007 for download, PHPWord strips out all the CSS etc. And it looks horrible.
Also while dompdf with the help of PHPWord (again writing the HTML to a file and being read as PDF) the PDF looks much better than the generated Word version but still has no styling.
I have reviewed the samples for each . . . all the articles I can find on here etc. Is there another way to do what I do manually--open the html in Word--for a download with PHP?
I cannot recode the blade template with the PHPWord tagging. But if the Windows laptop Word app can open my HTML and save it as a Word file just fine I would think I could do this relatively easily with PHP programmatically somehow.

Related

PHP function to search for text inside online pdf, replace it & save modified pdf on the server

Is there a way in PHP that can open remote PDF file, searching for specific text, replace it with new one & save the modified PDF file on the server?
Thanks
You can use a combination of tools or just one of them. Depends on how complex the file is and how much noise either of these generates.
DomPDF - converts HTML to PDF.
TCPDF - creates PDF files.
FPDI - uses already existing PDF files.
My personal recommendation would be to go for FPDI.
After many days of research, there is no plugin can extract pdf data from 'extraction protected' PDF.

Read complete content of .rtf document

I have to create a document using user inserted data and including data from a .rtf document into a web page layout i created (HTML+CSS and PHP for scripting).
My problem is, i can't find any way to obtain the full content of the .rtf document.
Being a technical document symbols, tables, graphs and images are very often included: with the methods I've found i could obtain the text with symbols in a decent formatting but i had no luck with images.
So what i need is a way to obtain the full content of a .rtf file, possibly maintaining the document formatting, so i can display and organize it in a webpage; preferrably in pure PHP but use of js/executables via php is fine.
I've tried:
-rtf to html converters but the best i could get is clear text and symbols but no images;
using COM extension to open the .rtf in ms word and saving it as .html (i noticed that if i open up the .rtf then save it as webpage in word it creates a perfect html page) but it only changed the extension and didn't create a html page;
extracting text and image sperately: works but again being the document a technical document image placement is very important.
It's my first question here, after many research; please bear with me in case of errors.

word document {tokens} replacement using PHP

I am trying to read a .doc file and find tokens like {name}, {phone}, {address} etc. now display tokens with text box and allow user to replace by inserting original data. so that .doc file will replace with actual data.how to do this using php? the color, fonts, and style of .doc should not be changed.
thanks....
This will be very tricky if you are using the old style Word documents. The new Word documents are saved in a some sort of Zip archive and therefore are much easier to edit.
You can extract this files and with some knowledge of the contents and Word WSDL you can edit the contents of the file.
Much easier is to make use of the PHPDocX Library. We are using it in a project and works like a charm. Only disadvantage is that it only works with .docx files.

Display document files in html

I am working on a job site where job seekers can upload their resume . When editing their profile , I want them to view their previous resume . I used <iframe> for this purpose , but instead of displaying the doc file,it shows an option to download . So how can I display their resume (in .doc,.docx and .odt format)
You can use php's fopen function, however there is a lot of unwanted code within a word doc file. Maybe a quick search could help you with what you want:
Reading/Writing a MS Word file in PHP
It would require a lot of effort. best bet is to create a wysiwyg editor instead of an upload that they can copy and paste to
You can't display .doc,.docx and .odt format files on browser. Basically a browser is designed for parsing HTML files only. You can use Flash to display doc inside your browser,
You need to embed the src, if you were to embed the source, it stops Adobe Reader or what not, taking over the browser entirely, and actually views it in the window, this should help:
Recommended way to embed PDF in HTML?
I know this is for PDF's but I would assume you can use it for .doc too.

How to clean up garbage text from string using PHP?

I am trying to parse a word document file. I upload the using PHP then I am trying to get contents using file_get_contents(); function but the problem is when its displayed in front end a lots of garbage code in there like
Æ�Ѐ¤d�¤d�[$\$gd®l±����„h¤d�¤d�[$\$^„hgd®l±���
&�F�¤d�¤d�[$\$gd3¡���gd3¡����„,¤d�¤d�[$\$^„,gd(E����¤d�¤d�[$\$gdÿ/��<��C��D��I��Å������O��P��‚��¡��¢��¬��­��®��Ù��ã��ó��ô�����
So my question is how can I clean up this text?
Maybe give this a shot? http://www.phpclasses.org/package/3553-PHP-Edit-Microsoft-Word-documents-using-COM-objects.html
Word documents (like docx and doc) are not straight text files - they are actually proprietary file types that do not just have the text from byte 0 - this is how they have fancy formatting and fonts. .docx files are actually archives (.zip files) that contain a myriad of XML and styles.
Your best bet is to use a text input form, or find code online that allows you to extract just the text. Or, download the doc files to your own computer and use your own copy of MS word to open it.

Categories