2011-03-09 56 views

回答

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);