캔버스에서 이미지를 캡처하여 아약스 게시 메서드를 통해 내 PHP 파일로 보냈습니다.PHP dataURL to png 이미지
여기 파일 유형과 확장명을 가진 png에 다시 넣어야합니다. fpdf를 사용하여이 새로운 이미지를 pdf에 추가 할 예정입니다.
여기 내 코드입니다. 나는 방금 깨진 이미지 링크 아이콘이 남았습니다.
<?php
require_once('fpdf/fpdf.php');
require_once('fpdi/fpdi.php');
$imgEmbed = $_POST['embed'];
//convert base64 string into an image file by wrapping
//it in the png container
$parts = explode(',',$imgEmbed);
$data = $parts[1];
$data = base64_decode($data);
header('Content-Type:image/png');
$pdf =& new FPDI();
$pdf->AddPage();
//Set the source PDF file
$pdf->setSourceFile("test2.pdf");
//Import the first page of the file
$tppl = $pdf->importPage(1);
//Use this page as template
// use the imported page and place it at point 20,30 with a width of 170 mm
$pdf->useTemplate($tppl, null, null, 215.9, 279.4, TRUE);
//Select Arial italic 8
$pdf->SetFont('Helvetica');
$pdf->SetTextColor(0,0,0);
$pdf->SetXY(100, 100);
$pdf->Write(0, 'This is just a simple text');
$pdf->Image($newIm,null,null,150,100);// x y h w 'png'
$pdf->Output("custom.pdf", "I"); // d send to browser, F send to local
// I auto open in browser window.
?>
'explode (',', $ imgEmbed);'는 ('. ', $ imgEmbed)'explode'이어야합니다. '출력 '은 이미지로 렌더링합니까? 나는 의심한다. –
출력은 FPDF 일입니다. 'header ('Content-Type : image/png ');를'header ('Content-Type : application/pdf '); 그것은 이미지를 만드는 데 아무런 영향을 미치지 않습니다. 나는 fpdf가 png 이미지로 헤더를 인식 할 필요가있다. 안타깝게도 귀하의 제안에 따라 코드가 더 복잡해집니다. ... ( – user61026
PNG를 서버에 임시 위치로 저장 한 다음 PDF에 기록 할 수 있습니까? –