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

how to generate pdf from template #559

Open
hotboyconvoi opened this issue Jun 22, 2015 · 9 comments
Open

how to generate pdf from template #559

hotboyconvoi opened this issue Jun 22, 2015 · 9 comments

Comments

@hotboyconvoi
Copy link

hotboyconvoi commented Jun 22, 2015

i do
$templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor('resources/AF Word.docx');
...
$templateProcessor->saveAs('results/TemplateBlock.docx');
That is good when make docx. But when i use
$templateProcessor->saveAs('results/TemplateBlock.pdf'); => didnot work?
i need a help, thank a lot


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

@hotboyconvoi hotboyconvoi changed the title how to generate pdf from pdf how to generate pdf from template Jun 22, 2015
@csablotron
Copy link

have load pdf library?

example:
\PhpOffice\PhpWord\Settings::setPdfRendererPath('vendor/dompdf/dompdf');
\PhpOffice\PhpWord\Settings::setPdfRendererName('DomPDF');

$template->saveAs('result/sampledocument.docx');
$temp = \PhpOffice\PhpWord\IOFactory::load('result/sampledocument.docx');
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($temp , 'PDF');
$xmlWriter->save('result/sampledocument.pdf', TRUE);

@hotboyconvoi
Copy link
Author

can you help me, how to load library?
thank you,

@hotboyconvoi
Copy link
Author

i had put in in samples/dompdf and i use file /samples/Sample_23_TemplateBlock.php
$templateProcessor->saveAs('results/Sample_23_TemplateBlock.docx');
\PhpOffice\PhpWord\Settings::setPdfRendererPath('dompdf/dompdf');
\PhpOffice\PhpWord\Settings::setPdfRendererName('DomPDF');
$temp = \PhpOffice\PhpWord\IOFactory::load('result/Sample_23_TemplateBlock.docx');
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($temp , 'PDF');
$xmlWriter->saveAs('results/Sample_23_TemplateBlock.pdf', TRUE);

docx created but pdf dont.

@csablotron
Copy link

i don't know if in Sample_23_TemplateBlock.php can export to pdf. but in my code

require_once 'vendor/phpoffice/phpword/src/PhpWord/Autoloader.php';
\PhpOffice\PhpWord\Autoloader::register();

\PhpOffice\PhpWord\Settings::setPdfRendererPath('vendor/dompdf/dompdf');
\PhpOffice\PhpWord\Settings::setPdfRendererName('DomPDF');

$writers = array('Word2007' => 'docx', 'HTML' => 'html', 'PDF' => 'pdf');

$template = new \PhpOffice\PhpWord\TemplateProcessor('template.docx');
$template->setValue('samplekey', htmlspecialchars('this is just simple key'));
$template->saveAs('result/faktur.docx');

$temp = \PhpOffice\PhpWord\IOFactory::load('result/faktur.docx');

$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($temp , 'PDF');
$xmlWriter->save('result/faktur.pdf', TRUE);

FYI, i'm using slim framework...

CMIIW

@hotboyconvoi
Copy link
Author

i use template so can i export to pdf?

On Tue, Jun 30, 2015 at 11:26 AM, Doni [email protected] wrote:

i don't know if in Sample_23_TemplateBlock.php can export to pdf. but in
my code

require_once 'vendor/phpoffice/phpword/src/PhpWord/Autoloader.php';
\PhpOffice\PhpWord\Autoloader::register();

\PhpOffice\PhpWord\Settings::setPdfRendererPath('vendor/dompdf/dompdf');
\PhpOffice\PhpWord\Settings::setPdfRendererName('DomPDF');

$writers = array('Word2007' => 'docx', 'HTML' => 'html', 'PDF' => 'pdf');

$template = new \PhpOffice\PhpWord\TemplateProcessor('template.docx');
$template->setValue('samplekey', htmlspecialchars('this is just simple
key'));
$template->saveAs('result/faktur.docx');

$temp = \PhpOffice\PhpWord\IOFactory::load('result/faktur.docx');

$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($temp , 'PDF');
$xmlWriter->save('result/faktur.pdf', TRUE);

FYI, i'm using slim framework...


Reply to this email directly or view it on GitHub
#559 (comment).

@hotboyconvoi
Copy link
Author

where your file location, my file and library dompdf in PhpOffice/samples/
library: PhpOffice/samples/dompdf.

On Tue, Jun 30, 2015 at 11:33 AM, Nhạc vàng mọi thời đại <
[email protected]> wrote:

i use template so can i export to pdf?

On Tue, Jun 30, 2015 at 11:26 AM, Doni [email protected] wrote:

i don't know if in Sample_23_TemplateBlock.php can export to pdf. but in
my code

require_once 'vendor/phpoffice/phpword/src/PhpWord/Autoloader.php';
\PhpOffice\PhpWord\Autoloader::register();

\PhpOffice\PhpWord\Settings::setPdfRendererPath('vendor/dompdf/dompdf');
\PhpOffice\PhpWord\Settings::setPdfRendererName('DomPDF');

$writers = array('Word2007' => 'docx', 'HTML' => 'html', 'PDF' => 'pdf');

$template = new \PhpOffice\PhpWord\TemplateProcessor('template.docx');
$template->setValue('samplekey', htmlspecialchars('this is just simple
key'));
$template->saveAs('result/faktur.docx');

$temp = \PhpOffice\PhpWord\IOFactory::load('result/faktur.docx');

$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($temp , 'PDF');
$xmlWriter->save('result/faktur.pdf', TRUE);

FYI, i'm using slim framework...


Reply to this email directly or view it on GitHub
#559 (comment).

@hotboyconvoi
Copy link
Author

can you zip for me full lib dompdf?

On Tue, Jun 30, 2015 at 11:36 AM, Nhạc vàng mọi thời đại <
[email protected]> wrote:

where your file location, my file and library dompdf in PhpOffice/samples/
library: PhpOffice/samples/dompdf.

On Tue, Jun 30, 2015 at 11:33 AM, Nhạc vàng mọi thời đại <
[email protected]> wrote:

i use template so can i export to pdf?

On Tue, Jun 30, 2015 at 11:26 AM, Doni [email protected] wrote:

i don't know if in Sample_23_TemplateBlock.php can export to pdf. but in
my code

require_once 'vendor/phpoffice/phpword/src/PhpWord/Autoloader.php';
\PhpOffice\PhpWord\Autoloader::register();

\PhpOffice\PhpWord\Settings::setPdfRendererPath('vendor/dompdf/dompdf');
\PhpOffice\PhpWord\Settings::setPdfRendererName('DomPDF');

$writers = array('Word2007' => 'docx', 'HTML' => 'html', 'PDF' => 'pdf');

$template = new \PhpOffice\PhpWord\TemplateProcessor('template.docx');
$template->setValue('samplekey', htmlspecialchars('this is just simple
key'));
$template->saveAs('result/faktur.docx');

$temp = \PhpOffice\PhpWord\IOFactory::load('result/faktur.docx');

$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($temp , 'PDF');
$xmlWriter->save('result/faktur.pdf', TRUE);

FYI, i'm using slim framework...


Reply to this email directly or view it on GitHub
#559 (comment)
.

@csablotron
Copy link

you can download from here https://github.com/dompdf/dompdf

@philippfrenzel
Copy link

Hi, I have the issue, that the format of my documents crashes while converting to pdf...
I process a template in format docx. Then I save it to a temp file - load it by the iofactory and then save it as a pdf.. I have the same issue by converting into a word2007 format :/ any solution for this?

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

3 participants