我有一个PDF文件广告我想在文档中添加一个图像,所以我在PDF库中找到了一个函数PDF_add_thumbnail
所以有没有给我一个如何通过一个例子使用该函数的例子?
答案 0 :(得分:1)
要添加缩略图,首先需要创建页面的缩略图。假设您有图像(如果您不知道如何为给定的PDF页面创建缩略图,这可能是另一个问题)您可以将图像添加为缩略图。结帐以下代码。
//getting new instance
$pdfFile = new_pdf();
PDF_open_file($pdfFile, " ");
//document info
pdf_set_info($pdfFile, "Auther", "Auther Name");
pdf_set_info($pdfFile, "Title", "My PDF Title");
pdf_set_info($pdfFile, "Subject", "PAGE THUMBNAIL");
//starting our page and define the width and highet of the document
pdf_begin_page($pdfFile, 595, 842);
//start writing from the point 50,780
PDF_show_xy($pdfFile, "Thumbnail will be added for this page.", 50, 780);
//load image file
$image = PDF_load_image($pdfFile,"jpg","pagethumb.jpg","");
//add image as thumbnail - this will be thumbnail for this page
PDF_add_thumbnail ( $pdfFile , $image );
PDF_end_page($pdfFile);
PDF_close($pdfFile);
//store the pdf document in $pdf
$pdf = PDF_get_buffer($pdfFile);
//get the len to tell the browser about it
$pdflen = strlen($pdfFile);
//telling the browser about the pdf document
header("Content-type: application/pdf");
header("Content-length: $pdflen");
header("Content-Disposition: inline; filename=pagethumb.pdf");
//output the document
print($pdf);
//delete the object
PDF_delete($pdfFile);