We help IT Professionals succeed at work.

DOC to PDF using php

codeoxygen
codeoxygen asked
on
Is there any php script available to convert docx file to pdf.
just convert a docx file as it is in pdf and save.
Comment
Watch Question

Kiran SonawaneProject Lead
Top Expert 2011

Commented:
There is library called 'phpLiveDocx' which offers methods to convert from DOC to PDF.
Google for 'phpLiveDocx' and you will find plenty of sample applications.
Most Valuable Expert 2011
Top Expert 2016

Commented:
What is the reason for choosing PHP as the programming language for this application?

Author

Commented:
its a site made in php, where gift vouchers are downloaded, I want them to be downloaded in pdf.
1) i already made in doc. , some fields get replaced in doc. and the downloaded. but the client needs in pdf.
2) either simplest, in the current sytem, i get an option to convert to pdf
3) if there is any method to replace certain text in pdf.

Author

Commented:
and the zend has to be installed on the server ??

Commented:
Why not use http://html2pdf.fr/ and make your vouchers in HTML
Most Valuable Expert 2011
Top Expert 2016
Commented:
You might find the free and popular open source FPDF tool useful.  You can import images and write over them or around them.  You can set the locations of things with great precision.  You might consider making a screen capture of the Word document, then using that as a background image on your PDFs.
http://fpdf.org/
<?php // RAY_fpdf_hello_world.php
error_reporting(E_ALL);

// BRING IN THE PDF THING
require_once('fpdf16/fpdf.php');



// DEMONSTRATE THE BASICS OF FPDF



// SYNTHESIZE THE PDF FILE INFORMATION
$pdf_file_link = '/RAY_junk/' . 'temp_pdf_blue' . '.pdf';
$pdf_file_name = getcwd()     . $pdf_file_link;

// DO THE HELLO WORLD EXERCISE IN WHITE ON A BLUE BACKGROUND
$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial', 'B', 16);
$pdf->SetFillColor(  0,   0, 255);
$pdf->SetTextColor(255, 255, 255);
$pdf->Cell(40, 10, 'Hello World!', 0, 2, 'L', TRUE);

// WRITE THE PDF TO DISK
$pdf->Output($pdf_file_name, 'F');

// PRESENT A LINK
echo '<a target="my_PDF" href="' . $pdf_file_link . '">Blue PDF</a>';



// START OVER FOR A NEW PDF
unset($pdf);
echo PHP_EOL . "<br/>";

// SYNTHESIZE THE PDF FILE INFORMATION
$pdf_file_link = '/RAY_junk/' . 'temp_pdf_red' . '.pdf';
$pdf_file_name = getcwd()     . $pdf_file_link;

// DO THE HELLO WORLD EXERCISE IN WHITE ON A RED BACKGROUND
$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial', 'B', 16);
$pdf->SetFillColor(255,   0,   0);
$pdf->SetTextColor(255, 255, 255);
$pdf->Cell(40, 10, 'Hello World!', 0, 2, 'L', TRUE);

// WRITE THE PDF TO DISK
$pdf->Output($pdf_file_name, 'F');

// PRESENT A LINK
echo '<a target="my_PDF" href="' . $pdf_file_link . '">Red PDF</a>';

Open in new window