EPUB to PDF conversion using calibre giving error - php

Below is the error that I am getting while I use the code
$output = shell_exec("/usr/bin/ebook-convert test.epub mech4eck.pdf");
<br>echo $output;
I need to run this with PHP only, and so I am trying to execute the shell commands. I am using Ubuntu 12.
No write acces to /root/.config/calibre using a temporary dir instead /opt/lampp/lib/libgcc_s.so.1: version GCC_4.2.0' not found (required by /usr/lib/i386-linux-gnu/libstdc++.so.6) /opt/lampp/lib/libgcc_s.so.1: versionGCC_4.2.0' not found (required by /usr/lib/i386-linux-gnu/libstdc++.so.6) 1% Converting input to HTML... InputFormatPlugin: EPUB Input running on /opt/lampp/htdocs/test.epub Found HTML cover content/calibre_title_page.html Parsing all content... 34% Running transforms on ebook... Merging user specified metadata... Detecting structure... Flattening CSS and remapping font sizes... Source base font size is 12.00000pt Removing fake margins... Cleaning up manifest... Trimming unused files from manifest... Creating PDF Output... 67% Creating PDF Output

I know none out here helped but I figured out on it my own.
Here is the trick
Rename the file /opt/lampp/lib/libgcc_s.so.1 to /opt/lampp/lib/libgcc_s.so.1.bak
Taddda it works :)

Related

Converting SVG to another format fail due to delegate not being found

I have PHP code running on Debian stretch with ImageMagick. It tries to convert SVG to another format. Here is how it starts
$im = new Imagick();
$im->readImageBlob($svg);
The variable $svg contains valid SVG code in a string. If I copy this string to a text file with a .svg extension then it opens just fine. But readImageBlob throws an exception saying no delegate for this image format.
I have seen similar questions solved by installing more packages to the system. But I've already installed libxml2-dev, librsvg2-bin, libmagickcore-6.q16-3-extra and libfreetype6-dev.
I have no idea what else I am missing.
I had to prepend the $svg with <?xml version="1.0" ?> and it worked. It least it does read in the SVG and attempts to create png/jpeg. One piece of text gets misplaced during convertion though. So the task in general is still failed. But this is another issue. I think the question is answered.
What do you get from running the following command from PHP exec()
convert -list format
The line SVG should say RSVG or MSVG/XML. Does it show that? if you need RSVG, you will have to install that delegate and then reinstall Imagemagick so that Imagemagick can find it. Imagemagick is used by Imagick. They are not the same. The RSVG delegate can be found by a Google Search or from linuxfromscratch.org/blfs/view/svn/general/librsvg.html. Your svg file seems to render properly for me in Imagemagick using RSVG, but I am not sure what it should look like. It is just a graph set of horizontal lines.
I do not know much about using readImageBlob(). Just use readImage(), where you supply the path to a saved svg image file. That should work. Try that and see what you get.
Here is what I get using RSVG 2.42.2 in Imagemagick 6.9.10.3 Q16 Mac OSX were I have saved your text in a file called test.svg.
convert test.svg test.png
If I force the use of the Imagemagick MSVG/XML, it does not look as good.
convert MSVG:test.svg test2.png

why dompdf inside laravel 4.2 failes to load html string?

Inside the laravel controller, When I do this
$html = '<h1><a name="top"></a>mPDF</h1>
<h2>Basic HTML Example</h2>
This file demonstrates most of the HTML elements.
<h3>Heading 3</h3>
<h4>Heading 4</h4>
<h5>Heading 5</h5>
<h6>Heading 6</h6>';
$pdf = App::make('dompdf');
$pdf->loadHTML($html);
$pdf->save('my_stored_invoice.pdf')
It works perfectly.
But when i do this
$pdf = App::make('dompdf');
$pdf->loadView('pdf.invoice');
$pdf->save('my_stored_invoice.pdf');
My browser crashes with the calling URL, Also apache got slowed down.
I have set INI limit 2048 MB.
Please suggest me some way to get out of this problem.
Thanks in advance.
Isnt really an answer but too big to fit in comments... Few things to try:
Check installed:
PHP version 5.3.0 or higher
DOM extension
GD extension
MBString extension
php-font-lib
php-svg-lib
Writeable folders - check to make sure that you are able to write any temporary files.
Check your logs to see what crashed?
Check top / htop / activity monitor etc to see if you are using all your ram
Hello for this is fixed by changing the file permission
/vendor/thujohn/pdf
To allow domPDF to write temporally data

PHP: Save Dynamic URL Image to Disk

Having trouble capturing the following dynamic image on disk, all I get is a 1K size file
http://water.weather.gov/precip/save.php?timetype=RECENT&loctype=NWS&units=engl&timeframe=current&product=observed&loc=regionER
I have setup PHP cURL feature to work just fine on static imagery, but does not work for the above link. Similarly, also copy function, file_put_contents (file_get_contents)...they all work fine for static image. Plenty of references in SO for usage of these PHP functions, so I will not get into details here. Just the copy command:
copy('http://water.weather.gov/precip/save.php?timetype=RECENT&loctype=NWS&units=engl&timeframe=current&product=observed&loc=regionER', 'precip5.png');
Behavior is same, getting precip5.png size 760 bytes, on my windows development box and linux staging box, so can rule OS issues out. Again, all PHP functions do exactly the same thing - generate a file - but empty. Command line curl program is also generating that same junk 1K file.
So, the issue seems to be source and the best I can tell is that it is a dynamic (streaming?) image.
Ideally, I would like this be done in PHP or some command line utility like curl. I am trying to avoid adding java (imageio) dependency just for this...until I absolutely have have to go there...
I am trying to understand the nature of the beast (the image) first ;-)...
The URL you are saving produces HTML output, not the image. You are missing the parameter &print=1
http://water.weather.gov/precip/save.php?timetype=RECENT&loctype=NWS&units=engl&timeframe=current&product=observed&loc=regionER&print=1

