Commit 840f46a6049c1d3397f72daf4b0090b371385d9e

Authored by Brian Manning
1 parent fdcecf240a
Exists in master

tcpdf_demo: script generates a valid PDF output file (with header lines)

Showing 1 changed file with 17 additions and 10 deletions Inline Diff

#!/usr/bin/env php 1 1 #!/usr/bin/env php
2 2
<?php 3 3 <?php
/** 4 4 /**
* FILENAME: 5 5 * FILENAME:
* tfpdf_demo 6 6 * tfpdf_demo
* 7 7 *
* DESCRIPTION: 8 8 * DESCRIPTION:
* Demonstration of the tFPDF PHP Library for generating PDF files 9 9 * Demonstration of the tFPDF PHP Library for generating PDF files
* 10 10 *
*/ 11 11 */
12 12
/** 13 13 /**
Links: 14 14 Links:
- https://packagist.org/packages/rev42/tfpdf 15 15 - https://packagist.org/packages/rev42/tfpdf
- https://packagist.org/packages/setasign/fpdi 16 16 - https://packagist.org/packages/setasign/fpdi
- http://www.fpdf.org/ 17 17 - http://www.fpdf.org/
- http://www.fpdf.org/en/doc/index.php 18 18 - http://www.fpdf.org/en/doc/index.php
- http://www.fpdf.org/en/tutorial/index.php 19 19 - http://www.fpdf.org/en/tutorial/index.php
- http://www.fpdf.org/en/tutorial/tuto6.htm (Links and flowing text) 20 20 - http://www.fpdf.org/en/tutorial/tuto6.htm (Links and flowing text)
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 tFPDF as FPDF;' needs to be added to the FPDI 26 26 NOTE the line 'use tFPDF 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 // set a default timezone
35 date_default_timezone_set("America/Los_Angeles");
35 36
37 //require_once('tcpdf_include.php');
38 //$pdf = new TCPDF('p', 'mm', 'Letter', TRUE, 'UTF-8');
39 class_exists('TCPDF', true);
40 $pdf = new FPDI('p', 'mm', 'Letter', TRUE, 'UTF-8');
41
// write out the contents of the first page 36 42 // write out the contents of the first page
$pdf->AddPage(); 37 43 $pdf->AddPage();
$topLink = $pdf->AddLink(); 38 44 $topLink = $pdf->AddLink();
$pdf->SetLink($topLink); 39 45 $pdf->SetLink($topLink);
$pdf->AddFont('DejaVu','','DejaVuSansCondensed.ttf',true); 40 46 //$pdf->AddFont('DejaVu','','DejaVuSansCondensed.ttf',true);
$pdf->SetFont('DejaVu', '', 20); 41 47 $pdf->AddFont('dejavusanscondensed','','dejavusanscondensed.php',true);
48 //$pdf->SetFont('DejaVu', '', 20);
49 $pdf->SetFont('dejavusanscondensed', '', 20);
$pdf->SetFont('', 'U'); 42 50 $pdf->SetFont('', 'U');
$ssfLink = $pdf->AddLink(); 43 51 $ssfLink = $pdf->AddLink();
$pdf->Write(10, "Jump SSF for SHACK-10A", $ssfLink); 44 52 $pdf->Write(10, "Jump to SSF for SHACK-10A", $ssfLink);
$pdf->SetFont(''); 45 53 $pdf->SetFont('');
$pdf->Ln(); 46 54 $pdf->Ln();
$pdf->Write(10, "This is some text on the first page; "); 47 55 $pdf->Write(10, "This is some text on the first page; ");
$pdf->Ln(); 48 56 $pdf->Ln();
$pdf->Write(10, "Привет! Этот немного текста."); 49 57 $pdf->Write(10, "Привет! Этот немного текста.");
50 58
// load up the Site Summary Figure to go on page #2 51 59 // load up the Site Summary Figure to go on page #2
$ssfPageCount = $pdf->setSourceFile(__DIR__ . '/site_summary_figure.pdf'); 52 60 $ssfPageCount = $pdf->setSourceFile(__DIR__ . '/site_summary_figure.pdf');
61 //print "Page count of site summary figure form is $ssfPageCount\n";
53 62
print "Page count of site summary figure form is $ssfPageCount\n"; 54
55
// import the SSF page 56 63 // import the SSF page
$ssfTemplate= $pdf->importPage(1); 57 64 $ssfTemplate= $pdf->importPage(1);
print "Page size of site summary figure PDF is: "; 58 65 //print "Page size of site summary figure PDF is: ";
$ssfSize = $pdf->getTemplateSize($ssfTemplate); 59 66 //$ssfSize = $pdf->getTemplateSize($ssfTemplate);
print "{$ssfSize['w']} x {$ssfSize['h']}\n"; 60 67 //print "{$ssfSize['w']}mm x {$ssfSize['h']}mm\n";
61 68
// add the SSF file to the 2nd page 62 69 // add the SSF file to the 2nd page
$pdf->AddPage(); 63 70 $pdf->AddPage();
$pdf->SetLink($ssfLink); 64 71 $pdf->SetLink($ssfLink);
$pdf->useTemplate($ssfTemplate); 65 72 $pdf->useTemplate($ssfTemplate);
$pdf->SetFont('Helvetica'); 66 73 $pdf->SetFont('Helvetica');
$pdf->SetXY(5,5); 67 74 $pdf->SetXY(5,5);
$pdf->SetFont('', 'U'); 68 75 $pdf->SetFont('', 'U');
$pdf->Write(8, "Top", $topLink); 69 76 $pdf->Write(8, "Top", $topLink);
$pdf->SetFont(''); 70 77 $pdf->SetFont('');
$pdf->SetXY(40, 5); 71 78 $pdf->SetXY(40, 5);
$pdf->Write(8, " SSF: P771/SHACK-10A"); 72 79 $pdf->Write(8, " SSF: P771/SHACK-10A");
73 80