#!/usr/bin/env php

<?php
/**
 * FILENAME:
 * fpdfdemo
 *
 * DESCRIPTION:
 * Demonstration of the FPDF PHP Library for generating PDF files
 *
 */

/**
 Links:
  - https://packagist.org/packages/itbz/fpdf
  - http://www.fpdf.org/
  - http://www.fpdf.org/en/doc/index.php
  - http://www.fpdf.org/en/tutorial/index.php
  - http://www.fpdf.org/en/tutorial/tuto6.htm (Links and flowing text)
  - http://www.fpdf.org/en/script/index.php

 This script also requires FPDI to load PDF documents into memory
  - https://www.setasign.com/products/fpdi/about/
  - https://www.setasign.com/products/fpdi/manual/#p-200

 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,
 for FPDI to work
*/

$loader = require __DIR__ . '/vendor/autoload.php';
$loader->register();

$pdf = new FPDI('p', 'mm', 'Letter');

// write out the contents of the first page
$pdf->AddPage();
$topLink = $pdf->AddLink();
$pdf->SetLink($topLink);
$pdf->SetFont('Arial', '', 20);
$pdf->SetFont('', 'U');
$ssfLink = $pdf->AddLink();
$pdf->Write(10, "Jump SSF for SHACK-10A", $ssfLink);
$pdf->SetFont('');
$pdf->Ln();
$pdf->Write(10, "This is some text on the first page; ");
$pdf->Ln();
$pdf->Write(10, "Привет! Этот немного текста.");

// load up the Site Summary Figure to go on page #2
$ssfPageCount = $pdf->setSourceFile(__DIR__ . '/site_summary_figure.pdf');

print "Page count of site summary figure form is $ssfPageCount\n";

// import the SSF page
$ssfTemplate= $pdf->importPage(1);
print "Page size of site summary figure PDF is: ";
$ssfSize = $pdf->getTemplateSize($ssfTemplate);
print "{$ssfSize['w']} x {$ssfSize['h']}\n";

// add the SSF file to the 2nd page
$pdf->AddPage();
$pdf->SetLink($ssfLink);
$pdf->useTemplate($ssfTemplate);
$pdf->SetFont('Helvetica');
$pdf->SetXY(5,5);
$pdf->SetFont('', 'U');
$pdf->Write(8, "Top", $topLink);
$pdf->SetFont('');
$pdf->SetXY(40, 5);
$pdf->Write(8, " SSF: P771/SHACK-10A");

// destination, F = "local file"; filename; isUTF8 (boolean)
//$pdf->Output('F', 'output.pdf', TRUE);
$pdf->Output('output.pdf', 'F');

// vim: expandtab filetype=php shiftwidth=3 tabstop=3