Commit f9af74f4818905442ff2fcfa32de4a7974faa7d9

Authored by Brian Manning
1 parent c3e38f7906
Exists in master

tcpdf_demo: added document properties, and added TCPDF-specific links

Showing 1 changed file with 10 additions and 4 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
17 - http://www.tcpdf.org/doc/code/classTCPDF-members.html
18 - http://www.tcpdf.org/examples.php
- http://www.fpdf.org/ 17 19 - http://www.fpdf.org/
- http://www.fpdf.org/en/doc/index.php 18 20 - http://www.fpdf.org/en/doc/index.php
- http://www.fpdf.org/en/tutorial/index.php 19 21 - http://www.fpdf.org/en/tutorial/index.php
- http://www.fpdf.org/en/tutorial/tuto6.htm (Links and flowing text) 20 22 - http://www.fpdf.org/en/tutorial/tuto6.htm (Links and flowing text)
- http://www.tcpdf.org/doc/code/classTCPDF-members.html 21
22 23
This script also requires FPDI to load PDF documents into memory 23 24 This script also requires FPDI to load PDF documents into memory
- https://www.setasign.com/products/fpdi/about/ 24 25 - https://www.setasign.com/products/fpdi/about/
- https://www.setasign.com/products/fpdi/manual/#p-200 25 26 - https://www.setasign.com/products/fpdi/manual/#p-200
26 27
NOTE the line 'use tFPDF as FPDF;' needs to be added to the FPDI 27
library, specifically in vendor/setasign/fpdi/fpdi_bridge.php, line 19, 28
for FPDI to work 29
*/ 30 28 */
31 29
$loader = require __DIR__ . '/vendor/autoload.php'; 32 30 $loader = require __DIR__ . '/vendor/autoload.php';
$loader->register(); 33 31 $loader->register();
34 32
// set a default timezone 35 33 // set a default timezone
date_default_timezone_set("America/Los_Angeles"); 36 34 date_default_timezone_set("America/Los_Angeles");
37 35
//require_once('tcpdf_include.php'); 38 36 //require_once('tcpdf_include.php');
//$pdf = new TCPDF('p', 'mm', 'Letter', TRUE, 'UTF-8'); 39 37 //$pdf = new TCPDF('p', 'mm', 'Letter', TRUE, 'UTF-8');
class_exists('TCPDF', true); 40 38 class_exists('TCPDF', true);
$pdf = new FPDI('p', 'mm', 'Letter', TRUE, 'UTF-8'); 41 39 $pdf = new FPDI('p', 'mm', 'Letter', TRUE, 'UTF-8');
40
41 // Set up document properties
42 $pdf->SetCreator('IODP Science Support Office');
43 $pdf->SetAuthor('IODP Science Support Office');
44 $pdf->SetTitle('Demo of TCPDF for generating IODP Proposals');
45 $pdf->SetSubject('IODP Proposals');
46 $pdf->SetKeywords('IODP proposal ocean drilling core expedition');
47
// disable headers and footers on all pages 42 48 // disable headers and footers on all pages
$pdf->setPrintHeader(FALSE); 43 49 $pdf->setPrintHeader(FALSE);
$pdf->setPrintFooter(FALSE); 44 50 $pdf->setPrintFooter(FALSE);
45 51
// write out the contents of the first page 46 52 // write out the contents of the first page
$pdf->AddPage(); 47 53 $pdf->AddPage();
$topLink = $pdf->AddLink(); 48 54 $topLink = $pdf->AddLink();
$pdf->SetLink($topLink); 49 55 $pdf->SetLink($topLink);
//$pdf->AddFont('DejaVu','','DejaVuSansCondensed.ttf',true); 50 56 //$pdf->AddFont('DejaVu','','DejaVuSansCondensed.ttf',true);
$pdf->AddFont('dejavusanscondensed','','dejavusanscondensed.php',true); 51 57 $pdf->AddFont('dejavusanscondensed','','dejavusanscondensed.php',true);
//$pdf->SetFont('DejaVu', '', 20); 52 58 //$pdf->SetFont('DejaVu', '', 20);
$pdf->SetFont('dejavusanscondensed', '', 20); 53 59 $pdf->SetFont('dejavusanscondensed', '', 20);
$pdf->SetFont('', 'U'); 54 60 $pdf->SetFont('', 'U');
$ssfLink = $pdf->AddLink(); 55 61 $ssfLink = $pdf->AddLink();
$pdf->Write(10, "Jump to SSF for SHACK-10A", $ssfLink); 56 62 $pdf->Write(10, "Jump to SSF for SHACK-10A", $ssfLink);
$pdf->SetFont(''); 57 63 $pdf->SetFont('');
$pdf->Ln(); 58 64 $pdf->Ln();
$pdf->Write(10, "This is some text on the first page; "); 59 65 $pdf->Write(10, "This is some text on the first page; ");
$pdf->Ln(); 60 66 $pdf->Ln();
$pdf->Write(10, "Привет! Этот немного текста."); 61 67 $pdf->Write(10, "Привет! Этот немного текста.");
62 68
// load up the Site Summary Figure to go on page #2 63 69 // load up the Site Summary Figure to go on page #2
$ssfPageCount = $pdf->setSourceFile(__DIR__ . '/site_summary_figure.pdf'); 64 70 $ssfPageCount = $pdf->setSourceFile(__DIR__ . '/site_summary_figure.pdf');
//print "Page count of site summary figure form is $ssfPageCount\n"; 65 71 //print "Page count of site summary figure form is $ssfPageCount\n";
66 72
// import the SSF page 67 73 // import the SSF page
$ssfTemplate= $pdf->importPage(1); 68 74 $ssfTemplate= $pdf->importPage(1);
//print "Page size of site summary figure PDF is: "; 69 75 //print "Page size of site summary figure PDF is: ";
//$ssfSize = $pdf->getTemplateSize($ssfTemplate); 70 76 //$ssfSize = $pdf->getTemplateSize($ssfTemplate);
//print "{$ssfSize['w']}mm x {$ssfSize['h']}mm\n"; 71 77 //print "{$ssfSize['w']}mm x {$ssfSize['h']}mm\n";
72 78
// add the SSF file to the 2nd page 73 79 // add the SSF file to the 2nd page
$pdf->AddPage(); 74 80 $pdf->AddPage();
$pdf->SetLink($ssfLink); 75 81 $pdf->SetLink($ssfLink);
$pdf->useTemplate($ssfTemplate); 76 82 $pdf->useTemplate($ssfTemplate);