I need to convert an Excel(.xls) spreadsheet to a PDF document with an image in PHP. If there is a library available please put the link.
Note - I have created excel(.xls) to PDF with "PHPExcel" library but my output is without image and border.
If PHPExcel can't do it, then you're stumped for a straight PHP solution, and might have to look at options like COM.
You don't mention what your problem is with the borders, and these have been a problem for some time in PHPExcel... the 1.7.6 version of PHPExcel resolved some of these issues, and there is a patch listed in the Issues section of the PHPExcel site that fixes some other problems with borders.
You can convert XLS files to PDF on Linux by installing OpenOffice
with a PDF writer as the default printer driver.
Then, you can call OpenOffice (from PHP) using the "-p" command-line
parameter, which will cause it to load a designated file and print it.
For example, if your file was "accounts.xls" you would call the
following command:
soffice -p accounts.xls
OpenOffice would load the "accounts.xls" file and "print" it to the
PDF writer, which would be configured to save the PDF document to the
desired filename.
GhostScript is a suitable PDF writer.
The OpenOffice setup guide describes how to install and configure
printer drivers using the "spadmin" utility, and discusses the use of
ghostscript as a PDF writer:
"Open Office Setup Guide - Appendix"
http://www.openoffice.org/docs/setup_guide/appendix.html
You can call OpenOffice from PHP by using the backtick execution
operator, or the "exec" function. You may also need to use PHP to move
and/or rename the resulting PDF files:
PHP: Program Execution Functions
http://www.php.net/manual/en/ref.exec.php
PHP: Filesystem: Rename
http://www.php.net/manual/en/function.rename.php
OpenOffice is pretty good at processing XLS files, but it may not
perfectly render every such file - so if you need the ultimate in
compatibility you will have to use Microsoft Excel on a Windows
Platform or emulator. "IT AsiaOne" looked at several alternatives to
Microsoft Office (including OpenOffice) and wrote that "while none of
the alternative suites promise ... full compatibility with Microsoft
Office-created documents, in general, they do a decent job of
translating Microsoft ".doc", ".ppt" and ".xls" file formats":
IT AsiaOne - Specials - Yours For The Picking
http://it.asia1.com.sg/specials/mmedia20020724_001.html
Additional links:
OpenOffice.org Home Page
http://www.openoffice.org/
Ghostscript Home Page
http://www.cs.wisc.edu/~ghost/
PHP Home Page
http://www.php.net/
Google search strategy:
openoffice scripting pdf linux
://www.google.com/search?q=openoffice%20scripting%20pdf%20linux
openoffice print "command line"
://www.google.com/search?q=openoffice%20scripting%20pdf%20linux
followed by a search for "command line parameters" from the
openoffice.org home page.
Ref
Related
I am working on a PHP web application which programatically generates some DOCX files.
I want these files to be converted to PDF, but their layout is so complex that not any PHP-PDF generator library (domPDF, TCPDF, etc.) works well. They result in a poorly formatted PDF in each case.
In this situation, I have decided to let Google Drive do the conversion. For this, I have to:
Upload the DOCX files to GDrive
And then export them in PDF...
I have seen all of the GDrive API documentation, but it is very poorly documented. I only want to execute one single PHP script which:
Uploads the file to GDrive
Downloads its exported PDF version
Lets the PDF be downloaded when the script is finished...
I am searching for the optimal way to achieve this behaviour... (with or without GDrive, since the LibreOffice/Openffice CLI command is not an option because I am on a web hosting and I can't install any software...).
Have you considered using a file conversion service to do this for you ?
For complete transparency I work for Zamzar (an online file conversion website), we have recently released a developer API - https://developers.zamzar.com/ that would allow you to convert your DOCX files to PDF with little or no loss of formatting.
This would then eradicate your need to convert your file(s) using the Google Drive API. Check out our fairly extensive docs here - https://developers.zamzar.com/docs.
I need to manipulate XLS files from PHP.
I found the great library PHPExcel which does 99% all of the job I need. Sadly I miss that 1%, which is writing the name of the "Creating application" (gnumeric sees it as meta:generator) in Excel 2007 files (Excel5 as called in the library).
Is there any other way to write this tag?
I can work around this by converting the XLS to gnumeric (using ssconvert), adding the tag to the XML file and convert back to XLS, but since I should use this script in a headless server I'd rather avoid installing gnumeric.
Any help is appreciated, even if another method exists (a command line tool, another PHP library).
I'm creating a docx file from an HTML page using pandoc, but for the life of me I can't seem to get it to take on any kind of styling or successfully use a dotx template. I don't know if it's because you can't style docx files or I'm doing something wrong - documentation isn't all that verbose for pandoc.
I've also tried just echoing the html out and setting headers so the client will open the file as a doc, but this has some problems when you save it (it will try to save as an html file and converting to a doc isn't all that easy).
What I want to do is create an editable document which is styled and contains a logo image - just font types, colours and sizes would be enough, maybe some basic positioning would be nice.
Does anyone know how to acheive this on a LAMP - like system?
I stumbled on using Libreoffice on the CLI to do the conversion, with a much greater degree of success. It's still not perfect but alot better than what I was getting, and seems to take onboard font types, sizes and colours alot better.
Steps to install and use (CentOS / Redhat here):
sudo yum install libreoffice libreoffice-headless
You may need some X11 / Xorg libs, easiest to just install Xorg if it won't run.
libreoffice --headless --convert-to docx --outdir ./ myfile.html
Worked for me, I ended up with a serviceable .docx file which could be read by MS Word 2008 and LibreOffice 3.5.6.2.
Other tools that might also be worth examining are JODReports and Docmosis which are focussed on generation from templates (mail-merge) rather than just format conversion. JODReports is free/Open Source, Docmosis is not. Both can be ivoked from PHP in various ways and Docmosis has a cloud-service which means a zero-install footprint if your application is allowed to reach the cloud. Please note I work for the company that created Docmosis.
I think they both can work from docx/dotx templates and produce a variety of output formats including DocX
Hope that helps.
How can i read formatted text as HTML from doc, docs and rtf files?
My script is on LAMP, can access openoffice installed on server for this type of conversion?
EDIT
Its not necessary that i want to access openoffice through a php extension or Apache module, if it is possible to use it using cli trhoug php, it would be fine too.
You can try Puno: http://www.wstech2.net/index.php?do=0a,01,05
This project is a PHP5 module written in C++ that brings the OpenOffice.org UNO Programming API to the PHP userspace.
It uses UNO Reflection API by OpenOffice for it. It's easy to start with. Check out sample example given there.
Is there any ready PHP-based soultiuon for creation of an JPEG images from the Adobe's PDF files? Just like this: http://www.convertpdftoimage.com/
The ImageMagick program allows conversion between graphic formats, and it includes support for reading PDF files. Therefore it should be able to convert PDF to JPG. (indeed, googling for ImageMagick pdf to jpg gives plenty of results, with good usage examples)
Furthermore, there is a PHP extension for ImageMagick, so if you have that extension included in your PHP, then it should be pretty simple (you can check which extensions are included in a given PHP installation by using the phpinfo() function).
If you don't have that extension (and you can't install it), you can still use ImageMagick, using it's command-line interface via the PHP shell_exec() function, etc.
I don't know about PHP. But we use this application: Callas pdfToolbox. It's standalone on your UNIX server.
Apache provides a Java solutions: PDFBox
Not sure PHP is capable of rendering PDF's. Getting the text out of then however should be easy.