Conversion of an Adobe PDF to the JPEG - php

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.

Related

How to create avif files in php?

Does anybody know how to write avif image files in php?
For webp files i have the function imagewebp. But avif?
Using PHP Version 7.4, 7.1 and 7.2 on different servers.
thanks a lot
EDIT:
It has been implemented in PHP 8.1 https://php.watch/versions/8.1/gd-avif
There is no dedicated function to do that at this moment. GD has implemented AVIF support but is not yet implemented in PHP. They are working on it https://bugs.php.net/bug.php?id=80828 , please vote for it.
Until that function is made, I image there can be other methods to create:
(1) using php exec/shell_exec and an command line app (like imagemagik). untested code:
if (function_exists("exec")) {
$command = "convert -size 600x600 canvas:white white.avif ";
exec($command, $output);
print("<pre>".print_r($output,true)."</pre>"); //debug
}
else {
echo "EXEC function is not available. See php.ini disabled_functions.<br />\n";
}
(2) using a php module like Imagik
https://www.php.net/manual/en/book.imagick.php
Verify ImageMagick installation
For both methods you need to make sure you have a recent version of ImageMagik compiled with proper libraries.
https://github.com/ImageMagick/ImageMagick/issues/1432
Unfortunately, there is no native PHP support (in any PHP version I know of) for the AVIF/AV1 image file formats, at this stage.
PHP normally relies on the GD, the ImageMagick, the GMagick (and Exif) image libraries, so - until these include support for the AVIF/AV1 image file formats, I'm afraid there won't be an easy (and "native") solution for you. There may be some third-party libraries, perhaps written in pure PHP, to support this, however the format is relatively new and not quite yet widely supported, so I believe it will take some time for these to be available, and a pure-PHP library for image processing is likely to be quite inefficient, performance-wise.
That said, I suppose you could consider using a workaround, which is PHP-generating an image in any of the other image formats (say JPEG or PNG), and then using a command-line tool to covert the resulting image file into AVIF/AV1?
See for example https://reposhub.com/rust/image-processing/kornelski-cavif.html
Good news - the work's been done to support AVIF in libgd, and this work has been propagated into PHP. It should be released in PHP 8.1.
Enjoy!

Converting a TIFF image to PNG/JPG/GIF in PHP without Imagick

I am working on a website for my client in which tiff images need to converted to png or jpg before they are assembled into a PDF.
I have read many articles, here and other sites, on this issue. They all recommend using Imagick to accomplish this. The problem is, my client's server does not have that extension installed, and the hosting company is unwilling to install the extension.
Nor is PDFLib installed on the server (which supports importing tiffs into a PDF).
Thanks.
This is tricky because of the tiff format. You can do this for most input formats with native PHP functions to create an image object from the source file and then save that using imagejpeg or imagepng. But tiff has patent issues and I don't think it's supported. Have a look at the PHP GD and image functions available on your server. May be some help in the comments here: http://php.net/manual/en/function.pdf-open-image-file.php

php Image processing (convert jpeg to png or gif or wbmp)

The situation is like this :
A server returns me a picture which is in jpeg format. Now I have to do some processing on the image (like writing caption on it,..). Since my server does not support jpeg, I want to convert it to a format that my server supports(png,gif and wbmp). How can I convert the image returned by the server into png/gif/wbmp format without using imagecreatefromjpeg ?
Try Imagine http://imagine.readthedocs.org/en/latest/index.html
In what way does your server not support jpeg? are you saying that the imagecreatefromjpeg() function is not available in your PHP?
Assuming this is the case, then it doesn't mean that your server "doesn't support jpeg"; what it means is that your copy of PHP doesn't have the GD library installed. This will affect all PHP's graphic processing functions, not just JPEG ones.
If you have the ability to install PHP extensions, or to ask your server admin to install them, then installing the GD library will be by far the easiest solution to this problem.
If you don't have that ability, you will still need to install something onto your server in order to read and process an image (of any type, not just jpeg).
A common tool for this is ImageMagick. This is a stand-alone tool, so you can install it and call it from the command line (ie using PHP's exec command, etc). There is also a PHP extension to control it, but obviously this will have the same issue as the GD library if it isn't already installed.
But ultimately, whatever you do, it will involve installing something on your server.

Excel to PDF in PHP

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

PHP, document reading library

I need a library to extract text from documents(doc, doxc, pdf, html, rtf, odt.....). Is there one library(for all document types) for this purpose?
Do batch conversions of the files to one format, using either
odtphp http://www.odtphp.com/index.php?i=tutorials&p=tutorial1
or
PyODConverter (run this using the PHP command line executable tool to make it 'work with' php) http://www.oooninja.com/2008/02/batch-command-line-file-conversion-with.html
Then run that last result through any generic pdf2txt library, or an phpOCR.
A safer bet would be to convert your documents to plain text first, and then parse the contents of the plain text version to do whatever you want. There's a lot of command line converters around that allow you to convert from different formats to plain text (Word to txt, PDF to txt, etc.), on ANY operating system.
BTW Regarding PDFs : not all of them actually contain plain text, some are just a collection of scanned images, so in that case you'll be out of luck (unless you would use OCR on them).
OpenTBS is a PHP tool that can read an modify the contents of any OpenDocument files (ODT, ODS, ODG, ODF, ODM, ODP, OTT, OTS, OTG, OTP). But also OpenXML files (DOCX, XLSX, PPTX).
If you can convert files having an unsupported format you need to one of those supported by OpenTBS, then it's done.
On systems other than Windows, there is no such library to do this for you, and there is a high probability there won't be as such in the future. Main reason is that the document formats you specified are continuously updated from time to time.
On Windows however, if you have php installed, you can definitely use activex extensions to read all of these formats with ease, and you will only need the proper office application to be installed apart from php on the machine to get this to work. This will also make sure future versions of documents continue to work in your php code, as long as your office applications can read those document. Look for 'php win32' libraries in php library collections and you should find some nice one there

Categories