Berk Kaya
Berk Kaya

Reputation: 470

Get content of PDF file in PHP

I have a FlipBook jquery page and too many ebooks(pdf format) to display on it. I need to keep these PDF's hidden so that I would like to get its content with PHP and display it with my FlipBook jquery page. (instead of giving whole pdf I would like to give it as parts).

Is there any way i can get whole content of PDF file with PHP? I need to seperate them according to their pages.

Upvotes: 10

Views: 42646

Answers (1)

Umair Shah
Umair Shah

Reputation: 2280

You can use PDF Parser (PHP PDF Library) to extract each and everything from PDF's.

PDF Parser Library Link: https://github.com/smalot/pdfparser

Online Demo Link: https://github.com/smalot/pdfparser/blob/master/doc/Usage.md

Documentation Link: https://github.com/smalot/pdfparser/tree/master/doc

Sample Code:

<?php
 
// Include Composer autoloader if not already done.
include 'vendor/autoload.php';
 
// Parse pdf file and build necessary objects.
$parser = new \Smalot\PdfParser\Parser();
$pdf    = $parser->parseFile('document.pdf');
 
$text = $pdf->getText();
echo $text;
 
?>

Regarding another part of your Question:

How To Convert Your PDF Pages Into Images:

You need ImageMagick and GhostScript

<?php
$im = new imagick('file.pdf[0]');
$im->setImageFormat('jpg');
header('Content-Type: image/jpeg');
echo $im;
?>

The [0] means page 1.

Upvotes: 14

Related Questions