create a .doc / pdf / odt using codeigniter and php - php

I followed this tut :
http://klewos.wordpress.com/2010/04/16/using-php-to-fill-a-word-document-quick-tip/
and all is fine till i open the downloaded .doc into libre office,
instead of outputing the doc content, it shows the full xml code as content !
Just note that i would prefer to create a PDF as final document but it seems easier with doc
I should miss a step with the xml to doc ?
if someone sees a better way to do this kind of thing (my base doc is 10 pages long so i don't really want to create a line by line pdf)
Anyhelp is welcome ;)

The article does mention that particular situation:
I’ve tried to open the Word 2003 XML document in OpenOffice.org 3.1.
Unfortunately, Writer wasn’t fooled by the .doc extension and opened
the document as plain text. Only after changing the document’s
extension to .xml, the editor opened it correctly. So, the documents
are portable after all.

Related

How to take into account the color of the graphics of Docx files when converting them to PDF using phpword?

Here is the code I used to convert my docx files to PDF:
<?php
require_once 'vendor/autoload.php';
use PhpOffice\PhpWord\IOFactory as WordIOFactory;
use PhpOffice\PhpWord\Settings;
// Set PDF renderer.
// Make sure you have `tecnickcom/tcpdf` in your composer dependencies.
Settings::setPdfRendererName(Settings::PDF_RENDERER_TCPDF);
// Path to directory with tcpdf.php file.
// Rigth now `TCPDF` writer is depreacted. Consider to use `DomPDF` or `MPDF` instead.
Settings::setPdfRendererPath('vendor/tecnickcom/tcpdf');
$phpWord = WordIOFactory::load('test/graph.docx', 'Word2007');
$phpWord->save('graph.pdf', 'PDF');
This code worked, but the problem was when it converted the file to PDF. The colors of the graphics were all lost and I feel like even the format was lost.
Here is the PDF file I had:
This picture shows the PDF file I had.
Here is the result after converting the DOCX file to a PDF file:
This picture shows the result after converting the DOCX file to a PDF file.
As you can see. The PDF file has lost the colors of the graphics. Who then, I would like to know from you. Do you have an idea to at least take into account the colors of the graphics? I have done a lot of research but have not found anything concrete. Can you help me please?
Well, I am doing my best to explain my problem. I hope I will get some nice answers. :)
Thank you for helping me. :)
I believe the OfficeConverter library will definitely helps you in what you're going to achieve, which it is actually utilising the libreoffice way mentioned by KJ.
I downloaded your graph.docx file and tested, the result should be what you're looking for. I have a demo site for you to test out, feel free to try it out, it is my open source project.
Here the link to the site PhpOfficeTemplate.
Do remember to Enable the Office Converter options.
Then select your docx file in the Template.
Hope it helps !
Microsoft Word has many proprietary features that cannot readily be carried over from conversion from DocX to simpler Rich Formats. This can be seen in Microsoft's own applications too. Very simply open a DocX in the native Write.exe here we see complex styles are unsupported.
It is thus not surprising that the only App that can faithfully convert Word Documents to PDF is MS Word export to PDF (Similar when converting PDF "To" DocX), and many converter programs/scripts can invoke an installed MS Office by calling Microsoft "Interop" DDLs.
Adobe Online Converter uses copies of MS Word as can be seen when using their conversion apps:-
Similar with other brand leading converters here Aspose clearly use MS Word
File: graph (1).pdf
...
Application: Microsoft Office Word
PDF Producer: Aspose.Words for .NET 22.11.0
PDF Version: 1.7
File Size: 7.07 KB (7,237 Bytes)
Number of Pages: 1
Page Size: 21.0 x 29.7 cm (A4)
Bottom line for docX fidelity you need a running copy of MS word
Next best
You can sometimes get close (but not always) using Libre Office or a variant so that chart works well using Server conversion. However, note the significant increase in size (over 10x bigger) to embed different MS aspects.
File: graph (2).pdf
...
Application: Writer
PDF Producer: ConvertAPI
PDF Version: 1.7
File Size: 93.37 KB (95,607 Bytes)
Number of Pages: 1
Page Size: 21.0 x 29.7 cm (A4)
You can better that (only 5 times bigger) by using a batch with local current 7.4
libreoffice\program>soffice --convert-to pdf *.docx
"The program script" as shown above, will start soffiice in the library\program folder, to convert every local docx into a local pdf.
If you need to customise, i.e. where you start it as a CWD, or run one by one files elsewhere, then that will be specific to your operating system and workflow, mine is just run one single line (or a few) as a full blown suite of commands, = power via one line simplicity.
There are 100's of variants of php aids and many to run and install libre office so try searching say github.com/search?q=php+libreoffice, a good example is the one shown by #zeikman
$converter->convertTo('output-file.pdf'); //generates pdf file in same directory as test-file.docx

