Commit 151c5c54bf748425d1bc2daa7083c6b191f9fb7a
1 parent
c3fc8ebc6c
Exists in
master
fpdfdemo: Added link back to the first page from the 2nd page
Showing 1 changed file with 12 additions and 6 deletions Inline Diff
fpdfdemo
View file @
151c5c5
#!/usr/bin/env php | 1 | 1 | #!/usr/bin/env php | |
2 | 2 | |||
<?php | 3 | 3 | <?php | |
/** | 4 | 4 | /** | |
* FILENAME: | 5 | 5 | * FILENAME: | |
* fpdfdemo | 6 | 6 | * fpdfdemo | |
* | 7 | 7 | * | |
* DESCRIPTION: | 8 | 8 | * DESCRIPTION: | |
* Demonstration of the FPDF PHP Library for generating PDF files | 9 | 9 | * Demonstration of the FPDF PHP Library for generating PDF files | |
* | 10 | 10 | * | |
*/ | 11 | 11 | */ | |
12 | 12 | |||
/** | 13 | 13 | /** | |
* Links: | 14 | 14 | * Links: | |
* - https://packagist.org/packages/itbz/fpdf | 15 | 15 | * - https://packagist.org/packages/itbz/fpdf | |
* - http://www.fpdf.org/ | 16 | 16 | * - http://www.fpdf.org/ | |
* - http://www.fpdf.org/en/doc/index.php | 17 | 17 | * - http://www.fpdf.org/en/doc/index.php | |
* - http://www.fpdf.org/en/tutorial/index.php | 18 | 18 | * - http://www.fpdf.org/en/tutorial/index.php | |
* - http://www.fpdf.org/en/tutorial/tuto6.htm (Links and flowing text) | 19 | 19 | * - http://www.fpdf.org/en/tutorial/tuto6.htm (Links and flowing text) | |
* - http://www.fpdf.org/en/script/index.php | 20 | 20 | * - http://www.fpdf.org/en/script/index.php | |
* | 21 | 21 | * | |
* This script also requires FPDI to load PDF documents into memory | 22 | 22 | * This script also requires FPDI to load PDF documents into memory | |
* - https://www.setasign.com/products/fpdi/about/ | 23 | 23 | * - https://www.setasign.com/products/fpdi/about/ | |
* - https://www.setasign.com/products/fpdi/manual/#p-200 | 24 | 24 | * - https://www.setasign.com/products/fpdi/manual/#p-200 | |
* | 25 | 25 | * | |
* NOTE the line 'use fpdf\FPDF as FPDF;' needs to be added to the FPDI | 26 | 26 | * NOTE the line 'use fpdf\FPDF as FPDF;' needs to be added to the FPDI | |
* library, specifically in vendor/setasign/fpdi/fpdi_bridge.php, line 19, | 27 | 27 | * library, specifically in vendor/setasign/fpdi/fpdi_bridge.php, line 19, | |
* for FPDI to work | 28 | 28 | * for FPDI to work | |
*/ | 29 | 29 | */ | |
30 | 30 | |||
$loader = require __DIR__ . '/vendor/autoload.php'; | 31 | 31 | $loader = require __DIR__ . '/vendor/autoload.php'; | |
$loader->register(); | 32 | 32 | $loader->register(); | |
33 | 33 | |||
$pdf = new FPDI('p', 'mm', 'Letter'); | 34 | 34 | $pdf = new FPDI('p', 'mm', 'Letter'); | |
35 | 35 | |||
// write out the contents of the first page | 36 | 36 | // write out the contents of the first page | |
$pdf->AddPage(); | 37 | 37 | $pdf->AddPage(); | |
38 | $topLink = $pdf->AddLink(); | |||
39 | $pdf->SetLink($topLink); | |||
$pdf->SetFont('Arial', '', 20); | 38 | 40 | $pdf->SetFont('Arial', '', 20); | |
$pdf->Write(10, "This is some text on the first page; "); | 39 | |||
$pdf->SetFont('', 'U'); | 40 | 41 | $pdf->SetFont('', 'U'); | |
$firstPageLink = $pdf->AddLink(); | 41 | 42 | $ssfLink = $pdf->AddLink(); | |
$pdf->Write(10, "Click here to view the Site Summary Figure", $firstPageLink); | 42 | 43 | $pdf->Write(10, "Jump SSF for SHACK-10A", $ssfLink); | |
$pdf->SetFont(''); | 43 | 44 | $pdf->SetFont(''); | |
$pdf->Ln(); | 44 | 45 | $pdf->Ln(); | |
46 | $pdf->Write(10, "This is some text on the first page; "); | |||
47 | $pdf->Ln(); | |||
$pdf->Write(10, "Привет! Этот немного текста."); | 45 | 48 | $pdf->Write(10, "Привет! Этот немного текста."); | |
46 | 49 | |||
47 | ||||
// load up the Site Summary Figure to go on page #2 | 48 | 50 | // load up the Site Summary Figure to go on page #2 | |
$ssfPageCount = $pdf->setSourceFile(__DIR__ . '/site_summary_figure.pdf'); | 49 | 51 | $ssfPageCount = $pdf->setSourceFile(__DIR__ . '/site_summary_figure.pdf'); | |
50 | 52 | |||
print "Page count of site summary figure form is $ssfPageCount\n"; | 51 | 53 | print "Page count of site summary figure form is $ssfPageCount\n"; | |
52 | 54 | |||
// import the SSF page | 53 | 55 | // import the SSF page | |
$ssfTemplate= $pdf->importPage(1); | 54 | 56 | $ssfTemplate= $pdf->importPage(1); | |
print "Page size of site summary figure PDF is: "; | 55 | 57 | print "Page size of site summary figure PDF is: "; | |
$ssfSize = $pdf->getTemplateSize($ssfTemplate); | 56 | 58 | $ssfSize = $pdf->getTemplateSize($ssfTemplate); | |
print "{$ssfSize['w']} x {$ssfSize['h']}\n"; | 57 | 59 | print "{$ssfSize['w']} x {$ssfSize['h']}\n"; | |
58 | 60 | |||
// add the SSF file to the 2nd page | 59 | 61 | // add the SSF file to the 2nd page | |
$pdf->AddPage(); | 60 | 62 | $pdf->AddPage(); | |
$pdf->SetLink($firstPageLink); | 61 | 63 | $pdf->SetLink($ssfLink); | |
$pdf->useTemplate($ssfTemplate); | 62 | 64 | $pdf->useTemplate($ssfTemplate); | |
$pdf->SetFont('Helvetica'); | 63 | 65 | $pdf->SetFont('Helvetica'); | |
$pdf->SetXY(5,5); | 64 | 66 | $pdf->SetXY(5,5); | |
$pdf->Write(8, "This is some text on the Site Summary Figure"); | 65 | 67 | $pdf->SetFont('', 'U'); | |
68 | $pdf->Write(8, "Top", $topLink); | |||
69 | $pdf->SetFont(''); |