shasi kanth
shasi kanth

Reputation: 7102

Convert pdf to html in php

I want to read the pdf documents and display the content to the browser, without allowing the users to save a copy of the pdf.

How can i use fpdf for this purpose? So far, i could not figure out a way of reading a pdf document with fpdf, apart from creating a new pdf. Can anyone suggest an example of reading a pdf file, and if possible, how to disable the save as pdf option?

Upvotes: 1

Views: 11922

Answers (4)

oezi
oezi

Reputation: 51817

fpdf can't read pdf's. take a look at it's FAQ - 16 an 17 sound interesting and it loooks like there are addons to do this.

what you really can't ever avoid is to let the user save that pdf - it has to be sent to the browser at the clients machine, to display it, so there will always be a possibility to save it. a possibility would be to transform every page of the pdf to an image (using Imagemagick for example) and oly display these images, so the user can't copy the text from it and has no possibility to get the original pdf-document - but that will only annoy people.

Upvotes: 2

Sondre
Sondre

Reputation: 1898

To convert a pdf to html there a program for linux called pdftohtml. However be aware that the result of this will not create something that looks like the original pdf and in many cases (locked pdf's etc) it will fail. What is a possible solution is generating an image of each page using a program like ImageMagick, then place the html over on an invisible layer to allow for interaction. I'd still rather go for displaying the pdf inline if I were you though.

Upvotes: 0

powtac
powtac

Reputation: 41080

Im not sure if this is possible, check the FPDI extension for FPDF here: http://www.setasign.de/products/pdf-php-solutions/fpdi/

Upvotes: 0

fire
fire

Reputation: 21531

If you have an existing PDF you want to display it inline rather than ask them to download it:

// Path to PDF file
$file = "blah.pdf";

// Show in browser
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="'.basename($file).'"');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
readfile($file);
exit();

You don't need to use FPDF that's only a class that helps you create PDF's from scratch.

Also bare in mind there is nothing to stop a user from saving a PDF even when displaying inline.

Upvotes: 0

Related Questions