From: Pak R. <pak...@gm...> - 2016-04-04 09:37:43
|
Hi Rafael: 2 months ago I had to use TCPDF to print barcode labels as the current webERP library was not precise enough for our needs (we must specify the width of the smallest vertical bar). I'm not an expert (al all) in PDF creation and was quite trial and error, but ended up with a simple code to read and maintain. I found really simple t use the "space management" space we have for printing purposes, when to add a page, etc) so I guess we'll end up with shorter code doing neater things. I will be happy to forward you the script (was too customized to be of any use for the community), but maybe it can help you with some portions of reusable code for the barcode part, If you think it can help, just let me know and I'mm forward to you. Many thanks for keep updating webERP in this field, which is much more tricky than it looks. Regards, Ricard 2016-04-04 0:32 GMT+08:00 Rafael Chacón <raf...@gm...>: > Hi Exson: > > Sorry by the delay, I was reviewing my notes. > To replace addTextWrap() and AddText() with Nicola Asuni TCPDF' functions, > there are some options. I did the following (I do not know if it is the > best, because I did it in a rush): > > addText($XPos,$YPos,$size,$text) > ----------- > I use public function: > Text($x, $y, $txt, $fstroke=false, $fclip=false, $ffill=true, $border=0, > $ln=0, $align='', $fill=false, $link='', $stretch=0, > $ignore_min_height=false, $calign='T', $valign='M', $rtloff=false). > Parameters: > * $x (float) Abscissa of the cell origin (same as addText_$XPos). MUST. > * $y (float) Ordinate of the cell origin (cell vertical coordinate from > page TOP side to cell top side in dpi -72dpi = 25.4mm-. WARNING: $y = > page_height – addText_$YPos). MUST. > * $txt (string) String to print (same as addText_$text). MUST. > To change font size, you have to use public function SetFontSize() in > tcpdf/tcpdf.php. > Example: > $this->SetFontSize($size); > $this->Text($XPos, $this->h-$YPos, $text); > More info: In tcpdf/tcpdf.php, line 4870. > See also: Cell(), Write(), MultiCell(), WriteHTML(), WriteHTMLCell(). > > addTextWrap($XPos, $YPos, $linewidth, $fontsize, $text, $Align='left', > $angle=0, $test=0, $border=0, $fill=false) > ------------------ > I use public function: > MultiCell($w, $h, $txt, $border=0, $align='J', $fill=false, $ln=1, $x='', > $y='', $reseth=true, $stretch=0, $ishtml=false, $autopadding=true, $maxh=0, > $valign='T', $fitcell=false). > Probably it is better to use the function writeHTMLCell (see: > http://www.tcpdf.org/examples/example_046.phps, a text hyphenation > example). This function can be used also to replace AddText(), but it is > more complex. > Parameters: > * $w (float) Width of cells. If 0, they extend up to the right margin of > the page (same as addTextWrap_$linewidth). MUST. > * $h (float) Cell minimum height. The cell extends automatically if needed > (I use the same as addTextWrap_$fontsize, but I saw some reports that use a > greater line_height). MUST. > * $txt (string) String to print [same as addTextWrap_$text, but you must > translate it to html using, as example, “html_entity_decode($text, > ENT_QUOTES, 'UTF-8')” ]. MUST. > * $border (mixed) Indicates if borders must be drawn around the cell. The > value can be a number: 0: no border (default); 1: frame; or a string > containing some or all of the following characters (in any order): L: left; > T: top; R: right; B: bottom; or an array of line styles for each border > group - for example: array('LTRB' => array('width' => 2, 'cap' => 'butt', > 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0))). OPTIONAL, I > recommend to input as “$border=0”. > * $align (string) Allows to centre or align the text. Possible values are: > L or empty string: left align; C: centre; R: right align; J: justification > (default value when $ishtml=false). OPTIONAL, I do a “switch($Align) {// > Translate from Pdf-Creator to TCPDF.”. > * $fill (boolean) Indicates if the cell background must be painted (true) > or transparent (false). OPTIONAL, I recommend to input as “$fill=false”. > * $ln (int) Indicates where the current position should go after the call. > Possible values are: 0: to the right; 1: to the beginning of the next line > [DEFAULT]; 2: below. OPTIONAL, I recommend to input as “$ln=1” to use the > return_function to control the position at the printing end. > * $x (float) x position in user units (same as addTextWrap_$XPos). > OPTIONAL, but I recommend to use it. > * $y (float) y position in user units (cell vertical coordinate from page > TOP side to cell top side in dpi -72dpi = 25.4mm-. WARNING_1: $y = > page_height – addTextWrap_$YPos – addTextWrap_$lineheight. WARNING_2: This > addTextWrap_$lineheight = addTextWrap_$fontsize is the difference in y_pos > between addTextWrap() and AddText(). OPTIONAL, but I recommend to use it. > To change font size, you have to use public function SetFontSize() in > tcpdf/tcpdf.php. > Example: > $this->SetFontSize($size); > $this->MultiCell($linewidth, $fontsize, html_entity_decode($text, > ENT_QUOTES, 'UTF-8'), $border, $Align, $fill, 1, $XPos, $this->h - > $Ypos);// Using $Ypos as in AddText(). > // return $this->h - $this->y;// The position after printing. COMMENT: > $YPos is the same as in addText(). > More info: In tcpdf/tcpdf.php, line 5732. > See also: SetFont(), SetDrawColor(), SetFillColor(), SetTextColor(), > SetLineWidth(), Cell(), Write(), SetAutoPageBreak(). > > Comments > -------------- > * For a quick transition, I included a new function in includes/class.pdf: > > //------------------------------------------------------------------------------ > public function TextWrap($XPos, $YPos, $linewidth, $fontsize, $text, > $Align='left', $border=0, $fill=false) { > // Adds text to the page, but ensure that it fits within a certain width. > If it does not fit then put in as much as possible, splitting at white > space or soft hyphen character and return the remainder. Justification can > also be specified for the text. It use UTF-8 encoding. > // $XPos = Cell horizontal coordinate from page left side to cell left > side in dpi (72dpi = 25.4mm). > // $YPos = Cell vertical coordinate from page bottom side to cell top side > in dpi (72dpi = 25.4mm). > // $linewidth = Cell (line) width in dpi (72dpi = 25.4mm). If 0, > MultiCell() extends up to the right margin of the page. > // $fontsize = Font size in dpi (72dpi = 25.4mm). > // $text = Text to be split in portion to be add to the page and the > remainder to be returned. > // $Align = 'left', 'center', 'centre', 'full' or 'right'. > // $border = Indicates if borders must be drawn around the cell. The value > can be a number: 0: no border (default), 1: frame, or a string containing > some or all of the following characters (in any order): L: left, T: top, R: > right, B: bottom or an array of line styles for each border group - for > example: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => > 'miter', 'dash' => 0, 'color' => array(0, 0, 0))). > // $fill = Indicates if the cell background must be painted (true) or > transparent (false). > // @access public. > $this->SetFontSize($fontsize);// Public function SetFontSize() in > ~/includes/tcpdf/tcpdf.php. > $text = html_entity_decode($text, ENT_QUOTES, 'UTF-8');// Convert all HTML > entities to their applicable characters. > switch($Align) {// Translate from Pdf-Creator to TCPDF. > case 'left': > $Align = 'L'; break; > case 'right': > $Align = 'R'; break; > case 'center': > $Align = 'C'; break; > case 'centre': > $Align = 'C'; break; > case 'full': > $Align = 'J'; break; > default: > $Align = 'L'; break; > } > $this->MultiCell($linewidth, $fontsize, $text, $border, $Align, $fill, 1, > $XPos, $this->h - $YPos);// Public function SetFontSize() in > ~/includes/tcpdf/tcpdf.php. > return $this->h - $this->y;// COMMENT: $YPos is the same as in addText(). > } > > //------------------------------------------------------------------------------ > > * Note: I am also thinking in migrate from barcodepack to Nicola Asuni > TCPDF' barcode_functions. > > Best regards, Rafael. > > 2016-04-01 18:28 GMT-06:00 ExsonQu <hex...@gm...>: > >> *Hi, Rafael,* >> >> Thank you for your reply. >> It is a good idea to migrate tcpdf absolutely. But the problem >> is >> that without addTextWrap, it's hard to control the Xpos and Ypos for >> multiple lines cell. Do you have any solution for this? >> >> Thanks and best regards! >> >> Exson >> >> >> >> -- >> View this message in context: >> http://weberp-accounting.1478800.n4.nabble.com/PDF-generator-in-webERP-tp4658061p4658572.html >> Sent from the web-ERP-developers mailing list archive at Nabble.com. >> >> >> ------------------------------------------------------------------------------ >> Transform Data into Opportunity. >> Accelerate data analysis in your applications with >> Intel Data Analytics Acceleration Library. >> Click to learn more. >> http://pubads.g.doubleclick.net/gampad/clk?id=278785471&iu=/4140 >> _______________________________________________ >> Web-erp-developers mailing list >> Web...@li... >> https://lists.sourceforge.net/lists/listinfo/web-erp-developers >> > > > > ------------------------------------------------------------------------------ > Transform Data into Opportunity. > Accelerate data analysis in your applications with > Intel Data Analytics Acceleration Library. > Click to learn more. > http://pubads.g.doubleclick.net/gampad/clk?id=278785471&iu=/4140 > _______________________________________________ > Web-erp-developers mailing list > Web...@li... > https://lists.sourceforge.net/lists/listinfo/web-erp-developers > > |