Jump to content

Problem with using php to create PDF file


vuthcam

Recommended Posts

I have some problems with using php to create PDF file. I have tested my php and making PDF already enabled. But when testing the code below, it always takes me to Page not found.

<?php

try {
    $p = new PDFlib();

    $p->begin_document(NULL,NULL);
    $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: attachment; filename=hello.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;
?> 

I wonder what the reason is??

Thanks in advance for your help.

I personally find the FPDF class (http://www.fpdf.com/) to be much more user friendly then PDFLib.  That's just me though.  The class is about 40k, plus font files.  Not sure the size of PDFLib, but it's certainly a lot easier to create a file using FPDF.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.