PHPExcel Writer .xls file generates Excel error ... how can I change the extension to .csv?

I'm using a Wordpress plugin, wpdatatables, that uses PHPExcel to produce pdf, csv, and Excel file exports.
Anyway, when downloading an .xls file from my website, when I open it .. Excel gives me the error “The file format and extension of “blahblah.xls” don’t match. The file could be corrupted or unsafe. Unless you trust its source, don’t open it.”
Of course the file still opens fine, but I'd like to get rid of this error. One thing I noticed is the .CSV export is seemingly identical in all ways except the file extension, and opens without an error.
As someone who is not terribly familiar with PHP sadly, what direction should I look in to make PHPExcel produce .csv files only? Is there a specific function or directory in PHPExcel responsible for the Excel writer file output?

cannot open php file

i have downloaded some php files (it's a content management system) but i can't open them. it appears that they contain binary data. this is what i get when i open them using a text editor:
Zend20020623011793334417xù
ں2ف=كڈإ™m{Orvƒًè¢9 ­ف]UفU0زع^ہ€eo.’ذî™éفïىجhzcë‌ن7,‏xAœگrBBو$89¯‘<"‌ٍs~±B¤كغتز‎Zء¤ص€1c‍Xû‡ûû×O¦أل¼\آ=o…ر¨ّzـ;^´>®é3ُéJہإً_±w[ƒٍµh‍يŒٍE6Ovئس~:.$َügLk,{+»9*گ~m.إ5طû¤ْW%&&aد؛fجMe´?›خة<ƒط<_$o¦َ—Q^4ûJ§{ç/‍صg}u¥kڈnFق0غM2‏#5شl\‏ظو›—.©3 ق?h+<Wٍ9LkئPïھة¤4ےbإ9…ھ â8”8'´‘گwٍشQf~[أي­Bى}VC‘ هNç،Œح]ڈق~[ƒ‰ف:ô¾6Wںنüو–¤‍£ôُe½ئـة÷g%ت»®-­ىلƒپآڈUˆ%©يئ‘B~نKٍ©,ةgڑCLاcپء¼اثYiآ9†ںئأ,?5طفمjک'g»³²ص_Jں&÷èQM+ƒZS=c¾03¥–xwجMB~­TN±‹`قƒ²
(there is much more, about 50 lines)
what is this? i have never worked with Zend, is it some kind of compression? how can i open and edit these files?
This file appears to be encoded by Zend guard. You probably cannot decode it.
Here is something you can read on http://www.zend.com/en/products/guard/
Encoded PHP file. Protecting their source code

How to convert all type of file into .swf format using php on Linux

As I Upload the file using php, it should move to conversion tools and the output, i.e. a file in a *.swf format, should be uploaded to the same directory, where my original file exists and should be displayed in my website.
I have searched long and I got swftool, but it's not working on my linux machine.
Converting every format is not possible. Your lazy question is a bit broad there.
As alternative to swftool you can however utilize OpenOffice/LibreOffice. The Impress presentation module allows to export .swf animations. LibreOffice can be utilized from the commandline (thus via php).
soffice -headless -convert-to swf animation.ppt
You can google other examples.
The actual task then becomes to create a Powerpoint or Impress document first (it's an XML format) from whatever input and media files you have. (Maybe a simple .SMIL works too.)
You still can convert any document to SWF if it can be printed. As almost any kind of document can be printed, it is possible to convert them to SWF. In order to achieve this you need to use a virtual SWF printer software, e.g. Print2Flash (www.print2flash.com). The PHP code is quite simple:
$p2f = new COM("Print2Flash4.Server2");
$p2f->ConvertFile($sourcefile,$outfile);
$sourcefile is the path and name of the source document, e.g. a PDF or Office document. $outfile is the name of the output SWF file. more details can be got from php sample from the SDK that can be downloaded from http://print2flash.com/download.php

Open epub files in PHP

I want to open an .epub document with PHP, to modify it (for example to add some text on the first page and last page) and to save it back to .epub I found some classes for saving a text into epub file, but I can't find anything about opening an epub in PHP.
epub files are just HTML+CSS files inside a ZIP archive (called the Open Container Format (OCF)) files with a different file extension :) So you can use PHP's ZipArchive class to work on the file.
There are libraries that support EPUB files. BookGlutton is one.

Categories