I have a website build on CakePHP framework. I have already integrated Dompdf library for generating PDF from HTML.
And now for viewing the PDF files, I need a pdf reader that will be embedded into the website with limited capabilities so that the files cannot be printed or shared. Ideally, this would be the layout of the reader. The top would show the title of the document and people can highlight, scribble, add note to the document.
Please try out PdfJs
It suits your needs the most and it has good documentation so you could get started quickly
Related
I am working with a tool which lets user upload a .csv file.
That csv file contains an address column. I have to use the address from each row in another HTML template. That HTML template is like this
. After creating that template I then need to convert it into a PDF, store the PDF on a file server and give the user a link to the PDF.
I've finished the first two steps - csv upload and created complete template with address, but I'm stuck on how I can convert a template into a PDF.
I have looked into a few php-pdf libraries like fpdf mpdf. I'm facing a problem in creating pdf with html template.
A link to a library wich convert HTML to PDF and works pretty well.
First the link to the library
HTML2PDF
Then some code* to create your PDF using your own generated HTML, where $content is your HTML string.
$html2pdf = new HTML2PDF('P','A4','fr');
$html2pdf->WriteHTML($content);
$html2pdf->Output('exemple.pdf');
*Code taken from the "example page" of the site.
I have used tcpdf in many cases, https://tcpdf.org/
Works well with tables, I have made receipts and accounting related stuff with it. Handle UTF-8 without problems, why it's my way to go.
Only downside is that code is bit long and complicated and it doesn't keep tables as tables in pdf and turns them to divs, so paddings and other styles might be bit trickier to do.
One way is to use webkit based HTML to PDF converter.
Pros are that it is easy to customize and style and to see in the browser how it will look and then you can be sure that it will look as same in PDF as well. You could use CSS and JavaScript as well to style and modify.
Cons are that it is hard to install it on the production server sometimes. But there are web services and APIs that get you covered.
For example one service is https://pdfapi.io. It is free to use. Only when your amounts get bigger, then it will charge like a cup of coffee.
Hope that helps.
I'm developing a PHP MySql website in which pdf will be uploaded by site administrator. Viewers will get a list of all the pdf documents.
What I want is:
To open the PDF in my <div>.
No user should be able to download the PDF by any means.
I tried google doc viewer, it simply converts pdf to images which can be saved easily.
Also it gives View in Full option by which one can easily download the pdf.
And ofcourse,
<div><object data="test.pdf" type="application/pdf" width="300" height="200"></object></div>
is not working.
Please help..
You can use an iframe to embed a PDF inside a div, though it will rely on them having a PDF-reader plugin enabled on their browser. However, there is no way to show a PDF to a user in a way that does not let them save it
In order to read the PDF they HAVE to save a tmp version on their computer in any case, so you simply cannot prevent them from having a copy if they want.
There are a variety of ways to make it more difficult, but that's it. Tieson's solution, which draws the PDF to an HTML5 canvass makes it difficult to get the original PDF for non-technical users, but it only took about 2 minutes for me to find the PDF source and download the original (i.e. http://hazaar.funkynerd.com/pdfdoc/get?file=acr5smallpdf_80327_7.pdf). There are other, similar approaches using java or flash that don't actually show the PDF, but rather a rendering of the PDF by a third-party plugin, which will make it even more difficult, but even then the user could re-create the PDF using third-party tools or just simple screenshots, etc.
It's not really 100% reliable/stable, but there is a jQuery plugin for Mozilla's experimental PDF.js at http://dev.funkynerd.com/projects/jquery-pdfdoc
I have very limited access to enable extensions etc on my hosting but am looking to generate a PDF from an HTML page (with css/images) through PHP.
Any ideas how I can achieve this with next to zero CL access etc?
Preferable not a "hack" / relient on a service (as I'll be looking to use this long term).
When generating HTML to render in to the PDF, create that HTML in single $html variable. This can be used to pass to the any of the pdf rendering api's.
Widely used API's are DOM PDF, html2pdf, html2ps.
Some of the API's like html2ps also supports the external css & classes also. Some required inline CSS.
I have used DOM PDF & html2ps
here are the links
domp df
HTML2PS & HTML2PDF
A number of solutions exist out there: domPdf, mPdf, html2pdf, tcpdf, zendPDF (zend framework) etc. I have used domPdf and mPDF very extensively and others just "in passing". domPdf is very easy but doesn't quite have the bells and whistles. html2pdf is not bad either, however, I am partial to mPDF as I believe it has the best set of features out there. For full documentation see this link: http://mpdf1.com/manual/index.php
I've converted pretty complicated web pages into pdf and mPDF seems to render them the best.
Found this yesterday just here at SO: mPDF. Haven't tried it, but the documentation is solid.
Check out html2pdf, I never used it, but it looks promising.
I am trying to take the raw data from a previously made PDF, and append it to a new PDF using DOMPDF. Is this possible?
Thanks for any help,Metropolis
Are you talking about overlaying one PDF on top of another or appending the pages of one document to another? DOMPDF doesn't currently support either type of functionality because it is focused on HTML to PDF conversion. Due to this focus by the project you're not likely to see any work put in to support the handling of existing PDFs anytime soon.
This doesn't help for your current project, but you might post a feature request to add support for a library that is capable of performing a merge (I think FPDI may work). DOMPDF relies on third-party PDF rendering engines for creation of the actual PDF. A modified version of the CPDF library is included with DOMPDF, but there's no reason other rendering engines couldn't be supported.
if it helps someone else,
what I did, I concatenated the HTML string in a loop and then made a pdf file after the loop.
And ofcourse using page-break-after: always; which creates a new page.
I am using FPDF / FPDI to build a PDF templating system. One PDF is used as the background and has a number of editable regions defined within it (stored in database). An editable region could be an image, a text, or both, however this is not my question, just a bit of background.
Some of the backgrounds (FPDI source PDF) PDFs or 'templates' contain embedded fonts, I want to be able to achieve two things and was wondering if this is possible.
I want to be able to use any fonts embedded in the source document in the output document.
I need to enumerate these fonts so that they can be included in the UI's font list.
To be clear I want to reuse these fonts, not just have them applied to the imported page, but offer the option to render new text in one of the embedded fonts.
Any pointers would be greatly appreciated.
First on fonts and PDFs.
If I remember correctly, when a font gets included into a PDF, all of the font can be included, or just a subset of the font covering the character faces actually being used can be embedded. Some of the PDF 'compression' tools can strip the unused font glyphs from the pdf file. (Can someone confirm/refute this?)
As for FPDF (it's the library I use), I don't think it can open a PDF in 'edit' mode. It can simply open a PDF and use it as a background - effectively an image of the document. A quick look through the contributed scripts appears to show no scripts that will open a PDF file for real (besides one that can just get the meta-info on the document).
There are other options for PDF libraries. The demonstration of TCPDF I saw at the following presentation, showed that TCPDF may have more in-built capabilities the FPDF. It may be worth a look into that library?
http://suburbanchicagophp.org/archives/75
I am the orginal question asker, but I lost my temp account so cant comment (admin please merge if you can).
Just to clarify.
We have chosen to use FPDF over over TCPDF due to compatibility problems detailed on the FPDI website as FPDI is the core component in this, dropping FPDI was not an option.
We use FPDI to pull pages from the template document, and we then place text and images (as defined in the database using a web UI) over the top of each page, so the usuage is exactly as FPDI allows.
I found another question on this board asking about pulling embedded fonts from pdf files, the asker was slated for copyright infringing activites which is a huge assumption.
How can I extract fonts from a PDF file with Perl?
Our templates will be coming from our designers, we want to resuse (rather than extract) fonts in the template pdf.
So these are our fonts, we just dont want every machine this pdf passes through for editing to have to not only have the font available to embed, but also to select and embed the correct font. It leads to double, even tripple handling of fonts, and possibly some guess work.
One of the replies in the above post is a very helpful direction, it is a Perl module that can enumurate embeded fonts, which is exctly what I need to display embeded fonts in the UI font list.
Now I need to test if the fonts embedded in a source (template) pdf are carried across to the new pdf, I presume they must be, so there must be a resonable way to reuse them.
Ill post back for completelness when I know for sure, still if anyone has any feedback or knowledge on this it would be greatly appreciated.
p.s. it is correct that some editors will create compressed pdf documents and strip some of the unused font, however it is a simple request for us to say dont use an editor that does this, or you will have to re-embed the font.
To further clarify this, Zend_PDF will allow for this exact functionality, enumerating and then reusing fonts embeded in a PDF, but it will not work with PDF later than v1.4, with v1.4 pdf however Zend works very well:
e.g the following is possible in Zend_PDF and then a font can reused by name:
public static function GetFontList($background)
{
$pdf = Zend_Pdf::load($background);
$fonts = array();
// Get all document fonts
$fontList = $pdf->extractFonts();
foreach ($fontList as $font)
{
$fontName = $font->getFontName(Zend_Pdf_Font::NAME_POSTSCRIPT, 'en', 'UTF-8');
$fonts[] = $fontName;
}
return $fonts;
}
Hopefully this will be helpful to someone, however I need a higher pdf versions than 1.4 so I guess I am looking to modify FPDI.