2011-06-07 94 views
0

好了,所以這裏是完整的代碼它不斷給我約pdf_add_bookmark功能廢話,而PHP的網站有這個功能沒有文檔更多PHP PDF功能錯誤

<?php 

    // Declare PDF File 

    $pdf = pdf_new(); 
    PDF_open_file($pdf, "1.pdf"); 

    // Set Document Properties 

    PDF_set_info($pdf, "author", "BT"); 
    PDF_set_info($pdf, "title", "Whats a title?"); 
    PDF_set_info($pdf, "creator", "BT"); 
    PDF_set_info($pdf, "subject", "Whats a subject?"); 

    // Get fonts to use 

    pdf_set_parameter($pdf, "FontOutline", "Arial=C:\Windows\Fonts\arial.ttf"); // get a custom font 
    $font1 = PDF_findfont($pdf, "Helvetica-Bold", "winansi", 0); // declare default font 
    $font2 = PDF_findfont($pdf, "Arial", "winansi", 1); // declare custom font & embed into file 

    /* 
    You can use the following Fontypes 14 safely (the default fonts) 
    Courier, Courier-Bold, Courier-Oblique, Courier-BoldOblique 
    Helvetica, Helvetica-Bold, Helvetica-Oblique, Helvetica-BoldOblique 
    Times-Roman, Times-Bold, Times-Italic, Times-BoldItalic 
    Symbol, ZapfDingbats 
    */ 

    // make the images 

    $image1 = PDF_open_image_file($pdf, "jpeg", "424698.jpg","page",$page); //supported filetypes are: jpeg, tiff, gif, png. 

    //Make First Page 

    PDF_begin_page($pdf, 450, 450); // page width and height. 
    $bookmark = PDF_add_bookmark($pdf, "Front"); // add a top level bookmark. 
    PDF_setfont($pdf, $font1, 12); // use this font from now on. 
    PDF_show_xy($pdf, "First Page!", 5, 225); // show this text measured from the left top. 
    pdf_place_image($pdf, $image1, 255, 5, 1); // last number will schale it. 
    PDF_end_page($pdf); // End of Page. 

    //Make Second Page 

    PDF_begin_page($pdf, 450, 225); // page width and height. 
    $bookmark1 = PDF_add_bookmark($pdf, "Chapter1", $bookmark); // add a nested bookmark. (can be nested multiple times.) 
    PDF_setfont($pdf, $font2, 12); // use this font from now on. 
    PDF_show_xy($pdf, "Chapter1!", 225, 5); 
    PDF_add_bookmark($pdf, "Chapter1.1", $bookmark1); // add a nested bookmark (already in a nested one). 
    PDF_setfont($pdf, $font1, 12); 
    PDF_show_xy($pdf, "Chapter1.1", 225, 5); 
    PDF_end_page($pdf); 

    // Finish the PDF File 

    PDF_close($pdf); // End Of PDF-File. 
    $output = PDF_get_buffer($pdf); // assemble the file in a variable. 

    // Output Area 

    header("Content-type: application/pdf"); //set filetype to pdf. 
    header("Content-Length: ".strlen($output)); //content length 
    header("Content-Disposition: attachment; filename=test.pdf"); // you can use inline or attachment. 
    echo $output; // actual print area! 

    // Cleanup 

    PDF_delete($pdf); 
?> 

這裏是返回錯誤代碼

Fatal error: Uncaught exception 'PDFlibException' with message 'pdf_add_bookmark() expects exactly 4 parameters, 2 given' in D:\wamp\www\PDF\pdf.php:36 Stack trace: #0 D:\wamp\www\PDF\pdf.php(36): pdf_add_bookmark(Resource id #2, 'Front') #1 {main} thrown in D:\wamp\www\PDF\pdf.php on line 36 

回答

1

最好的選擇,如果你想要寫PDF是TCPDF libray。看這裏:http://www.tcpdf.org/

它正在積極發展中,有很多例子和很好的作品。它也非常適用於轉換HTML到PDF(其有時比使用PDF細胞是有用的和更小的麻煩)

+0

謝謝我會考慮是否正在研究fpdf一個 – 2011-06-07 15:12:28

+0

它也可以用於HTML到PDF的轉換。在我看來,創建PDF的任何其他庫都好得多(比Zend_Framework 1.11好幾百倍於Zend_Pdf) – 2011-06-07 15:29:04

1

我會推薦使用http://www.fpdf.org/來代替。它沒有積極的發展,但它有很好的文檔和支持/關注。

+0

謝謝,但我會嘗試這一個或TCPDF然後看看哪一個更好 – 2011-06-07 15:12:58

0
int pdf_add_bookmark (resource pdfdoc, string text, int parent, int open) 

添加下父嵌套書籤或一個新的頂層書籤如果父= 0 。返回一個書籤描述符,可用作後續嵌套書籤的父代。如果打開= 1,則子書籤將摺疊出來,並且如果打開= 0則不可見。參數parent和open在PHP 4.3.5或PDFlib小於5之前是可選的。