Commit 52c8784437809812951572280adc7288703d1faa

Authored by Brian Manning
1 parent e021c94a73

pdflib_demo: fix position of text on second page

Showing 1 changed file with 5 additions and 0 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:
* pdflib_demo 6 6 * pdflib_demo
* 7 7 *
* DESCRIPTION: 8 8 * DESCRIPTION:
* Demonstration of the pdflib PHP Library for generating PDF files 9 9 * Demonstration of the pdflib PHP Library for generating PDF files
* 10 10 *
*/ 11 11 */
12 12
/** 13 13 /**
Links: 14 14 Links:
- https://www.pdflib.com/developer/technical-documentation/manuals/ 15 15 - https://www.pdflib.com/developer/technical-documentation/manuals/
- https://www.pdflib.com/pdflib-cookbook/browse-all-topics/ 16 16 - https://www.pdflib.com/pdflib-cookbook/browse-all-topics/
- https://www.pdflib.com/pdflib-cookbook/general-programming/starter-basic/php-general-progamming-issues/ 17 17 - https://www.pdflib.com/pdflib-cookbook/general-programming/starter-basic/php-general-progamming-issues/
- https://www.pdflib.com/en/pdflib-cookbook/block-handling-and-pps/linked-textblocks/php-linked-textblocks/ 18 18 - https://www.pdflib.com/en/pdflib-cookbook/block-handling-and-pps/linked-textblocks/php-linked-textblocks/
- https://www.pdflib.com/pdflib-cookbook/interactive-elements/link-annotations/php-link-annotations/ 19 19 - https://www.pdflib.com/pdflib-cookbook/interactive-elements/link-annotations/php-link-annotations/
- https://www.pdflib.com/pdflib-cookbook/text-output/footnotes-in-text/footnotes-in-text/ 20 20 - https://www.pdflib.com/pdflib-cookbook/text-output/footnotes-in-text/footnotes-in-text/
- https://www.pdflib.com/fileadmin/pdflib/Cookbook/pdf/footnotes_in_text.pdf 21 21 - https://www.pdflib.com/fileadmin/pdflib/Cookbook/pdf/footnotes_in_text.pdf
- https://www.pdflib.com/pdflib-cookbook/pdf-import/import-in-reverse-order/php-import-in-reverse-order/ 22 22 - https://www.pdflib.com/pdflib-cookbook/pdf-import/import-in-reverse-order/php-import-in-reverse-order/
23 23
*/ 24 24 */
25 25
// set a default timezone 26 26 // set a default timezone
date_default_timezone_set("America/Los_Angeles"); 27 27 date_default_timezone_set("America/Los_Angeles");
28 28
//require_once('tcpdf_include.php'); 29 29 //require_once('tcpdf_include.php');
$outfile = __DIR__ . '/output.pdf'; 30 30 $outfile = __DIR__ . '/output.pdf';
31 31
// wrap PDFlib usage in a try{} block 32 32 // wrap PDFlib usage in a try{} block
try { 33 33 try {
$pdf = new PDFlib(); 34 34 $pdf = new PDFlib();
35 35
// set up some PDFlib options 36 36 // set up some PDFlib options
$pdf->set_option("errorpolicy=return"); 37 37 $pdf->set_option("errorpolicy=return");
$pdf->set_option("stringformat=utf8"); 38 38 $pdf->set_option("stringformat=utf8");
39 39
if ($pdf->begin_document($outfile, "") == 0) 40 40 if ($pdf->begin_document($outfile, "") == 0)
throw new Exception("Error: " . $pdf->get_errmsg()); 41 41 throw new Exception("Error: " . $pdf->get_errmsg());
42 42
// set up the document metadata info 43 43 // set up the document metadata info
$pdf->set_info('Creator', 'IODP Science Support Office'); 44 44 $pdf->set_info('Creator', 'IODP Science Support Office');
$pdf->set_info('Author', 'IODP Science Support Office'); 45 45 $pdf->set_info('Author', 'IODP Science Support Office');
$pdf->set_info('Title', 'Demo of TCPDF for generating IODP Proposals'); 46 46 $pdf->set_info('Title', 'Demo of TCPDF for generating IODP Proposals');
$pdf->set_info('Subject', 'IODP Proposals'); 47 47 $pdf->set_info('Subject', 'IODP Proposals');
$pdf->set_info('Keywords', 'IODP proposal ocean drilling core expedition'); 48 48 $pdf->set_info('Keywords', 'IODP proposal ocean drilling core expedition');
49 49
// START PAGE 1 50 50 // START PAGE 1
$pdf->begin_page_ext(612, 792, ''); 51 51 $pdf->begin_page_ext(612, 792, '');
52 52
$textOpts = "fontname={Helvetica} embedding fontsize=20 " 53 53 $textOpts = "fontname={Helvetica} embedding fontsize=20 "
. "encoding=unicode "; 54 54 . "encoding=unicode ";
55 55
$pdf->fit_textline("Jump to SSF for SHACK-10A", 20, 750, 56 56 $pdf->fit_textline("Jump to SSF for SHACK-10A", 20, 750,
$textOpts . " underline=true"); 57 57 $textOpts . " underline=true");
$pdf->fit_textline("This is some text on the first page; ", 20, 720, 58 58 $pdf->fit_textline("This is some text on the first page; ", 20, 720,
$textOpts); 59 59 $textOpts);
$pdf->fit_textline("Привет! Этот немного текста.", 20, 690, $textOpts); 60 60 $pdf->fit_textline("Привет! Этот немного текста.", 20, 690, $textOpts);
61 61
// END PAGE 1 62 62 // END PAGE 1
$pdf->end_page_ext(''); 63 63 $pdf->end_page_ext('');
64 64
// START PAGE 2 65 65 // START PAGE 2
//$pdf->begin_page_ext(612, 792, ''); 66 66 //$pdf->begin_page_ext(612, 792, '');
$ssfPDF = $pdf->open_pdi_document(__DIR__ . "/site_summary_figure.pdf", ''); 67 67 $ssfPDF = $pdf->open_pdi_document(__DIR__ . "/site_summary_figure.pdf", '');
if ($ssfPDF == 0) 68 68 if ($ssfPDF == 0)
throw new Exception("Error: " . $p->get_errmsg()); 69 69 throw new Exception("Error: " . $p->get_errmsg());
70 70
$ssfPage = $pdf->open_pdi_page($ssfPDF, 1, ''); 71 71 $ssfPage = $pdf->open_pdi_page($ssfPDF, 1, '');
$ssfWidth = $pdf->pcos_get_number($ssfPDF, "pages[0]/width"); 72 72 $ssfWidth = $pdf->pcos_get_number($ssfPDF, "pages[0]/width");
$ssfHeight = $pdf->pcos_get_number($ssfPDF, "pages[0]/height"); 73 73 $ssfHeight = $pdf->pcos_get_number($ssfPDF, "pages[0]/height");
74 74
$pdf->begin_page_ext($ssfWidth, $ssfHeight, ''); 75 75 $pdf->begin_page_ext($ssfWidth, $ssfHeight, '');
76 76
$pdf->fit_pdi_page($ssfPage, 0, 0, ''); 77 77 $pdf->fit_pdi_page($ssfPage, 0, 0, '');
$pdf->close_pdi_page($ssfPage); 78 78 $pdf->close_pdi_page($ssfPage);
$pdf->close_pdi_document($ssfPDF); 79 79 $pdf->close_pdi_document($ssfPDF);
80
81 // write some text on to the page
82 $pdf->fit_textline("Back to Top", 20, 570,
83 $textOpts . " underline=true");
84
// END PAGE 2 80 85 // END PAGE 2
$pdf->end_page_ext(''); 81 86 $pdf->end_page_ext('');
82 87
// close the document 83 88 // close the document
$pdf->end_document(''); 84 89 $pdf->end_document('');
85 90
} 86 91 }
87 92
catch (PDFlibException $e) { 88 93 catch (PDFlibException $e) {
die("PDFlib exception occurred in sample:\n" . 89 94 die("PDFlib exception occurred in sample:\n" .
"[" . $e->get_errnum() . "] " . $e->get_apiname() . ": " . 90 95 "[" . $e->get_errnum() . "] " . $e->get_apiname() . ": " .
$e->get_errmsg() . "\n"); 91 96 $e->get_errmsg() . "\n");
} 92 97 }
93 98
catch (Exception $e) { 94 99 catch (Exception $e) {
die($e); 95 100 die($e);
} 96 101 }
97 102
$p = 0; 98 103 $p = 0;
99 104
/* 100 105 /*
// write out the contents of the first page 101 106 // write out the contents of the first page
$pdf->AddPage(); 102 107 $pdf->AddPage();
$topLink = $pdf->AddLink(); 103 108 $topLink = $pdf->AddLink();
$pdf->SetLink($topLink); 104 109 $pdf->SetLink($topLink);
//$pdf->AddFont('DejaVu','','DejaVuSansCondensed.ttf',true); 105 110 //$pdf->AddFont('DejaVu','','DejaVuSansCondensed.ttf',true);
$pdf->AddFont('dejavusanscondensed','','dejavusanscondensed.php',true); 106 111 $pdf->AddFont('dejavusanscondensed','','dejavusanscondensed.php',true);
//$pdf->SetFont('DejaVu', '', 20); 107 112 //$pdf->SetFont('DejaVu', '', 20);
$pdf->SetFont('dejavusanscondensed', '', 20); 108 113 $pdf->SetFont('dejavusanscondensed', '', 20);
$pdf->SetFont('', 'U'); 109 114 $pdf->SetFont('', 'U');
$ssfLink = $pdf->AddLink(); 110 115 $ssfLink = $pdf->AddLink();
$pdf->Write(10, "Jump to SSF for SHACK-10A", $ssfLink); 111 116 $pdf->Write(10, "Jump to SSF for SHACK-10A", $ssfLink);
$pdf->SetFont(''); 112 117 $pdf->SetFont('');
$pdf->Ln(); 113 118 $pdf->Ln();
$pdf->Write(10, "This is some text on the first page; "); 114 119 $pdf->Write(10, "This is some text on the first page; ");
$pdf->Ln(); 115 120 $pdf->Ln();
$pdf->Write(10, "Привет! Этот немного текста."); 116 121 $pdf->Write(10, "Привет! Этот немного текста.");
117 122