-
-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #217 from Setasign/development
Fixed handling of imported pages in templates with another unit than "pt"
- Loading branch information
Showing
16 changed files
with
267 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
use setasign\Fpdi\Fpdi; | ||
|
||
require_once '../vendor/autoload.php'; | ||
|
||
$pdf = new Fpdi('P', 'mm'); | ||
$pdf->setSourceFile(__DIR__ . '/../tests/_files/pdfs/Boombastic-Box.pdf'); | ||
$pageId = $pdf->importPage(1); | ||
|
||
$pdf->beginTemplate(); | ||
$size = $pdf->useImportedPage($pageId, 10, 10, 100); | ||
$pdf->SetDrawColor(0, 255, 0); | ||
$pdf->Rect(10, 10, $size['width'], $size['height']); | ||
$tplId = $pdf->endTemplate(); | ||
|
||
$pdf->AddPage(); | ||
$x = 10; | ||
$y = 20; | ||
$width = 190; | ||
|
||
$size = $pdf->useTemplate($tplId, $x, $y, $width); | ||
|
||
$pdf->SetDrawColor(255, 0, 0); | ||
$pdf->Rect($x, $y, $size['width'], $size['height']); | ||
|
||
$pdf->Output('F', 'page-in-template.pdf'); | ||
|
||
?> | ||
<iframe src="http://pdfanalyzer2.dev1.setasign.local/plugin?file=<?php echo urlencode(realpath('page-in-template.pdf')); ?>" width="100%" height="98%"></iframe> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
<?php | ||
|
||
namespace setasign\Fpdi\visual; | ||
|
||
use setasign\Fpdi\Fpdi; | ||
|
||
class FpdiTest extends VisualTestCase | ||
{ | ||
/** | ||
* Should return __FILE__ | ||
* | ||
* @return string | ||
*/ | ||
public function getClassFile() | ||
{ | ||
return __FILE__; | ||
} | ||
|
||
public function getInstance($unit = 'pt') | ||
{ | ||
return new Fpdi('P', $unit); | ||
} | ||
|
||
public function createProvider() | ||
{ | ||
return [ | ||
[ | ||
[ | ||
'_method' => 'importedPageInTemplatePt1', | ||
'tmpPath' => 'importedPageInTemplatePt1', | ||
], | ||
0.1, | ||
72 // dpi | ||
], | ||
[ | ||
[ | ||
'_method' => 'importedPageInTemplateMm1', | ||
'tmpPath' => 'importedPageInTemplateMm1', | ||
], | ||
0.1, | ||
72 // dpi | ||
], | ||
[ | ||
[ | ||
'_method' => 'importedPageInTemplatePt2', | ||
'tmpPath' => 'importedPageInTemplatePt2', | ||
], | ||
0.1, | ||
72 // dpi | ||
], | ||
[ | ||
[ | ||
'_method' => 'importedPageInTemplateMm2', | ||
'tmpPath' => 'importedPageInTemplateMm2', | ||
], | ||
0.1, | ||
72 // dpi | ||
], | ||
]; | ||
} | ||
|
||
public function importedPageInTemplatePt1($inputData, $outputFile) | ||
{ | ||
$pdf = $this->getInstance(); | ||
|
||
$pdf->setSourceFile(__DIR__ . '/../_files/pdfs/Boombastic-Box.pdf'); | ||
$pageIdx = $pdf->importPage(1); | ||
|
||
// page looks identically | ||
$pdf->AddPage(); | ||
$pdf->beginTemplate(); | ||
$size = $pdf->useTemplate($pageIdx); | ||
$pdf->SetDrawColor(255, 0, 255); | ||
$pdf->Rect(0, 0, $size['width'], $size['height']); | ||
$tplIdx = $pdf->endTemplate(); | ||
$pdf->useTemplate($tplIdx); | ||
|
||
// draw template with an offset and different size | ||
$pdf->AddPage(); | ||
$size = $pdf->useTemplate($tplIdx, 10, 50, 250); | ||
$pdf->SetDrawColor(0, 255, 0); | ||
$pdf->Rect(10, 50, $size['width'], $size['height']); | ||
|
||
$pdf->Output('F', $outputFile); | ||
} | ||
|
||
public function importedPageInTemplateMm1($inputData, $outputFile) | ||
{ | ||
$pdf = $this->getInstance('mm'); | ||
|
||
$pdf->setSourceFile(__DIR__ . '/../_files/pdfs/Boombastic-Box.pdf'); | ||
$pageIdx = $pdf->importPage(1); | ||
|
||
// page looks identically | ||
$pdf->AddPage(); | ||
$pdf->beginTemplate(); | ||
$size = $pdf->useTemplate($pageIdx); | ||
$pdf->SetDrawColor(255, 0, 255); | ||
$pdf->Rect(0, 0, $size['width'], $size['height']); | ||
$tplIdx = $pdf->endTemplate(); | ||
$pdf->useTemplate($tplIdx); | ||
|
||
// draw template with an offset and different size | ||
$pdf->AddPage(); | ||
$size = $pdf->useTemplate($tplIdx, 10, 20, 100); | ||
$pdf->SetDrawColor(0, 255, 0); | ||
$pdf->Rect(10, 20, $size['width'], $size['height']); | ||
|
||
$pdf->Output('F', $outputFile); | ||
} | ||
|
||
public function importedPageInTemplatePt2($inputData, $outputFile) | ||
{ | ||
$pdf = $this->getInstance(); | ||
|
||
$pdf->setSourceFile(__DIR__ . '/../_files/pdfs/Boombastic-Box.pdf'); | ||
$pageIdx = $pdf->importPage(1); | ||
|
||
// draw the page onto another templage | ||
$pdf->AddPage(); | ||
$pdf->beginTemplate(100, 200); | ||
$pdf->SetDrawColor(255, 0, 0); | ||
$pdf->Rect(0, 0, 100, 200); | ||
$size = $pdf->useTemplate($pageIdx, 10, 10, 80, 180); | ||
$pdf->SetDrawColor(0, 0, 255); | ||
$pdf->Rect(10, 10, $size['width'], $size['height']); | ||
$tplIdx = $pdf->endTemplate(); | ||
$pdf->useTemplate($tplIdx, 10, 10); | ||
|
||
// create an additional template and draw the previous template onto this | ||
$pdf->AddPage(); | ||
$pdf->beginTemplate(150, 200); | ||
$pdf->SetDrawColor(255, 0, 0); | ||
$pdf->Rect(0, 0, 150, 200); | ||
$size = $pdf->useTemplate($tplIdx, 10, 10, null, 180); | ||
$pdf->SetDrawColor(0, 255, 0); | ||
$pdf->Rect(10, 10, $size['width'], 180); | ||
$tplIdx2 = $pdf->endTemplate(); | ||
$pdf->useTemplate($tplIdx2, 30, 100); | ||
|
||
$pdf->Output('F', $outputFile); | ||
} | ||
|
||
public function importedPageInTemplateMm2($inputData, $outputFile) | ||
{ | ||
$pdf = $this->getInstance('mm'); | ||
|
||
$pdf->setSourceFile(__DIR__ . '/../_files/pdfs/Boombastic-Box.pdf'); | ||
$pageIdx = $pdf->importPage(1); | ||
|
||
// draw the page onto another templage | ||
$pdf->AddPage(); | ||
$pdf->beginTemplate(100, 200); | ||
$pdf->SetDrawColor(255, 0, 0); | ||
$pdf->Rect(0, 0, 100, 200); | ||
$size = $pdf->useTemplate($pageIdx, 10, 10, 80, 180); | ||
$pdf->SetDrawColor(0, 0, 255); | ||
$pdf->Rect(10, 10, $size['width'], $size['height']); | ||
$tplIdx = $pdf->endTemplate(); | ||
$pdf->useTemplate($tplIdx, 10, 10); | ||
|
||
// create an additional template and draw the previous template onto this | ||
$pdf->AddPage(); | ||
$pdf->beginTemplate(100, 150); | ||
$pdf->SetDrawColor(255, 0, 0); | ||
$pdf->Rect(0, 0, 100, 150); | ||
$size = $pdf->useTemplate($tplIdx, 10, 10, null, 130); | ||
$pdf->SetDrawColor(0, 255, 0); | ||
$pdf->Rect(10, 10, $size['width'], 130); | ||
$tplIdx2 = $pdf->endTemplate(); | ||
$pdf->useTemplate($tplIdx2, 10, 30); | ||
|
||
$pdf->Output('F', $outputFile); | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+1.65 KB
tests/visual/Tfpdf/FpdfTplTest/templateInTemplateMm/original/result.pdf
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace Tfpdf; | ||
|
||
use setasign\Fpdi\Tfpdf\Fpdi; | ||
|
||
class FpdiTest extends \setasign\Fpdi\visual\FpdiTest | ||
{ | ||
/** | ||
* Should return __FILE__ | ||
* | ||
* @return string | ||
*/ | ||
public function getClassFile() | ||
{ | ||
return __FILE__; | ||
} | ||
|
||
public function getInstance($unit = 'pt') | ||
{ | ||
return new Fpdi('P', $unit); | ||
} | ||
} |
Binary file added
BIN
+105 KB
tests/visual/Tfpdf/FpdiTest/importedPageInTemplateMm1/original/result.pdf
Binary file not shown.
Binary file added
BIN
+105 KB
tests/visual/Tfpdf/FpdiTest/importedPageInTemplateMm2/original/result.pdf
Binary file not shown.
Binary file added
BIN
+105 KB
tests/visual/Tfpdf/FpdiTest/importedPageInTemplatePt1/original/result.pdf
Binary file not shown.
Binary file added
BIN
+105 KB
tests/visual/Tfpdf/FpdiTest/importedPageInTemplatePt2/original/result.pdf
Binary file not shown.