Forum Moderators: coopster
<?php
$pdf = PDF_new();
pdf_open_file($pdf, "/hsphere/local/home/cefalu/example.com/pdfs/hello.pdf");
/* open new PDF file; insert a file name to create the PDF on disk */
if (PDF_begin_document($pdf, "", "") == 0) {
die("Error: " . PDF_get_errmsg($pdf));
}
pdf_set_info($pdf, "Creator", "hello.php");
pdf_set_info($pdf, "Author", "Rainer Schaaf");
pdf_set_info($pdf, "Title", "Hello world (PHP)!");
pdf_begin_page($pdf, 595, 842, "");
$font = PDF_load_font($pdf, "Helvetica-Bold", "winansi", "");
PDF_setfont($pdf, $font, 24.0);
PDF_set_text_pos($pdf, 50, 700);
PDF_show($pdf, "Hello world!");
PDF_continue_text($pdf, "(says PHP)");
pdf_end_page($pdf);
pdf_close($pdf);
pdf_delete($pdf);
$len = filesize("/hsphere/local/home/cefalu/example.com/pdfs/hello.pdf");
header("Content-type: application/pdf");
header("Content-Length: $len");
header("Content-Disposition: inline; filename=hello.pdf");
readfile("/hsphere/local/home/cefalu/example.com/pdfs/hello.pdf");
?>
[edited by: jatar_k at 2:02 pm (utc) on Jan. 6, 2008]
[edit reason] please use example.com [/edit]
To get the content length of the PDF file in memory, I believe you use a combination of PDF_get_buffer and strlen on that buffer. I'm not 100% sure though, it's just something I read somewhere.