Skip to content

Instantly share code, notes, and snippets.

@peaceman
Last active July 18, 2019 11:09
Show Gist options
  • Select an option

  • Save peaceman/379d54369ae077865e83fb59abdcb9fb to your computer and use it in GitHub Desktop.

Select an option

Save peaceman/379d54369ae077865e83fb59abdcb9fb to your computer and use it in GitHub Desktop.
fit_textflow fitmethod auto ?
<?php
$p = new PDFlib();
$p->set_option("stringformat=utf8");
$p->begin_document("", "");
/* Create an A4 Landscape page */
$p->begin_page_ext(0, 0, "width=a4.height height=a4.width");
$createTextFlowOptList = [
'hyphenchar=none',
'fontname=Helvetica',
'encoding=unicode',
'fontsize=32',
'leftindent=0',
'adjustmethod=nofit',
'charclass={letter .}',
];
$fitTextFlowOpts = 'fitmethod=auto showborder';
$boxDims = ['width' => 200, 'height' => 50];
$boxPos = ['llx' => 10, 'lly' => 400];
$textFlow = $p->create_textflow('[email protected]', implode(' ', $createTextFlowOptList));
$res = $p->fit_textflow(
$textFlow,
$boxPos['llx'], $boxPos['lly'],
$boxPos['llx'] + $boxDims['width'],
$boxPos['lly'] + $boxDims['height'],
$fitTextFlowOpts
);
$p->end_page_ext("");
$p->end_document("");
$buf = $p->get_buffer();
$len = strlen($buf);
header("Content-type: application/pdf");
header("Content-Length: $len");
header("Content-Disposition: inline; filename=fitmethod-auto.pdf");
print $buf;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment