Files
liche/api/controllers/Pdfapi.php
T
2022-03-24 23:40:06 +08:00

53 lines
1.8 KiB
PHP

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
use mikehaertl\pdftk\Pdf;
class Pdfapi extends CI_Controller {
//pdf填充表单域接口 dev使用
public function fill_pdf()
{
$file_url = $this->input->post('file_url');
$fill_data = $this->input->post('fill_data');
if(!$file_url || !$fill_data){
die(json_encode(['code'=>0,'msg'=>'参数错误']));
}
$fill_data = json_decode($fill_data,true);
$url = base64_decode(urldecode($file_url));
$file_path = FCPATH.'tmp.pdf';
$arrContextOptions = [
"ssl" => [
"verify_peer"=>false,
"verify_peer_name"=>false,
],
];
$file = file_get_contents($file_url,false,stream_context_create($arrContextOptions));
file_put_contents($file_path, $file);
if(file_exists($file_path)){
$pdf = new Pdf($file_path);
$result = $pdf->fillForm($fill_data)->needAppearances()->saveAs('fill.pdf');
if ($result === false) {
die(json_encode(['code'=>0,'msg'=>$pdf->getError()]));
}else{
$data = [
'file_path' => http_host_com('api').'/fill.pdf',
];
@unlink($file_path);
die(json_encode(['code'=>1,'msg'=>'保存成功','data'=>$data]));
}
}else{
die(json_encode(['code'=>0,'msg'=>'保存文件失败']));
}
}
public function add_pdf(){
$o_id = $this->input->get('oid');
$this->load->library('receiver/orders_v2_entity');
if($o_id){
$res = $this->orders_v2_entity->create_pdf($o_id);
die(json_encode($res,JSON_UNESCAPED_UNICODE));
}
}
}