gpt4 book ai didi

php - 如何使用 pdfcrowd HTML to PDF API for PHP 设置背景水印图像?

转载 作者:行者123 更新时间:2023-11-28 03:27:45 24 4
gpt4 key购买 nike

我正在使用“pdfcrowd HTML to PDF API for PHP”从 PHP 和 smarty 文件生成 PDF 文件。我能够生成 PDF,但无法将背景水印图像添​​加到我正在打印的 PDF 中。我什么都试过了,还是放不上背景水印。任何人都可以就此指导我吗?我哪里错了?任何形式的帮助将不胜感激。以下是我的代码供您引用:

<?php
set_time_limit(0);

require_once("../../includes/application-header.php");
require_once OCN_ROOT."/core/extention/pdfcrowd/pdfcrowd_config.php";
require_once OCN_ROOT."/core/extention/pdfcrowd/pdfcrowd.php";

try
{
// create an API client instance
$client = new Pdfcrowd($username, $apikey);
$objPracticeSheet = new PracticeSheet();
$practice_sheet_id = $_GET['practice_sheet_id'];

$bread_crumbs_text = 'View Practice Sheet';

$practice_details = $objPracticeSheet->ViewPracticeSheet($practice_sheet_id);

$practice_sheet_details = $objPracticeSheet->GetPracticeSheetDetailsById($practice_sheet_id);

$smarty->assign('bread_crumbs_text', $bread_crumbs_text);
$smarty->assign('practice_sheet_name', $practice_sheet_details['practice_sheet_name']);
$smarty->assign("practice_details", $practice_details);
$smarty->assign("practice_sheet_questions", $practice_sheet_details['practice_sheet_total_questions']);
$smarty->assign("practice_sheet_display_date", $practice_sheet_details['practice_sheet_display_date']);
$smarty->assign("practice_sheet_for", $practice_sheet_details['practice_sheet_for']);

$file_to_show = "pdf-practice-sheet.tpl";

$final_data = $smarty->fetch($file_to_show);

$file = fopen(ADMIN_ROOT."temp/pdf_practice_sheet.html", "w+");
file_put_contents($file, "");

fwrite($file, $final_data);
fclose($file);
$client->setHeaderHtml($header_html);
$client->setFooterHtml("<table border='0' width='100%' cellpadding='5' cellspacing='0' style='font-size:10px;font-family:verdana;background:#EFBC8F;margin-top:10px;'><tr><td align='left'>Powered by EntrancePrime.com :
India's Favourite Online Test Series for JEE, NEET, & CA-CPT</td><td align='right'>Page %p/%n</td></tr></table>");
$client->setPageWidth("210mm");
$client->setPageHeight("298mm");
$client->setNoCopy('True');
//$client->setVerticalMargin("0.8in");
$client->setPageMargins("1.1in","0.2in","0.4in","0.2in");

//Set watermark
$client->setWatermarkInBackground(True);
$client->setWatermark("'".ADMIN_SITE_URL."assets/img/watermark.png'", -28, 406);

$pdf = $client->convertFile(ADMIN_ROOT."temp/pdf_practice_sheet.html");
$filename = $practice_sheet_details['practice_sheet_name'];
// set HTTP response headers
header("Content-Type: application/pdf");
header("Cache-Control: no-cache");
header("Accept-Ranges: none");
header("Content-Disposition: attachment; filename=\"" . $filename . ".pdf\"");
// send the generated PDF
echo $pdf;
}
catch(PdfcrowdException $why)
{
echo "Pdfcrowd Error: " . $why;
}
?>

期待回复。

最佳答案

尝试在此 $client->setWatermark("'".ADMIN_SITE_URL."assets/img/watermark.png'", -28, 406); 中使用绝对 URL( http://www.yoursite.com/image.png );

看看你得到了什么。对我来说,这看起来像是一个路径问题。祝你好运。

关于php - 如何使用 pdfcrowd HTML to PDF API for PHP 设置背景水印图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20073078/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com