I’m having trouble installing PDFlib in my apache to use in my wordpress application.
I followed the tutorial PHP
I still did the following command, because I thought in another doubt about the installation:
echo "katleia.com.br localhost" | sudo tee /etc/apache2/conf-available/fqdn.conf
sudo a2enconf fqdn
It is katleia.com.br/worpress the route I put on my browser to access my page.
However when I give the command:
service apache2 restart
It’s the next exit with error:
* Restarting web server apache2 [fail]
* The apache2 configtest failed.
Output of config test was:
AH00526: Syntax error on line 1 of /etc/apache2/conf-enabled/fqdn.conf:
Invalid command 'katleia.com.br', perhaps misspelled or defined by a module not included in the server configuration
Action 'configtest' failed.
The Apache error log may have more information.
Can someone help me configure PDFlib? because I’m about four hours trying to make it work in wordpress and has nothing to right.
Already I leave on notice not want to install a wordpress plugin.
UPDATE
To undo this command:
echo "katleia.com.br katleia" | sudo tee /etc/apache2/conf-available/fqdn.conf
UPDATE2
I managed to make him stop giving error but still does not work.
I did the following command in order to be able to restart the server:
echo "ServerName localhost" | sudo tee /etc/apache2/conf-available/fqdn.conf
sudo a2enconf fqdn
service apache2 restart
with this my server returned to work, I added this code in a php file that is named after the click on a button to test:
try{
$pdf = new PDFlib();
} catch (Exception $e) {
echo "error: ".$e->getMessage()."<br>";
} finally {
// open a file
pdf_open_file($pdf, "test.pdf");
// start a new page (A4)
pdf_begin_page($pdf, 595, 842);
// get and use a font object
$arial = pdf_findfont($pdf, "Arial", "host", 1);
pdf_setfont($pdf, $arial, 10);
// print text
pdf_show_xy($pdf, "There are more things in heaven and earth, Horatio,",50, 750);
pdf_show_xy($pdf, "than are dreamt of in your philosophy", 50,730);
// end page
pdf_end_page($pdf);
// close and save file
pdf_close($pdf);
}
He did not have any error, but when I try the file do not find anywhere.
UPDATE3
There is this command which in theory was to get an output showing that the PDFlib is running but it does not show anything when I do it on my prompt:
# php -i |grep PDF
PDFlib
PDFlib Support => enabled
PDFlib GmbH Binary-Version => 7.0.5p3
I could do this part to work was forgetting to add the extension = pdf.so
the file /etc/php5/cli/php.ini
. After I restarted the apache and he gave the expected output.
But still it does not appear the test.pdf
anywhere.
UPDATE4
try {
$p = new PDFlib();
/* open new PDF file; insert a file name to create the PDF on disk */
if ($p->begin_document("", "") == 0) {
die("Error: " . $p->get_errmsg());
}
$p->set_info("Creator", "hello.php");
$p->set_info("Author", "Rainer Schaaf");
$p->set_info("Title", "Hello world (PHP)!");
$p->begin_page_ext(595, 842, "");
$font = $p->load_font("Helvetica-Bold", "winansi", "");
$p->setfont($font, 24.0);
$p->set_text_pos(50, 700);
$p->show("Hello world!");
$p->continue_text("(says PHP)");
$p->end_page_ext("");
$p->end_document("");
$buf = $p->get_buffer();
$len = strlen($buf);
header("Content-type: application/pdf");
header("Content-Length: $len");
header("Content-Disposition: inline; filename=teste_do_katleia.pdf");
print $buf;
}
catch (PDFlibException $e) {
die("PDFlib exception occurred in hello sample:n" .
"[" . $e->get_errnum() . "] " . $e->get_apiname() . ": " .
$e->get_errmsg() . "n");
}
catch (Exception $e) {
die($e);
}
$p = 0;
$len = mb_strlen($buf, 'ASCII');
exit();
With the above code can generate a pdf and view it on the site, but that’s not what I want. What I want is to save it in a folder and then to recover on another page.
Does anyone know what I have to change this code to be able to do this?
you should check the comment in the line before the begin_document():
in addition you should check the the PDFlib 7 Tutorial, chapter 3.1.4 “Generating PDF Documents in Memory” for more details on this.
Hint: when creating files on disc, you can not use get_buffer(), which get the the PDF data from memory. (Please consult the API reference, which is also included in your PDFlib 7 package within the doc directory)