Overlap two PDF in tcppdf - php

I want to overlay two PDF file in same page. I want to use one PDF as background and overlay other PDF data on this. I do not want to concat the two PDFs.

tcppdf definately doesn't support this idea, I'm not even sure if it supports background images? What you could do is covert the pdfs into images, do some image manipulation to make one the background of the other, then convert back to pdf?
I know this sounds messy but the less work done with the pdf generation the better in my experience.

Related

Library to create print-ready charts in PDF using PHP 5.3

I have to create some nicely formatted charts (bar and 3D pie) from dynamic data using PHP 5.3 and for output as PDF report. The report is not to be rendered to the screen at all. I have made the charts using pChart2 as .png files and imported them using tcpdf. The system works, but the quality level is poor, rendering text as a graphic causes the font edges to be blurry etc. when printed. I tweaked the image size of the .PNG output, and it made some improvements but it increases the file size, and the text still looks blurry.
So what I am after is a library to create charts using PHP that can be exported to .svg or .eps format, so elements are drawn by the printer and render sharply for print. Using TCPDF I have imported our logos that are in .EPS format, and the difference between the images is quite marked.
I have seen there is a library called ezcomponents that i can give a try. But before I dive in, is there any advice on what to try before proceeding?
I have had reasonable success rendering the images on a canvas that is two to three times larger than what I ultimately need and then, once I'm finished, using the imagecopyrresampled() function to copy the large image onto a canvas with smaller dimensions, which I save as a png and add to the PDF file. The dithering is pretty good and curved lines, in particular, benefit greatly from this approach. Text might not benefit quite as much, but its worth trying, because it should require very few changes to your code to experiment with this approach.

What PHP library or tool can scale the size of an existing PDF and its contents?

I have written an web application that dynamically creates PDFs that contain only 1-page that has various vector graphics in it, say for example a complex pie or bar chart. In the back-end I have need to scale this PDF and its contents programaticaly to a few different sizes for print.
The few tools I've looked at so far for PHP seem to generate an image out of the original PDF and scale that, which doesn't work for me, I need the contents to remain vectorized and scale with the document.
Any pointers?
probably the simples walkaround would be to generate different PDF files for different page sizes from your original web-application

PHP generate HTML convert to JPG then to PDF

I'm developing an app where the user adds items to a list. That list is stored in an array and passed to PHP with JSON.
The objective is to then create a PDF with all the values extracted from the user. The PDF is quite complicated. It includes images depending on what the user selects and the text varies depending on the images and the input data.
The first idea was to generate the pdf in php with one of those pdf libraries, but that's going to be a real hassle.
Then I thought of creating an html & css (much easier) and the convert it to PDF. But since the html & css are quite complex I don't think those pdf converters will work with this.
Then I thought I could convert the html to jpg and then to pdf.
It'll be much simpler if I could just use html but the output needs to be pdf.
What do you suggest?
Here's a post that discusses creating PDF files with PHP and the PDFLib extension.
Generate PDFs with PHP it's on sitepoint.
Or if you want to go from HTML to the PDF it looks like TCPDF might work.
You can try using FPDF
Then I thought of creating an html & css (much easier) and the convert it to PDF. But since the html & css are quite complex I don't think those pdf converters will work with this.
wkhtmltopdf to the rescue! If you are on a VPS or dedicated machine, it's probably the best (open source) HTML-to-PDF engine out there. It leverages Webkit, the rendering engine used by Google Chrome and Apple Safari, amongst others.
Otherwise, your only other options are going to involve drawing every aspect of the PDF or image yourself, "by hand" in your code.

Can I make html table into image to embed into pdf

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

Using PHP to recreate something similar to VistaPrint / CafePress / Zazzle. Any Ideas?

I am working on a website in which the client wishes to have users upload background images to a printable design, crop to size, add text. Do this to multiple pages then generate a pdf of the 'book'
I am running into the following issues/questions and just need to see where I can start
Are there any PHP developer packages that can do something similar. I have seen jquery crop tools but something also for adding text to an image?
How would I keep the resolution up? If the final cropped with text image needs to be 150dpi, when cropping I am guessing I would have them working on a 72dpi image, then somehow apply the crop and changes to the large image?
If the resolution issue wasn't a big deal I would go about it this way:
Simple image upload
Use jquery to crop photo to correct dimensions
Mess around with gdlibrary and imagettftext() to get the text onto an image (page)
Use something like FPDF to create a pdf from each 'page'
Is this the right way to go about it and any thoughts on the resolution issue. Thank you for any help!
Your primary tool should be ImageMagick. ImageMagick can do the cropping, resizing, scaling, overlay text or graphics, combining images, and apply special effects. A big advantage of using a separate tool instead of PHP's image manipulation tools is that you can do the same transforms in batch through other mechanisms, or even hand the work over to another server to keep the website more responsive. And if you do want to integrate it tightly into the website, you can use the MagickWand For PHP interface.
Cropping does not change DPI, only the dimensions of the image. Scaling, on the other hand, changed both.
You should take a look at Gallery, a GPLed program with some of the functionality you're looking for, and written in PHP.
domPDF is a good tool for converting HTML to a PDF. this way you can use the image they upload as a background image, then put the text over it in any standard HTML tag.
As far as the resolution/dpi issue goes, I'm not sure if there is much you can do outside of changing the size of the image. I would recommend looking into This PHP Library, which has a lot of good tools for manipulating images.
I think with a combination of these tools, you'll be able to create HTML that can make a PDF that's fit to print, and use that.

Categories