本文整理汇总了PHP中FPDI::setSourceFile方法的典型用法代码示例。如果您正苦于以下问题:PHP FPDI::setSourceFile方法的具体用法?PHP FPDI::setSourceFile怎么用?PHP FPDI::setSourceFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FPDI
的用法示例。
在下文中一共展示了FPDI::setSourceFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: merge
/**
* Merge multiple documents.
*
* @return Dhl_Intraship_Helper_Pdf $this
* @throws Dhl_Intraship_Helper_Pdf_Exception
*/
public function merge()
{
// Include required fpdi library.
if (!class_exists('FPDF', false)) {
require_once Mage::getBaseDir('base') . DS . 'lib' . DS . 'fpdf' . DS . 'fpdf.php';
}
if (!class_exists('FPDI', false)) {
require_once Mage::getBaseDir('base') . DS . 'lib' . DS . 'fpdf' . DS . 'fpdi.php';
}
// Try to merge documents via FPDI.
try {
// Create new FPDI document
$this->_document = new FPDI('P', 'mm', $this->getConfig()->getFormat());
$this->_document->SetAutoPageBreak(false);
$page = 1;
foreach ($this->_collection as $document) {
$pages = $this->_document->setSourceFile($document->getFilePath());
for ($i = 1; $i <= $pages; $i++) {
$this->_document->addPage();
$this->_document->useTemplate($this->_document->importPage($i, '/MediaBox'));
$page++;
}
}
} catch (Exception $e) {
throw new Dhl_Intraship_Helper_Pdf_Exception('pdf merging failed. service temporary not available', $e->getCode());
}
return $this;
}
示例2: generate_philosophy_certificate
function generate_philosophy_certificate($confirmation, $form, $entry, $ajax)
{
// print_r( $entry ); die;
if ($entry['gquiz_is_pass']) {
$upload_dir = wp_upload_dir();
// initiate FPDI
$pdf = new FPDI();
// set the sourcefile
$pdf->setSourceFile(get_template_directory() . '/library/certificate.pdf');
// import page 1
$tplIdx = $pdf->importPage(1);
// get the width and height of the template
$specs = $pdf->getTemplateSize($tplIdx);
// add a page
$pdf->AddPage("L", array($specs['w'], $specs['h']));
// use the imported page as the template
$pdf->useTemplate($tplIdx, 0, 0);
// now write some text above the imported page
$pdf->SetY(101);
$pdf->SetFont("dejavuserifbi", 'I', 35);
$pdf->SetTextColor(0, 54, 99);
$text = $entry['2.3'] . " " . $entry['2.6'];
$pdf->MultiCell(260, 40, $text, 0, 'C');
// now write some text above the imported page
$pdf->SetY(165);
$pdf->SetFont("dejavuserifbi", 'I', 22);
$pdf->SetTextColor(0, 54, 99);
$text = date('F j, Y');
$pdf->MultiCell(260, 22, $text, 0, 'C');
// save the pdf out to file
$pdf->Output($upload_dir['basedir'] . '/certificates/' . $entry['id'] . '.pdf', 'F');
}
return array('redirect' => '/philosophy-results/?id=' . $entry['id']);
}
示例3: runProcessStep
public function runProcessStep($dokument)
{
$file = $dokument->getLatestRevision()->getFile();
$extension = array_pop(explode(".", $file->getExportFilename()));
#$this->ziphandler->addFile($file->getAbsoluteFilename(), $file->getExportFilename());
// Print Metainfo for PDFs
if (strtolower($extension) == "pdf") {
try {
$fpdf = new FPDI();
$pagecount = $fpdf->setSourceFile($file->getAbsoluteFilename());
$fpdf->SetMargins(0, 0, 0);
$fpdf->SetFont('Courier', '', 8);
$fpdf->SetTextColor(0, 0, 0);
$documentSize = null;
for ($i = 0; $i < $pagecount; $i++) {
$string = $dokument->getLatestRevision()->getIdentifier() . " (Seite " . ($i + 1) . " von " . $pagecount . ", Revision " . $dokument->getLatestRevision()->getRevisionID() . ")";
$fpdf->AddPage();
$tpl = $fpdf->importPage($i + 1);
$size = $fpdf->getTemplateSize($tpl);
// First Page defines documentSize
if ($documentSize === null) {
$documentSize = $size;
}
// Center Template on Document
$fpdf->useTemplate($tpl, intval(($documentSize["w"] - $size["w"]) / 2), intval(($documentSize["h"] - $size["h"]) / 2), 0, 0, true);
$fpdf->Text(intval($documentSize["w"]) - 10 - $fpdf->GetStringWidth($string), 5, $string);
}
$this->ziphandler->addFromString($dokument->getLatestRevision()->getIdentifier() . "." . $extension, $fpdf->Output("", "S"));
} catch (Exception $e) {
$this->ziphandler->addFile($file->getAbsoluteFilename(), $dokument->getLatestRevision()->getIdentifier() . "." . $extension);
}
} else {
$this->ziphandler->addFile($file->getAbsoluteFilename(), $dokument->getLatestRevision()->getIdentifier() . "." . $extension);
}
}
示例4: generate_mitgliedsbescheinigung
function generate_mitgliedsbescheinigung($titleAndName, $strasse, $plz, $ort, $land, $jahr, $vorstand, $datum)
{
// initiate FPDI
$pdf = new FPDI();
// add a page
$pdf->AddPage();
// set the source file
$pdf->setSourceFile(HOME_DIRECTORY . 'alumpiHP_libraries/Mitgliedsbestaetigung_blank.pdf');
// import page 1
$tplIdx = $pdf->importPage(1);
// use the imported page and place it at position 0,0 with a width of 210 mm (full page)
$pdf->useTemplate($tplIdx, 0, 0, 210);
// add the font DejaVu
$pdf->AddFont('DejaVuSans', '', 'DejaVuSans.ttf', true);
$pdf->AddFont('DejaVuSans-Bold', '', 'DejaVuSans-Bold.ttf', true);
// text settings
$pdf->SetTextColor(0, 0, 0);
// add address of the member
$addressString = $titleAndName . "\n";
$addressString .= $strasse . "\n";
$addressString .= $plz . " " . $ort . "\n";
$addressString .= $land;
$pdf->SetFont('DejaVuSans');
$pdf->SetFontSize(12);
$pdf->SetXY(20, 23);
$pdf->Multicell(80, 6, $addressString);
//add heading
$headingString = "Mitgliedsbescheinigung " . $jahr;
$pdf->SetFont('DejaVuSans-Bold');
$pdf->SetFontSize(16);
$pdf->SetXY(20, 80);
$pdf->Multicell(170, 6, $headingString);
// add main text
$textString = "Hiermit wird bestätigt, dass " . $titleAndName . " im Kalenderjahr " . $jahr;
$textString .= " ordentliches Mitglied des Absolventen- und Förderverein MPI Uni Bayreuth e.V. (aluMPI) ist.\n";
$textString .= "\n";
$pdf->SetFont('DejaVuSans');
$pdf->SetFontSize(12);
$pdf->SetXY(20, 100);
$pdf->Multicell(170, 6, $textString);
// add signature text
$signatureString = "Absolventen- und Förderverein MPI Uni Bayreuth e.V.\n";
$signatureString .= "1. Vorstand: " . $vorstand . "\n";
$pdf->SetXY(20, 140);
$pdf->Multicell(170, 6, $signatureString);
// add signature
$pdf->Image(HOME_DIRECTORY . 'alumpiHP_libraries/unterschrift_krinninger.png', 20, 155, 50);
// add place and date
$dateString = "Bayreuth, " . $datum;
$pdf->SetXY(20, 180);
$pdf->Multicell(170, 6, $dateString);
ob_clean();
$pdf->Output();
}
示例5: createPDF
public function createPDF(FPDI $fpdi, $filename)
{
$fpdi->setSourceFile(__DIR__ . '/A.pdf');
$template = $fpdi->importPage(1);
$size = $fpdi->getTemplateSize($template);
$fpdi->AddPage('P', array($size['w'], $size['h']));
$fpdi->useTemplate($template);
$template = $fpdi->importPage(1);
$fpdi->AddPage('P', array($size['w'], $size['h']));
$fpdi->useTemplate($template);
file_put_contents($filename, $fpdi->Output('', 'S'));
}
示例6: handle
/**
* Handle the event.
*
* @param BookPublished $event
* @return void
*/
public function handle(CreateChapter $event)
{
// create PDF
$fpdi = new \FPDI();
// count the book page
$pageCount = $fpdi->setSourceFile($this->uploadPath . $event->chapter->url);
// this one is used within the CreatePDF to include it within the template
Session::put('total_pages', $pageCount);
// update the database with total page count
$event->chapter->update(['total_pages' => $pageCount]);
$event->chapter->save();
}
示例7: listAction
public function listAction()
{
$receipt = new \FPDI();
// PDFの余白(上左右)を設定
$receipt->SetMargins(0, 0, 0);
// ヘッダーの出力を無効化
$receipt->setPrintHeader(false);
// フッターの出力を無効化
$receipt->setPrintFooter(false);
// フォントを登録
$fontPathRegular = $this->getLibPath() . '/tcpdf/fonts/migmix-2p-regular.ttf';
// $regularFont = $receipt->addTTFfont($fontPathRegular, '', '', 32);
$font = new TCPDF_FONTS();
$regularFont = $font->addTTFfont($fontPathRegular);
$fontPathBold = $this->getLibPath() . '/tcpdf/fonts/migmix-2p-bold.ttf';
// $boldFont = $receipt->addTTFfont($fontPathBold, '', '', 32);
$font = new TCPDF_FONTS();
$boldFont = $font->addTTFfont($fontPathBold);
// ページを追加
$receipt->AddPage();
// テンプレートを読み込み
// $receipt->setSourceFile($this->getLibPath() . '/tcpdf/tpl/receipt.pdf');
// $receipt->setSourceFile($this->getLibPath() . '/tcpdf/tpl/template.pdf');
// $receipt->setSourceFile($this->getLibPath() . '/tcpdf/tpl/w01_1.pdf');
$receipt->setSourceFile($this->getLibPath() . '/tcpdf/tpl/senijiten.pdf');
// 読み込んだPDFの1ページ目のインデックスを取得
$tplIdx = $receipt->importPage(1);
// 読み込んだPDFの1ページ目をテンプレートとして使用
$receipt->useTemplate($tplIdx, null, null, null, null, true);
// 書き込む文字列のフォントを指定
$receipt->SetFont($regularFont, '', 11);
// 書き込む文字列の文字色を指定
$receipt->SetTextColor(0, 0, 255);
// X : 42mm / Y : 108mm の位置に
$receipt->SetXY(59, 248);
// 文字列を書き込む
$receipt->Write(0, isset($_POST['name']) ? $_POST['name'] . 'さん' : '名無しさん');
/* $response = new Response(
// Output関数の第一引数にはファイル名、第二引数には出力タイプを指定する
// 今回は文字列で返してほしいので、ファイル名はnull、出力タイプは S = String を選択する
$receipt->Output(null, 'S'),
200,
array('content-type' => 'application/pdf')
);
// レスポンスヘッダーにContent-Dispositionをセットし、ファイル名をreceipt.pdfに指定
$response->headers->set('Content-Disposition', 'attachment; filename="receipt.pdf"');
return $response;
*/
// $receipt->
$receipt->output('newpdf.pdf', 'I');
}
示例8: testMerge
public function testMerge()
{
$fpdi = new FPDI();
$fpdi->setSourceFile(__DIR__ . '/A.pdf');
$template = $fpdi->importPage(1);
$size = $fpdi->getTemplateSize($template);
$fpdi->AddPage('P', array($size['w'], $size['h']));
$fpdi->useTemplate($template);
$template = $fpdi->importPage(1);
$fpdi->AddPage('P', array($size['w'], $size['h']));
$fpdi->useTemplate($template);
file_put_contents(__DIR__ . '/AA.pdf', $fpdi->Output('', 'S'));
}
示例9: split_pdf
function split_pdf($filename, $end_directory = false, $num = 1)
{
require_once 'fpdf/fpdf.php';
require_once 'fpdi/fpdi.php';
$end_directory = $end_directory ? $end_directory . date("d-m-Y__H-i-s") . "/" : './';
$new_path = preg_replace('/[\\/]+/', '/', $end_directory . '/' . substr($filename, 0, strrpos($filename, '/')));
if (!is_dir($new_path)) {
// Will make directories under end directory that don't exist
// Provided that end directory exists and has the right permissions
mkdir($new_path, 0777, true);
}
$pdf = new FPDI();
$pagecount = $pdf->setSourceFile($filename);
// How many pages?
$j = 0;
// Split each page into a new PDF
$new_pdf = new FPDI();
for ($i = 1; $i <= $pagecount; $i++) {
$new_pdf->AddPage();
$new_pdf->setSourceFile($filename);
$new_pdf->useTemplate($new_pdf->importPage($i));
if ($i != 1 && $i % $num == 0 || $num == 1) {
try {
$new_filename = $end_directory . str_replace('.pdf', '', $filename) . '_' . $i . ".pdf";
$new_pdf->Output($new_filename, "F");
$url = "http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['SCRIPT_NAME']) . "/";
echo "File: <a href='" . $url . $new_filename . "'>" . $url . $new_filename . "</a><br />\n";
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
unset($new_pdf);
$new_pdf = new FPDI();
$j = 0;
}
$j++;
}
if ($j != 0) {
try {
$new_filename = $end_directory . str_replace('.pdf', '', $filename) . '_' . ($i - 1) . ".pdf";
$new_pdf->Output($new_filename, "F");
$url = "http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['SCRIPT_NAME']) . "/";
echo "File: <a href='" . $url . $new_filename . "'>" . $url . $new_filename . "</a><br />\n";
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
}
}
示例10: merge
/**
* Merges your provided PDFs and outputs to specified location.
* @param $outputmode
* @param $outputname
* @return PDF
*/
public function merge($outputmode = 'browser', $outputpath = 'newfile.pdf')
{
if (!isset($this->_files) || !is_array($this->_files)) {
throw new exception("No PDFs to merge.");
}
$fpdi = new FPDI();
//$fpdi->setPrintHeader(FALSE);
//$fpdi->setPrintFooter(FALSE);
//merger operations
foreach ($this->_files as $file) {
$filename = $file[0];
$filepages = $file[1];
$count = $fpdi->setSourceFile($filename);
//add the pages
if ($filepages == 'all') {
for ($i = 1; $i <= $count; $i++) {
$template = $fpdi->importPage($i);
$size = $fpdi->getTemplateSize($template);
$orientation = $size['w'] <= $size['h'] ? 'P' : 'L';
$fpdi->AddPage($orientation, array($size['w'], $size['h']));
$fpdi->useTemplate($template);
}
} else {
foreach ($filepages as $page) {
if (!($template = $fpdi->importPage($page))) {
throw new exception("Could not load page '{$page}' in PDF '{$filename}'. Check that the page exists.");
}
$size = $fpdi->getTemplateSize($template);
$orientation = $size['w'] <= $size['h'] ? 'P' : 'L';
$fpdi->AddPage($orientation, array($size['w'], $size['h']));
$fpdi->useTemplate($template);
}
}
}
//output operations
$mode = $this->_switchmode($outputmode);
if ($mode == 'S') {
return $fpdi->Output($outputpath, 'S');
} else {
if ($fpdi->Output($outputpath, $mode) == '') {
return true;
} else {
throw new exception("Error outputting PDF to '{$outputmode}'.");
return false;
}
}
}
示例11: carl_merge_pdfs_fpdi
function carl_merge_pdfs_fpdi($pdffiles, $titles = array(), $metadata = array(), $metadata_encoding = 'UTF-8')
{
// FPDI throws some notices that break the PDF
$old_error = error_reporting(E_ERROR | E_WARNING | E_PARSE);
include_once INCLUDE_PATH . 'pdf/tcpdf/tcpdf.php';
include_once INCLUDE_PATH . 'pdf/fpdi/fpdi.php';
if (gettype($pdffiles) != 'array') {
trigger_error('$pdffiles must be an array');
return false;
}
if (!(class_exists('TCPDF') && class_exists('FPDI'))) {
trigger_error('You must have TCPDF/FPDI installed in order to run carl_merge_pdfs()');
return false;
}
if (empty($pdffiles)) {
return NULL;
}
$fpdi = new FPDI();
foreach ($pdffiles as $pdffile) {
if (file_exists($pdffile)) {
$count = $fpdi->setSourceFile($pdffile);
for ($i = 1; $i <= $count; $i++) {
$template = $fpdi->importPage($i);
$size = $fpdi->getTemplateSize($template);
$fpdi->AddPage('P', array($size['w'], $size['h']));
$fpdi->useTemplate($template, null, null, null, null, true);
if ($i == 1) {
if (isset($titles[$pdffile])) {
$bookmark = html_entity_decode($titles[$pdffile]);
} else {
$bookmark = $pdffile;
}
$fpdi->Bookmark($bookmark, 1, 0, '', '', array(0, 0, 0));
}
}
}
}
error_reporting($old_error);
return $fpdi->Output('ignored.pdf', 'S');
}
示例12: mkdir
function split_multi_pdf($arrayOfFiles)
{
$new_path = storage_path() . '/Macyspos';
if (!is_dir($new_path)) {
// Will make directories under end directory that don't exist
// Provided that end directory exists and has the right permissions
mkdir($new_path, 0777, true);
}
foreach ($arrayOfFiles as $file) {
$tempArrayOfPos = array();
$tempArrayOfPos = $this->getArrayOfPOs($file);
$pdf = new FPDI();
$pagecount = $pdf->setSourceFile($file);
// How many pages?
for ($i = 1; $i <= $pagecount; $i++) {
$singleItem = $tempArrayOfPos[$i - 1];
// dd($singleItem);
$tempPackingList = MacysPackingList::where('po', '=', $singleItem['PO'])->first();
if ($tempPackingList == null) {
$new_pdf = new FPDI();
$new_pdf->AddPage();
$new_pdf->setSourceFile($file);
$newPackingList = new MacysPackingList();
$newPackingList->po = trim($singleItem['PO']);
$newPackingList->shipterms = trim($singleItem['shipterms']);
$new_pdf->useTemplate($new_pdf->importPage($i));
try {
$new_filename = storage_path() . '/Macyspos/' . $singleItem['PO'] . '.pdf';
$newPackingList->pathToFile = $new_filename;
$new_pdf->Output($new_filename, "F");
$newPackingList->save();
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
}
}
}
}
示例13: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$id = $input->getArgument('id');
$pdffile = $input->getArgument('pdf');
$em = $this->getContainer()->get('doctrine');
$tab = $this->csv($pdffile);
$template = $em->getRepository('PrintBundle:Template')->find($id);
$path = $this->getContainer()->get('kernel')->getRootDir() . '/../web/uploads/pdf/' . $template->getPdffile();
$width = $template->getWidth();
$height = $template->getHeight();
$orientation = $height > $width ? 'P' : 'L';
$custom_layout = array($width, $height);
$i = 1;
foreach ($tab as $key => $value) {
$pdf = new \FPDI($orientation, 'mm', $custom_layout, true, 'UTF-8', false);
$pdf->setPageOrientation($orientation);
$pdf->SetMargins(PDF_MARGIN_LEFT, 40, PDF_MARGIN_RIGHT);
$pdf->SetAutoPageBreak(true, 40);
$pdf->setFontSubsetting(false);
// add a page
$pdf->AddPage($orientation);
$pdf->setSourceFile($path);
$_tplIdx = $pdf->importPage(1);
$size = $pdf->useTemplate($_tplIdx, 0, 0, $width, true);
foreach ($template->getChildactivity() as $opt) {
$pdf->SetXY($opt->getX(), $opt->getY());
$pdf->SetFont($opt->getFont(), '', $opt->getFontsize() * 2);
// echo $opt->getFontsize()."\n";
$pdf->Cell($opt->getWidth(), $opt->getHeight(), $value[$opt->getName()]);
}
//$pdf->Cell(0, $size['h'], 'TCPDF and FPDI');
// echo $template->getId();
$pdf->Output($this->getContainer()->get('kernel')->getRootDir() . '/../web/folder/pdf' . $template->getId() . "-{$i}.pdf", 'F');
$i++;
}
}
示例14: splitPages
protected function splitPages($pages)
{
if (!isset($pages) || empty($pages) || !is_array($pages)) {
static::raiseError(__METHOD__ . '(), $pages parameter is invalid!');
return false;
}
try {
$pdf = new \FPDI();
} catch (\Exception $e) {
static::raiseError(__METHOD__ . '(), failed to load FPDI!');
return false;
}
if (($fqfn = $this->tempItem->getFilePath()) === false) {
static::raiseError(get_class($this->tempItem) . '::getFilePath() returned false!');
return false;
}
try {
$page_count = $pdf->setSourceFile($fqfn);
} catch (\Exception $e) {
static::raiseError(getClass($pdf) . '::setSourceFile() has thrown an exception! ' . $e->getMessage());
return false;
}
if ($page_count == count($pages)) {
try {
@$pdf->cleanUp();
} catch (\Exception $e) {
static::raiseError(get_class($pdf) . '::cleanUp() has thrown an exception! ' . $e->getMessage());
return false;
}
return true;
}
for ($page_no = 1; $page_no <= $page_count; $page_no++) {
if (!in_array($page_no, $pages)) {
continue;
}
// import a page
$templateId = $pdf->importPage($page_no);
// get the size of the imported page
$size = $pdf->getTemplateSize($templateId);
// create a page (landscape or portrait depending on the imported page size)
if ($size['w'] > $size['h']) {
$pdf->AddPage('L', array($size['w'], $size['h']));
} else {
$pdf->AddPage('P', array($size['w'], $size['h']));
}
// use the imported page
$pdf->useTemplate($templateId);
}
try {
$pdf->Output($fqfn, 'F');
} catch (\Exception $e) {
static::raiseError(get_class($pdf) . '::Output() returned false!');
return false;
}
if (!$this->tempItem->refresh()) {
static::raiseError(get_class($this->tempItem) . '::refresh() returned false!');
return false;
}
return true;
}
示例15: ValorSql
$idFormulario = ValorSql($sql, "", $params);
$params = array(":sa_idformulario" => $idFormulario);
$sql =
"SELECT art.utiles.armar_cuit(sa_cuit) cuit, sa_nombre
FROM asa_solicitudafiliacion
WHERE sa_idformulario = :sa_idformulario";
$stmt = DBExecSql($conn, $sql, $params);
$row2 = DBGetQuery($stmt, 1, false);
if ($autoPrint)
$pdf = new PDF_AutoPrint();
else
$pdf = new FPDI();
$pdf->setSourceFile($_SERVER["DOCUMENT_ROOT"]."/modules/solicitud_afiliacion/templates/ventanilla_electronica.pdf");
$pdf->AddPage();
$tplIdx = $pdf->importPage(1);
$pdf->useTemplate($tplIdx);
$pdf->SetFont("Arial", "B", 9);
$pdf->Ln(34.5);
$pdf->Cell(38);
$pdf->Cell(136, 0, $row2["SA_NOMBRE"]);
$pdf->Ln(5.2);
$pdf->Cell(31);
$pdf->Cell(32, 0, $row2["CUIT"]);