Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Word to PDF conversion issues #1023

Open
aayu-ramola opened this issue Mar 17, 2017 · 10 comments
Open

Word to PDF conversion issues #1023

aayu-ramola opened this issue Mar 17, 2017 · 10 comments

Comments

@aayu-ramola
Copy link

aayu-ramola commented Mar 17, 2017

Hello,
I am using PHPWord with Cakephp 1.3. I used TCPDF, DomPDF, and MPDF to convert a Resume/CV docx to PDF but the output file is not as expected. On page 2 onwards, it contains a lot of extra spaces, a single word is broken into multiple lines, and images (e.g. logo ) is not coming (pls see attachment). Any tips on getting this to work? Thanks

Below is the code I wrote:

Using MPDF:
App::import('Vendor', 'doctopdf/vendor/autoload');
\PhpOffice\PhpWord\Settings::setPdfRendererPath(APP.'vendors'.DS.'mpdf'.DS.'mpdf.php');
\PhpOffice\PhpWord\Settings::setPdfRendererName('MPDF');
$phpWord = \PhpOffice\PhpWord\IOFactory::load($docPath);
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'PDF');
$objWriter->save($PdfPath,true);

Using TCPDF:
App::import('Vendor', 'doctopdf/vendor/autoload');
\PhpOffice\PhpWord\Settings::setPdfRendererPath(APP.'vendors'.DS.tcpdf'.DS.'tcpdf.php');
\PhpOffice\PhpWord\Settings::setPdfRendererName('TCPDF');
$phpWord = \PhpOffice\PhpWord\IOFactory::load($docPath);
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'PDF');
$objWriter->save($PdfPath,true);

Using DomPDF I am getting error :
Fatal error: Uncaught exception 'DOMPDF_Exception' with message 'An input file is required (i.e. input_file _GET variable).' in C:\xampp\htdocs\recruiter\app\vendors\dompdf\dompdf.php:199 Stack trace: #0 C:\xampp\htdocs\recruiter\app\vendors\doctopdf\vendor\phpoffice\phpword\src\PhpWord\Writer\PDF\AbstractRenderer.php(89): require_once() #1 C:\xampp\htdocs\recruiter\app\vendors\doctopdf\vendor\phpoffice\phpword\src\PhpWord\Writer\PDF.php(61): PhpOffice\PhpWord\Writer\PDF\AbstractRenderer->__construct(Object(PhpOffice\PhpWord\PhpWord)) #2 C:\xampp\htdocs\recruiter\app\vendors\doctopdf\vendor\phpoffice\phpword\src\PhpWord\IOFactory.php(44): PhpOffice\PhpWord\Writer\PDF->__construct(Object(PhpOffice\PhpWord\PhpWord)) #3 C:\xampp\htdocs\recruiter\app\controllers\candidates.php(9755): PhpOffice\PhpWord\IOFactory::createWriter(Object(PhpOffice\PhpWord\PhpWord), 'PDF') #4 C:\xampp\htdocs\recruiter\app\controllers\candidates.php(8590): CandidatesController->convertDocToPdf('C:\xampp\ht in C:\xampp\htdocs\recruiter\app\vendors\dompdf\dompdf.php on line 199

Attachment: Alok_Kumar.pdf


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@levieraf
Copy link

I have the same problem!

@levieraf
Copy link

To convert .docx to pdf I am checking the command line doc2pdf, I did the test with this and work ok! also I did a test using the soffice of libreoffice which mean that you need to install the libreoffice. Bc I cannot see a librery on php or python or ruby that convert correctly a docx to pdf.

@tantos
Copy link

tantos commented Oct 29, 2018

I got the same problem.
I lost the header and styles when converting word to pdf using MPDF, TCPDF or DomPDF.

@yjrowe
Copy link

yjrowe commented Mar 19, 2019

I also have the problem.
I got random code and the img became big when converting docx word to pdf using DomPDF.
the problem is so egg pain.

@moly4565
Copy link

moly4565 commented Dec 2, 2019

I got same problem.
I lost header footer,radio button when converting word to pdf. pls help me.
my code below
define('PHPWORD_BASE_DIR', realpath(DIR));
require 'phpoffice/phpword/vendor/autoload.php';
require 'phpoffice/phpword/vendor/tecnickcom/tcpdf/tcpdf.php';

$PdfPath = realpath(DIR).'/phpoffice/phpword/vendor/tecnickcom/tcpdf';
\PhpOffice\PhpWord\Settings::setPdfRendererPath($PdfPath);
\PhpOffice\PhpWord\Settings::setPdfRendererName('TCPDF');
//echo $paths=realpath(DIR).'/'.$fpdf1;
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->SetCreator(PDF_CREATOR);
$pdf->AddPage();
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
$pdf->setPrintHeader(true);
$pdf->setPrintFooter(true);

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
$pdf = \PhpOffice\PhpWord\IOFactory::load(realpath(DIR).'/'.$file);

$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($pdf ,'PDF');
$xmlWriter->save('pdf/'.substr($file,5,-5).'.pdf');

@yjrowe
Copy link

yjrowe commented Dec 3, 2019 via email

@yvescleuder
Copy link

I problem.. not converting header..

@mpolch
Copy link

mpolch commented Mar 30, 2021

I am having problems with tabulators. They are just moved to the left..

@Asmitta-01
Copy link

I am having problems with tabulators. They are just moved to the left..

I have the same problem.

@Asmitta-01
Copy link

Anyone has a tip for it please ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

8 participants