FPDF error: This document (testcopy.pdf) probably uses a compression technique which is not supported by the free parser shipped with FPDI

I am running the following code and giving me this error : FPDF error: This document (testcopy.pdf) probably uses a compression technique which is not supported by the free parser shipped with FPDI. I used another pdf named test.pdf and that works fine but it is giving me error in testcopy.pdf.
I think this is parser problem. Anyone know any other parser that can be used with fpdf to avoid this error?
My code:
require('fpdf17/fpdf.php');
require('fpdf17/fpdi.php');
// initiate FPDI
$pdf = new FPDI();
while (ob_get_level())
ob_end_clean();
header("Content-Encoding: None", true);
// set the sourcefile
$pagecount = $pdf->setSourceFile('testcopy.pdf');
I want to split pdf in two pdfs and want to attach both pdfs in file attachments field.How to save pdf to server. Can it be possible with fpdf?
Yes, Exactly the FPDF library supports only PDF version 1.4 & lesser. So to over come from this issue use GhostScript. This script helps to change the PDF versions dynamically.
(1) Download the Ghostscript here.
(2) Install the Ghostscript and define the environment variable PATH.
(3) Then, use the below php code to change the PDF version.
shell_exec( "gswin32 -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dQUIET -dBATCH -sOutputFile=".$new_pdf." ".$old_pdf."");
(4) Now we get PDF with version 1.4 as output, then continue with FPDF.
Enjoy!
I had the same issue that PDFMerger does not work with certain PDF.
It seems that Adobe keep updating compression way of pdf extension.
I found solution with Chrome.
1. Open the PDF file(which does not work with PDFMerger) with Chrome
2. Right Click and Print
3. Change destination as [Save as PDF]
4. This exported PDF file is compatible with PDFMerger
The file needs to be PDF 1.4 (Acrobat 5) or lower. If you have Adobe Acrobat Pro you can change this with Document->Decrease File Size.
Looking through the answers so far, I wasn't able to resolve the issue.
Here's why and you may have the same issue so this answer would be invaluable to you too.
I did not have access to acrobat, so I couldn't downgrade the version of the original PDF. I wasn't in a position to purchase the newer version of the library which has upgraded encryption.
In the end I used an online PDF converter to downgrade my PDF file to version 5 (1.4)
If you are not able to find one, here's a link for completeness.
https://docupub.com/pdfconvert/
(bear in mind that the contents of a link may change)
Here is my answer from another topic:
"It can be overcome by re-saving the template and change compression type.
In Adobe Acrobat Pro go to File->Save As->Optimised PDF-> Popup left list - Clean Up,
Object Compression Options -> Change to "Compress document structure" -> OK to save"
Ref. Editing password protected pdfs with fpdi
GPL Ghostscript 8.70 (2009-07-31) / Centos 7
ghostscript -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dQUIET -dBATCH -sOutputFile=new_file.pdf file.pdf
For those that don't have any of the pro versions of Acrobat:
I was having this problem with new versions of Word when trying to use the Office functionality to save to a PDF. It seems the PDF conversion tool supplied in Office is using the newer formats. Here's how I fixed it.
Install NitroPDF free version (May work with another free PDF creator that can be downloaded)
Go to the Word document and select 'Print'.
In the print options, instead of your printer, select 'Nitro PDF Creator (Reader 3)' or whatever the current version is.
A dialog box will open and allow you to select where to save the PDF.
The version saved was able to be opened by FPDF.
Hope it helps
In the case of Mac, you can open the PDF file in Preview and "export as PDF". The exported one can then be used.
I had a very similar error like you. My solution was to convert the pdf to a lower pdf version. Than everything worked like expected.
I hope that simple trick will help you!

convert pdf to text file in php (note : shell_exec is disabled)

the best way to solve this was to use "pdftotext" that is in the "xpdf" package but in all shared hosts that i googled shell_exec is disabled . i found alternative metods that used only php like a function called pdf2string() (on php.net) but none of those functions didn't work as expected (with some pdf files they just didn't output correct text and with some other pdf they didn't output nothing and some other versions of this function just didnt work at all so i excluded this option). any way to convert that open source pdftotext into a php script ? (source is in c++ i think and can be found here : http://www.foolabs.com/xpdf/download.html) . any other solution will be accepted as far as it gives to me text output of the pdf (the correct one)
Since you have a restricted environment, you may want to look at this.
http://webcheatsheet.com/php/reading_clean_text_from_pdf.php
This uses no external library to parse pdf to text formats.
However, since this parse text out of raw pdf format, i m not sure how stable it is.

Categories