上海优翰信息科技有限公司自研Html网址Url在线生成Pdf文件第三方Api接口,提供appid和密钥调用接口或者独立本地化部署都可以,支持个性化的设置pdf大小以及头部尾部等,附上一段调用demo示例,如需要测试和试用请联系本公司开通账号
/**
* 生成PDF接口
*/
public function index(Request $request): Response
{
// ///PDF查詢接口 /app/pdfapi/api/queryPdf
// $serviceCode = "EXP_RECE_SEARCH_PDF";
// $params = [
// 'uniqueID' => 'b845a700-3d17-fd31-be1a-03a596bd36d1'
// ];
///生成PDF接口 /app/pdfapi/api/createPdf
$serviceCode = "EXP_RECE_CREAT_PDF";
$params = [
'url' => 'https://www.shyohan.com', //需要生成PDF文件的页面url地址
'configure' => [
'scale' => 1, //(string)页面渲染的缩放。默认是1。缩放值必须介于0.1到2之间。
'displayHeaderFooter' => false, //(boolean)显示页眉页脚 默认不显示 false
'headerTemplate' => '<div style="width:calc(100% - 28px);margin-bottom: -20px; font-size:8px; padding:15px 14px;display: flex; justify-content: space-between; "><span style="font-size: 10px;"><label class="title"></label><label class="url"></label></span><span style="font-size: 10px;" class="date"></span><span style="font-size: 10px;"><label class="pageNumber"></label>/<label class="totalPages"></label></span></div>', //(string)页眉的html模板,可以有这些变量:date 格式化的日期 title 网页标题 url 网页地址 pageNumber 当前页码 totalPages 总页数
'footerTemplate' => '<div style="width:calc(100% - 28px);margin-bottom: -20px; font-size:8px; padding:15px 14px;display: flex; justify-content: space-between; "><span style="font-size: 10px;"><label class="title"></label><label class="url"></label></span><span style="font-size: 10px;"></span><span style="font-size: 10px;"><label class="pageNumber"></label>/<label class="totalPages"></label></span></div>', //(string)页脚的html模板。和页眉模板变量相同。
'printBackground' => false, //(boolean)是否打印背景图 默认是 false
'landscape' => false, //(boolean)页面横向(?Paper orientation). 默认为 false.
'pageRanges' => '', //(string)要输出的页码范围, 比如, '1-5, 8, 11-13'。默认是空字符串,表示全部页码。
'format' => 'A4', //(string)页面格式。如果设置了,将覆盖 width 和 height 配置. 默认是 'Letter'。 纸张大小 A0-A6 Letter Legal Tabloid Ledger
'width' => '', //(string)页面宽度, 接受带单位的字符串。
'height' => '', //(string)页面高度, 接受带单位的字符串。
'margin' => ['top'=>'20mm','bottom'=>'20mm','left'=>'','right'=>''], //(array)页面空白白边配置,默认是空
'preferCSSPageSize' => false //(boolean)给页面优先级声明的任何CSS @page 大小超过 width 和 height 或 format 选项中声明的大小。 默认为 false,它将缩放内容以适合纸张大小。
],
];
//参数验签
$requestID = getuuid();
$timestamp = time();
$msgData = json_encode($params);
// 通过MD5和BASE64生成数字签名
$msgDigest = base64_encode(md5((urlencode($msgData . $timestamp . self::$checkword)), TRUE));
// 发送参数
$postData = array(
'clientID' => self::$clientID,
'requestID' => $requestID,
'serviceCode' => $serviceCode,
'timestamp' => $timestamp,
'msgDigest' => $msgDigest,
'msgData' => $msgData
);
print_r($postData);
return json($postData);
// $resultCont = $this->sendPost(self::$CALL_URL_PROD.'/app/pdfapi/api/createPdf', $postData);
// $data = json_decode($resultCont, true);
// return json($data);
}