首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >PHP PDF函数错误

PHP PDF函数错误
EN

Stack Overflow用户
提问于 2011-06-07 23:03:46
回答 4查看 708关注 0票数 0

好了,这是它一直给我的关于pdf_add_bookmark函数的完整代码,而PHP的网站上没有关于这个函数的文档。

代码语言:javascript
运行
复制
<?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); 
?>

以下是返回的错误码

代码语言:javascript
运行
复制
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
EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2011-06-07 23:09:16

如果你想写PDF,最好的选择是TCPDF libray。看这里:http://www.tcpdf.org/

它正在积极开发中,有很多例子,效果很好。它还可以很好地将HTML转换为PDF (这有时很有用,而且比使用PDF单元格要少一些麻烦)

票数 1
EN

Stack Overflow用户

发布于 2011-06-07 23:05:59

我建议使用http://www.fpdf.org/。它不是在积极开发中,但它有很好的文档和支持/后续。

票数 1
EN

Stack Overflow用户

发布于 2011-06-07 23:09:12

PDF_add_bookmark,但已弃用,并显示请使用PDF_create_bookmark

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6267266

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档