reducing the size of generated pdf using FPDF [closed] - php

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm generating a pdf for every page using FPDF. Its working properly. But the main problem is with the file size. Some files have a size of more than 2Mb. I want to limit the size. How can I limit the size within 300 kb? Any help would be appreciated.

Typically PDFs are large because they contain large images or because they contain large fonts.
So the solution is typically to reduce the resolution of the images and to avoid the fonts getting embedded.
If FPDF will allow you to do this then this will likely solve your problem.
If not then you will need to post-process your PDF using another library to unembed the fonts and resample the images.
ABCpdf will do this using the ReduceSize operation. No doubt other libraries will allow something similar.
I work on the ABCpdf .NET software component so my replies may feature concepts based around ABCpdf. It's just what I know. :-)

The best way is to compress pdf file is that first you generate the pdf and then use any tool to compress the pdf file. As far as my experience is concerned, there is no other way to compress pdf file.

Related

Best method to server-side img compress from full src img [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 10 months ago.
Improve this question
I want to display a simple image gallery on a PHP webpage where the images are compressed; however, it allows for full res jpegs to be downloaded. And I'm just curious what method you would recommend for a project like this?
I'm thinking I store the full-res jpeg on my server and use server-side PHP imagecreatefromjpeg() and imagejpeg() to create a lower-res thumbnail of the image with an option to download? Or I suppose I could store lower res and high res jpegs both on the server and just echo them out but I would rather not store the lower res if possible.
Are there any other options for a project like this? And if imagejepg() is a good option, would someone direct me in how to use it?
Lower-rez images typically take much less disk space, much less, than hi-rez images. Disk space is extremely unlikely to be a limiting factor when you pre-create the smaller images.
And, resizing and decompressing on the fly in response to user requests eats server power. Store the low-rez images: think green.
For what it's worth, WordPress (40% of web servers on the net) resizes on upload and stores resized images, so that approach is proven effective.

How to save data from phpmyadmin database to pdf? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have a database on phpmyadmin. Then I have a website with some products. When user clicks on a specific product, he gets some details about that product. Those details are pulled from the database.
My question is: Is it possible to create a pdf file with the specific details about that product, so the user can download it?
So, the options i know are:
DOMPDF : php class that wrap the html and build the pdf. Works good, customizable, based on pdflib, if i remember right it takes even some CSS. Bad news: slow when the html is big or many complex.
this is a tutorial to follow :http://www.sitepoint.com/convert-html-to-pdf-with-dompdf/
HTML2PS: same of DOMPDF, but this one convert first in .ps (ghostscript), then, in whatever format you need (pdf, jpg, png). For me is little better then dompdf, but have the same speed problem.. oh, better compatibility with css.
Those two are php classes, but if you can install some software on the server, and access it throught passthru() or system(), give a look to these too:
wkhtmltopdf: based on webkit (safari's wrapper), is really fast and powerfull.. seem like is the best one (atm) for convert on the fly html pages to pdf, taking only 2 seconds for a 3 pages xHTML document with CSS2. Is a recent project, anyway, the google.code page is often updated.

Display Document (PDF) Like SCRIBD.COM [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I want to display some pdf file on my website, but I do not want people to download the file. like scribd.com that displays the document.
anyone can help me?
If you want to make sure your user cannot download the original PDF file you will have to convert it to something else before.
Scribd converts the PDF to HTML (with one image in the background that contains all non-text objects). I am not aware of any PDF to HTML parsers, so you would have to write your own. Due to the nature of PDF files, this will unfortunately not be easy (see this question for some more details: Convert PDF to HTML in PHP?)
If you are fine with relying on some external web service, you might try this: https://cloudconvert.org/pdf-to-html
As an alternative to parsing the PDF to HTML, you could also just output it as an image. This is much easier to achieve but also not very nice in terms of user experience. If you chose this method, the easiest way would be to use ImageMagick and Ghostscript (see https://stackoverflow.com/a/467805):
<?php
$im = new imagick('file.pdf[0]');
$im->setImageFormat('jpg');
header('Content-Type: image/jpeg');
echo $im;

How to download a full HTML page as pdf using DOMPDF? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I used dompdf to download a receipt that is initially in HTML format. But as soon as it gets converted, the orientation and the format gets distorted. Is there way to download an HTML page as pdf with the same height and width as the HTML page?
No there is not. Every html->pdf tool are different. some doesnt allow css some allow html5 but very bad. some allow gif etc. lots of variations. You shouldnt look for a tool that render the html page and convert to pdf. You should find something like view the page and get its screenshots of it and print as pdf. because today's complex html pages are just too overwhelming for html->pdf tools. Those tools are made for html coders to create fancy pdfs.
Try to search browser plug-ins. If you find one you can automatize the process via linux konsole. (fire-fox, maybe chrome too not sure though)

How do I extract image from a pdf file using php [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
Please, any ideas on how to extract image from pdf in php?
Take a look at pdfimages. Here is the description from the page:
Pdfimages saves images from a Portable
Document Format (PDF) file as
Portable Pixmap (PPM), Portable Bitmap
(PBM), or JPEG files.
Pdfimages reads the PDF file, scans
one or more pages, PDF-file, and
writes one PPM, PBM, or JPEG file for
each image, image-root-nnn.xxx,
where nnn is the image number and
xxx is the image type (.ppm, .pbm,
.jpg).
NB: pdfimages extracts the raw image
data from the PDF file, without
performing any additional
transforms. Any rotation, clipping,
color inversion, etc. done by the PDF
content stream is ignored.
I believe you can use imagemagic as well. You can send it command line arguments and snap a picture given the coordinates you can provide. You will need to install some rpms etc.
Check out PDFLib. Their TET product does just that. You can get the images and text out... Only thing it doesn't cover is vector images.
If you have an existing PDF File I guess it's pretty impossible to extract an image from there using PHP, maybe you'll have better luck with C: you need to disassemble the binary file, decode/decompress/decompile it and find where the image is stored, then copy it.
It's easier if you just copy'n'paste it.

Categories