We have a enveloping machine that is able to read optical character recognition codes (OMR). See: http://en.wikipedia.org/wiki/Optical_character_recognition
For that we want enrich our PDF output with such an OMR code. We use FPDF in PHP to generate our documents.
Is there a way to greate these codes maybe as a picture?
Thanks a lot!
Perhaps you could insert images into your PDF that your OMR enveloping machine could read.
If so, I can recommend this FPDF Script which writes out standard HTML which can include images into the PDF being created:
http://fpdf.org/en/script/script42.php
$pdf->WriteHTML("<img src="http://www.example.com/OMR_readable_image.gif">");
If you need to dynamically create images with page numbers, I can see a solution where you combine a circle background image with the page number text to create an image that you then use as your image source.
How to create an image dynamically:
http://www.php.net/manual/en/image.examples-png.php
Related
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.
I am using dompdf to generate a PDF file. The PDF simply contains texts. I need the content of the PDF to show as an image instead of texts. I do not know where to start. Cannot find anything using Google. Any suggestions?
More info:
In the PDF I currently generated, I can select specific portion of texts by highlighting it using the mouse. In the PDF I should generate, I should not be able to select portion of texts because the texts is already an image. So the PDF I should generate contains an image, and the image contains the texts.
You could generate a png first using phpgd / ImageMagick then shove it through dompdf
I am using HTML2PDF converter in order to export web page to PDF file. The issue I have faced is that the result PDF is to large (more than 1 MB). I want to reduce it, so here is what I have basically:
2 images (100 KB both)
1 Courier Bulgarian font - added
3 tables with a lot of inline styles of each cell
Could these things lead to the large size of the output PDF? And could anyone share some experience and best practices with the library in order to get smaller PDF as result.
Thanks in advance.
If you have access to Adobe Acrobat, it'll let you peek in the PDF and see which areas use what percentage of space. This would tell you how much of the space is taken up by images, fonts etc... If you make a sample PDF available I'll be happy to take a look at it.
How much space in the PDF is used by different objects really depends on how the PDF was written and how efficiently it uses different compression algorithms. For example, images can be ZIP, JPEG or even JPEG-2000 compressed in PDF, the question is what HTML2PDF does with your images.
Fonts can be big as well - depending on what the size of the original font is.
Page content (your tables with inline styles etc) are written in a condensed textual format (for example 1 0 0 rg would be the instruction to set the fill color for text and line-art to red). Normally efficient PDF writers will write all of these textual instructions and then ZIP compress them, which means they won't take much place in the file.
So you'd really need to take a look at the PDF file itself to see where the space is used. That will allow you to start looking at the library to see if it can be made more efficient.
To start with...
Have one separate page for printing and displaying - for printing.
While printing use Ptint.CSS and include as less as possible classes
In those three tables. Keep only require classes in CSS. Please use compress images for printing e.g if you have BMP in display use the PNG for printing.
Make tables simple using TR-TD and make them less colorfull do not put inline CSS.
This may help you to save PDF in compress version.
I have mananged to find what causes the big size of my output PDFs files. It last the fonts.
For my task I have used courier bulgarian (italics, normal and bold). This means I have embeded three additional fonts.
Something more, I do not know, but helvica is the defauld font for this PHP library and althought I am not using it, it is embeded to the PDFs too.
If you meet the same issue, open all files that have "helvica" and replace the "helvica" font with this that you are using.
I have been reading about this but I have to do some thing. I have a table with diagonal text in the heading columns and horizontal text in the rows. I was able to make text diagonal using CSS rotation thing, table data is coming from db and I want to generate the same html into the pdf. I don't know who to write diagonal text in the pdf. The solution is to create an image of the visible html table with data and then store it and then make pdf and embed that image there. I have been reading the GD library but how can I make table in GD library I am stuck , Stack Overflow is the last resort. Please help.
try this ezpdf class http://www.ros.co.nz/pdf/readme.pdf. they got some sample code to rotate text and how to embed image into pdf.
example
for ($angle=0;$angle<360;$angle=$angle+20){
$r=rand(0,100)/100;
$g=rand(0,100)/100;
$b=rand(0,100)/100;
$pdf->setColor($r,$g,$b);
$pdf->addText(300+cos(deg2rad($angle))*40,300-
sin(deg2rad($angle))*40,20,$demotext,$angle);
{
$pdf->stream();
If you want to go directly from your HTML code to PDF, and if you need something entirely in PHP you can try dompdf. The 0.6.0 release will include CSS transform support.
For image generation in PHP you can use GD functions (fast) or iMagick (not so wide spread, docs are WorkInProgress, but you could do almost anything you can imagine with it).
GD should be enough.
A simple idea about making text diagonal would be to just rotate the image, once you output text from the db onto it.
Use wkhtmltoimage or wkhtmltopdf.
Do you need to do this only once or does this need to be an ondemand service? If not why not just load the html page take a screenshot and crop it down to the table?
Instead of trying to convert HTML directly to a PDF document, you might want to try a PDF library for creating the document directly in PHP. This way you will get more control over what the PDF looks like, and it may be a better solution that trying to convert your HTML output.
https://stackoverflow.com/questions/560583/which-is-the-best-pdf-library-for-php
How can I rotate a pdf document using php and linux?
Rotate an Entire PDF Document's Pages to 180 Degrees
$command = "pdftk in.pdf cat 1-endS output out.pdf";
system($command);
You could use pdf90 from PDFjam.
To address some of the other suggestions:
I would be wary of adjusting the Rotate attribute directly, as this attribute is stored as text, and '90' or '270' obviously uses a different number of bytes to '0'. I believe inserting the required bytes can make a mess of the index tables that appear at the end of a PDF file. After that, you're reliant on a viewer being able to interpret the damaged file.
Rendering the PDF to an image and rotating that is going to rasterize any text or vector graphics, leading to either a much larger file size, or much lower quality.
You would have to use a external library like this to extract the info a generate an image, then put it back to the pdf(or a new one)
EDIT:
If your going to get a Logo or a diagram this is a good choice, if its a big document with text and lots of images... its going to be pretty hard, could you edit the OP with more info on what you need?
You will have to access the PDF as a binary file then find and adjust the "Rotate" attribute for each page (and possibly the "MediaBox" attribute). I am not aware of any PDF libraries for PHP that allow for this sort of direct manipulation of existing files. This method will not require changing anything about the content of the pages, it just changes the orientation the pages are displayed in by viewers (similar to the EXIF Orientation information in JPEG images).
This snippet of perl should help illustrate what parts of the file you are looking for.
There are a few libraries for handling PDFs with PHP.
Here's a good code example using such a library. I found it, just by Googling "PHP PDF":
http://www.fpdf.org/en/script/script2.php