PDFLibに関するさらに別の質問です。pdflib 9 PDF_add_textflowは最初の2行を区切りません。
私は次のクラスからsetupMultilineTextflow()関数を呼び出ししようとしていた場合、テキストの最初の2行は関数の呼び出しは、値は以下のクラスで起こる
// Abstract PDF class, holding generalised functions and
// intialising a new PDF file
//namespace synergetic\realscan-middleware-pdflib;
class AbstractPDF{
protected $pdf;
protected $searchpath;
protected $fontName;
public function __construct(){
$this->pdf = PDF_new();
$this->searchpath = "fonts/";
/*
pdf_set_parameter($this->pdf,"errorpolicy", "return"); // check return values of load_font() etc.
pdf_set_parameter($this->pdf,"hypertextencoding", "winansi"); // used to prevent problems with japanese systems
pdf_set_parameter($this->pdf,"SearchPath", $searchpath); // **set search path parameter in pdf
*/
if (pdf_begin_document($this->pdf,"", "") == 0) {
die("Error: " . pdf_get_errmsg($this->pdf));
}
pdf_set_option($this->pdf,"errorpolicy=return");
pdf_set_option($this->pdf,"searchpath={" . $this->searchpath . "}");
pdf_set_option($this->pdf,"stringformat=utf8");
}
protected function startAFourPage(){
pdf_begin_page_ext($this->pdf, 0, 0, "width=a4.width height=a4.height");
}
protected function startPage($format){
switch (true){
case($format="a4"):
pdf_begin_page_ext($this->pdf, 0, 0, "width=a4.width height=a4.height");
break;
/*
case("usletter"):
//pdf_begin_page_ext($this->pdf, 0, 0, "width=a4.width height=a4.height");
break;
*/
}
}
// When setting up any of the PDF content types, one should
// remember that in PDFLib, x=>y axis start with 0(zero) at
// lower left corner.
// The text line is set up in space by setting up the
// coordinates of the lower left corner and then providing
// height and width of the object as separate values
protected function setupTextLine($xcoordinate, $ycoordinate, $width, $height,
$fontName, $fontEncoding, $fontSize, $text, $textPosition = "left"){
//adding text directly through the PDFLib documentation
$font = PDF_load_font($this->pdf, $fontName, $fontEncoding, "");
PDF_setfont($this->pdf, $font, $fontSize);
//PDF_set_text_pos($this->pdf, 25, 650);
//PDF_show($this->pdf, $text);
PDF_fit_textline ($this->pdf, $text, $xcoordinate, $ycoordinate, "boxsize {".$width." ".$height."} position=left");
}
// When setting up any of the PDF content types, one should
// remember that in PDFLib, x=>y axis start with 0(zero) at
// lower left corner.
// The text flow is set up by providing the coordinate for
// lower left corner and upper right, as a rule.
// But overall PDFLib will placed it by coordinates for
// two corners diagonal to each other.
// For this class we will identify these corners as
// lowLeft and upperRight
protected function setupMultilineTextflow($lowLeftX, $lowLeftY, $upperRightX, $upperRightY,
$fontName, $fontEncoding, $fontSize, $text){
//two types of text can be submitted string and array
if (gettype($text) == "array"){
foreach ($text as $line){
if ($count == 0){
$textFlow = PDF_create_textflow($this->pdf, $line,
"fontname=".$fontName."
fontsize=".$fontSize."
encoding=".$fontEncoding);
}
else{
$textFlow = PDF_add_textflow($this->pdf, $textFlow, $line,
"fontname=".$fontName."
fontsize=".$fontSize."
encoding=".$fontEncoding);
}
$count++;
}
}
else{
$textFlow = PDF_create_textflow($this->pdf, $line,
"fontname=".$fontName."
fontsize=".$fontSize."
encoding=".$fontEncoding);
}
PDF_fit_textflow($this->pdf, $textFlow, $lowLeftX, $lowLeftY, $upperRightX, $upperRightY,"");
}
protected function setupTable($headers=array('test'=>''), array $field){
}
protected function endDocument(){
//this is fo the end of the document
pdf_end_page_ext($this->pdf,"");
pdf_end_document($this->pdf,"");
//exit;
$data = pdf_get_buffer($this->pdf);
$len = strlen($data);
header("Content-type: application/pdf");
header("Content-Length: $len");
header("Content-Disposition: inline; filename=hello.pdf");
print $data;
$this->pdf = 0;
}
}
に分離されていません "データム:"、 "Auftrags-NR"、 "Auftragsname:"、 "Kunden-NR"
require 'AbstractPDF.php';
class Lieferschein extends AbstractPDF{
public function __construct(){
parent::__construct();
}
public function generateContent(){
//set up general order set fields
$orderDetailNames = array("Datum:", "Auftrags-NR:", "Auftragsname:", "Kunden-Nr:");
$fontName = "ZEISSFrutigerNextW1G-Light";
parent::setupMultilineTextflow(111, 350, 191, 520,
$fontName, "unicode", 9, $orderDetailNames);
parent:: endDocument();
return "";
}
}
結果の値の配列として供給されますコールルックPDF データムに次のように:Auftrags-NRを: Auftragsname: Kunden-NRを:
私は今しばらくの間、これで苦労してきたが、関係なく、私は、コードをどのように変化するか、それはまだ終了していません2つのトップラインを合わせて:-(
ありがとうございました。
ありがとう:-)各行の最後に\ nを追加しました。 テキストの中で使用したときに、時にはうまくいかず、テキストが持ち越されず、代わりに –
と表示されるだけで、あなたの側で何が起こるかを推測するのは難しいです。たぶん\ nを\ n誤って単一のテキスト出力(fit_textline())に追加しますか? – Rainer