HPDFPRINT TO ERRO

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

User avatar
jairpinho
Posts: 251
Joined: Mon Jul 18, 2011 5:36 pm
Location: Rio Grande do Sul - Brasil
Been thanked: 5 times
Contact:

HPDFPRINT TO ERRO

Post by jairpinho » Thu Nov 29, 2018 2:18 am

Hello if it exceeds the defined size it does not present any information in the pdf follows examples if someone can help

Code: Select all


#include <hmg.ch>
#include "hfcl.ch"


Function Main

        Load Window Main
        Main.Center
        Main.Activate

Return


*******************************************************************************
function edit_pdf()
*******************************************************************************
Local cFonte1:= "Helvetica-Bold"
Local cEdit1 := "1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
Local cEdit2 := "2XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
Local cEdit3 := "3XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
Local cArquivo:= "Assistencia.pdf"
local lSuccess := .f.

   SELECT HPDFDOC cArquivo TO lSuccess papersize HPDF_PAPER_A4
   SET HPDFDOC COMPRESS ALL
   SET HPDFDOC PAGEMODE TO OUTLINE
   SET HPDFINFO AUTHOR      TO 'Jair Pinho'
   SET HPDFINFO CREATOR     TO 'Jair Pinho'
   SET HPDFINFO TITLE      TO 'Assistência'
   SET HPDFINFO SUBJECT     TO 'Criado com LibHaru/HPDF Library'
   SET HPDFINFO KEYWORDS    TO 'HMG, HPDF, Documentation, LibHaru, Harbour, MiniGUI'
   SET HPDFINFO DATECREATED TO date() TIME time()
   SET HPDFDOC ENCODING TO "WinAnsiEncoding"


   if lSuccess
      
        START HPDFPAGE
            SET HPDFDOC PAGEOUTLINE TITLE "Assistencia" 
			//@ 16, 115 HPDFPRINT IMAGE "Logo_pdf.png" width 80 height 35 TYPE PNG
			@ 95.5, 11 HPDFPRINT "DESCRIÇÃO EQUIPAMENTO: " FONT cFonte1 size 9 COLOR { 0, 0, 0 }  
			@ 20, 15 HPDFPRINT cEdit1 TO 143, 198 FONT cFonte1 size 9 COLOR { 0, 0, 0 } RIGHT
			@ 150, 15 HPDFPRINT cEdit2 TO 183, 198 FONT cFonte1 size 9 COLOR { 0, 0, 0 } JUSTIFY
			@ 190, 15 HPDFPRINT cEdit3 TO 230, 198 FONT cFonte1 size 9 COLOR { 0, 0, 0 } JUSTIFY
			          page = 1
		END HPDFPAGE

	ENDIF
      END HPDFDOC	 	
      execute file cArquivo			
			
Return Nil			

Image
Attachments
Assistenciajpg_Page1.jpg
Assistenciajpg_Page1.jpg (21.02 KiB) Viewed 399 times
Jair Pinho
HMG ALTA REVOLUÇÃO xBASE
HMG xBASE REVOLUTION HIGH
http://www.hmgforum.com.br

EduardoLuis
Posts: 601
Joined: Tue Jun 04, 2013 6:33 pm
Location: Argentina
Has thanked: 1 time
Been thanked: 39 times

Post by EduardoLuis » Thu Nov 29, 2018 2:21 pm

Jaipirino

Instead of a not posible continuos char line, put:

Cedit1 := Replicate("3Xxxx " , 50)

As you can after last x there is a space like a word.
If you put a continuos carácter without any space, justify ignores all line.

Test it it works. Eduardo. Ni

edk
Posts: 382
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland
Has thanked: 110 times
Been thanked: 278 times

Post by edk » Thu Nov 29, 2018 2:31 pm

This is because HPDF_Page_TextRect can not automatically wrap lines when there is no split character in the string (space, comma). If the character string is too wide from the declared field size, then it is not printed, the function returns the PDF_STRING_OUT_OF_RANGE error.

Try using my modified command
@ <Row>, <Col> HPDFPRINT [DATE] <xData> TO <nToRow>, <nToCol>
[FONT <cFontName>]
[SIZE <nFontSize>]
[BOLD [IF lBold]]
[ITALIC [IF lItalic]]
[UNDERLINE [IF lUnderline]]
[STRIKEOUT [IF lStrikeout]]
[COLOR <aColor>]
[RIGHT | CENTER | JUSTIFY]
[WRAP]
[FONTSIZEFIT]

Using the WRAP option will wrap the line, even if there is no split character.
Using the FONTSIZEFIT option, if the content from with the declared font size does not fit into the field, will result in adjusting the font size (by reducing it), so that the entire content fits in the field. The font sizes are adjusted to the minimum size of 4.

Code: Select all

#include "hmg.ch"
#include "harupdf.ch"

************* This part of the code can be placed in hmg_hpdf.ch **************

#xcommand @ <Row> , <Col> HPDFPRINT [ DATA ] <cText> ;
	TO <ToRow> , <ToCol> ;
	[ <lfont : FONT> <cFontName> ] ;
	[ <lsize : SIZE> <nFontSize> ] ;
    [ <bold : BOLD> [ IF <lBold> ] ] ;
	[ <italic : ITALIC> [ IF <lItalic> ] ] ;
	[ <underline : UNDERLINE> [ IF <lUnderline> ] ] ;
	[ <strikeout : STRIKEOUT> [ IF <lStrikeout> ] ] ;
	[ <lcolor : COLOR> <aColor> ] ;
	[ <align:CENTER,RIGHT,JUSTIFY> ] ;
	[ <wrap : WRAP> ] ;
	[ <fontsizefit : FONTSIZEFIT> ] ;
	=> ;
	_HMG_HPDF_MULTILINE_PRINT ( <Row> , <Col> , <ToRow> , <ToCol> , <cFontName> , <nFontSize> , <aColor>\[1\] , <aColor>\[2\] , <aColor>\[3\] , <cText> , ;
		<.bold.> .AND. iif( HB_IsLogical(<lBold>), <lBold>, HB_IsNil(<lBold>) ) ,; 
		<.italic.> .AND. iif( HB_IsLogical(<lItalic>), <lItalic>, HB_IsNil(<lItalic>) ) ,;
		<.underline.> .AND. iif( HB_IsLogical(<lUnderline>), <lUnderline>, HB_IsNil(<lUnderline>) ) ,;
		<.strikeout.> .AND. iif( HB_IsLogical(<lStrikeout>), <lStrikeout>, HB_IsNil(<lStrikeout>) ) ,;
		<.lcolor.> , <.lfont.> , <.lsize.> , <"align">, <.wrap.>, <.fontsizefit.> ) 


***************  The end of this part of the code. *********************
		
Function Main()

Local cFonte1:= "Helvetica-Bold"
Local cEdit1 := "1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
Local cEdit2 := "2XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
Local cEdit3 := "3XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
Local cEdit4 := "I am thinking about whether the standard function _HMG_HPDF_MULTILINE_PRINT can be forced to transfer text to the next line "+;
			"when it does not fit in the declared width, not like now - by wrapping the text, but wrapping anywhere in the word."

SELECT HPDFDOC "sample.pdf" PAPERLENGTH 300 PAPERWIDTH 300 LOG
START HPDFDOC
	SET HPDFDOC ENCODING TO "WinAnsiEncoding"
		
	START HPDFPAGE

		@ 95.5, 11 HPDFPRINT "DESCRICAO EQUIPAMENTO: " FONT cFonte1 size 9 COLOR { 0, 0, 0 }

		@ 20, 15 HPDFPRINT RECTANGLE TO 40, 198 PENWIDTH 0.1
		@ 20, 15 HPDFPRINT cEdit1 TO 40, 198 FONT cFonte1 size 9 COLOR { 0, 0, 0 } RIGHT WRAP
		
		@ 150, 15 HPDFPRINT RECTANGLE TO 175, 198 PENWIDTH 0.1
		@ 150, 15 HPDFPRINT cEdit2 TO 175, 198 FONT cFonte1 size 9 COLOR { 0, 0, 0 } JUSTIFY WRAP
		
		@ 180, 15 HPDFPRINT RECTANGLE TO 200, 198 PENWIDTH 0.1
		@ 180, 15 HPDFPRINT cEdit3 TO 200, 198 FONT cFonte1 size 9 COLOR { 0, 0, 0 } JUSTIFY

		@ 205,120 HPDFPRINT "Standard 9px" FONT cFonte1 size 9
		
		@ 205, 15 HPDFPRINT RECTANGLE TO 215, 115 PENWIDTH 0.1
		@ 205, 15 HPDFPRINT cEdit4 TO 215, 115 FONT cFonte1 size 9 CENTER 
		
		@ 225,120 HPDFPRINT "Wrap 9px" FONT cFonte1 size 9
		
		@ 225, 15 HPDFPRINT RECTANGLE TO 235, 115 PENWIDTH 0.1
		@ 225, 15 HPDFPRINT cEdit4 TO 235, 115 FONT cFonte1 size 9 CENTER WRAP
		
		@ 245,120 HPDFPRINT "Standard + Font Size Fit" FONT cFonte1 size 9
		
		@ 245, 15 HPDFPRINT RECTANGLE TO 255, 115 PENWIDTH 0.1
		@ 245, 15 HPDFPRINT cEdit4 TO 255, 115 FONT cFonte1 size 9 CENTER FONTSIZEFIT
		
		@ 265,120 HPDFPRINT "Wrap + Font Size Fit" FONT cFonte1 size 9
		
		@ 265, 15 HPDFPRINT RECTANGLE TO 275, 115 PENWIDTH 0.1
		@ 265, 15 HPDFPRINT cEdit4 TO 275, 115 FONT cFonte1 size 9 CENTER WRAP FONTSIZEFIT
		 
	END HPDFPAGE
END HPDFDOC
Execute File 'sample.pdf'
Return Nil

************ This part of the code can be placed in h_HMG_HPDF.Prg **********
********* Change "STATIC Function _HMG_HPDF_MULTILINE_PRINT" to *************
****************** "Function _HMG_HPDF_MULTILINE_PRINT" *********************
******* Replace the existing _HMG_HPDF_MULTILINE_PRINT function *************
********************** then, HMG needs to be rebuilt ************************

STATIC Function _HMG_HPDF_MULTILINE_PRINT ( nRow, nCol, nToRow, nToCol, cFontName, nFontSize, nRColor, nGColor, nBColor, cText, lBold, lItalic, lUnderline, lStrikeout, lColor, lFont, lSize, cAlign, lWrap, lFontSizeFit )
Local nWidth := _HMG_SYSDATA[ 150 ][ 4 ]
Local nHeight := _HMG_SYSDATA[ 150 ][ 5 ]
Local nTextWidth := 0
Local nxPos := _HMG_HPDF_MM2Pixel( nCol )
Local nyPos := nHeight - _HMG_HPDF_MM2Pixel( nRow )
Local nToxPos := nxPos + _HMG_HPDF_MM2Pixel( nToCol - nCol )
Local nToyPos := nyPos - _HMG_HPDF_MM2Pixel( nToRow - nRow )
Local oFont := Nil
Local cFont := ''
Local cTtfFnt // Pablo June, 2014
Local cTextIn, cTextOut, cLine, nLineSpacingPrev, nLineSpacing, nLineCount
   
default cFontName := ''
//default nFontSize := 12
default nFontSize := _HMG_SYSDATA[ 150 ][ 9 ]
default nRColor := 0
default nGColor := 0
default nBColor := 0
default lBold := .f.
default lItalic := .f.
default lUnderline := .f.
default lStrikeout := .f.
default lColor := .f.
default lFont := .f.
default lSize := .f.
default cAlign := ''
default lWrap := .f.		
default lFontSizeFit := .f.		

cTtfFnt := cFontName // Pablo June, 2014

If _HMG_SYSDATA[ 150 ][ 1 ] == Nil // PDF object not found!
   _HMG_HPDF_Error( 3 )
   Return Nil
endif
If _HMG_SYSDATA[ 150 ][ 7 ] == Nil // PDF Page object not found!
   _HMG_HPDF_Error( 5 )
   Return Nil
endif

// set color
If lColor
   HPDF_Page_SetRGBFill( _HMG_SYSDATA[ 150 ][ 7 ], nRColor/255, nGColor/255, nBColor/255 )
else
   HPDF_Page_SetRGBFill( _HMG_SYSDATA[ 150 ][ 7 ], 0.0, 0.0, 0.0 )
endIf   

// set font
//If HMG_LEN( alltrim( cFontName ) ) == 0
//   cFontName := _HMG_HPDF_SetFont( cFontName, lBold, lItalic )
//   oFont := HPDF_GetFont( _HMG_SYSDATA[ 150 ][ 1 ], cFontName, _HMG_SYSDATA[ 150 ][ 10 ] )
//else
   // cFontName := alltrim( cFontName )
   cFontName := AllTrim(_HMG_HPDF_SetFont( cFontName, lBold, lItalic ))
   
   if HMG_UPPER (cFileExt (cFontName)) == '.TTF' // load ttf font
   
      cFont := HPDF_LOADTTFONTFROMFILE( _HMG_SYSDATA[ 150 ][ 1 ], cFontName, .t. )
      If HMG_LEN( alltrim( cFont ) ) == 0
         _HMG_HPDF_Error( 6 , cFontName )
         Return Nil
      endif
      oFont := HPDF_GetFont( _HMG_SYSDATA[ 150 ][ 1 ], cFont, _HMG_SYSDATA[ 150 ][ 10 ] )
   else
      If HMG_UPPER( alltrim( cFontName ) ) == "SYMBOL" .or. HMG_UPPER( alltrim( cFontName ) ) == "ZAPFDINGBATS"
         oFont := HPDF_GetFont( _HMG_SYSDATA[ 150 ][ 1 ], cFontName, Nil )
      else   
         oFont := HPDF_GetFont( _HMG_SYSDATA[ 150 ][ 1 ], cFontName, _HMG_SYSDATA[ 150 ][ 10 ] )
      endIf   
   endif
//endIf   
If oFont == Nil
   _HMG_HPDF_Error( 6 , cFontName )
   Return Nil
else
   nLineSpacingPrev := HPDF_Page_GetTextLeading(_HMG_SYSDATA[ 150 ][ 7 ])
   nLineSpacing := nLineSpacingPrev
   IF nLineSpacing == 0
      nLineSpacing := nFontSize * ( 1 + ( 47 / 300 ) )
   ENDIF
   
   DO WHILE .T.	//Fitting text
      HPDF_Page_SetFontAndSize( _HMG_SYSDATA[ 150 ][ 7 ], oFont, nFontSize )
      HPDF_Page_SetTextLeading(_HMG_SYSDATA[ 150 ][ 7 ], nLineSpacing )
      
      cTextIn := cText
      cTextOut := ""
      nLineCount := 0
   
      DO WHILE !EMPTY(cTextIn)
         nLineCount ++
         nLineLen := HPDF_Page_MeasureText( _HMG_SYSDATA[ 150 ][ 7 ], cTextIn, nToxPos - nxPos, !lWrap, NIL )
         IF nLineLen = 0
             EXIT
         ENDIF
         cLine := Trim( hb_USubStr( cTextIn , 1 , nLineLen ) )
         cTextIn := hb_USubStr( cTextIn, nLineLen + 1 )
         cTextOut += cLine + IF( !EMPTY( cTextIn ) , hb_eol() , "")
      ENDDO

      IF !lFontSizeFit /* "Don't fit font" */ .OR. ;
         ( nLineCount * HPDF_Page_GetTextLeading(_HMG_SYSDATA[ 150 ][ 7 ]) ) <= nyPos - nToyPos /* "Fitted" */ .OR. ;
         nFontSize <= 4 /* "Abandon further reducing the font" */	
         EXIT
      ENDIF
      nFontSize -= 0.01			 //decrease font size
      nLineSpacing := nFontSize * ( 1 + ( 47 / 300 ) ) //decrease line spacing
   ENDDO

   cText := cTextOut
   
   HPDF_Page_BeginText( _HMG_SYSDATA[ 150 ][ 7 ] )
   do case
      case HMG_UPPER( cAlign ) == 'CENTER'
         HPDF_Page_TextRect( _HMG_SYSDATA[ 150 ][ 7 ], nxPos, nyPos, nToxPos, nToyPos, cText, HPDF_TALIGN_CENTER, Nil )
      case HMG_UPPER( cAlign ) == 'RIGHT'
         HPDF_Page_TextRect( _HMG_SYSDATA[ 150 ][ 7 ], nxPos, nyPos, nToxPos, nToyPos, cText, HPDF_TALIGN_RIGHT, Nil )
      case HMG_UPPER( cAlign ) == 'JUSTIFY'
         HPDF_Page_TextRect( _HMG_SYSDATA[ 150 ][ 7 ], nxPos, nyPos, nToxPos, nToyPos, cText, HPDF_TALIGN_JUSTIFY, Nil )
      otherwise         
         HPDF_Page_TextRect( _HMG_SYSDATA[ 150 ][ 7 ], nxPos, nyPos, nToxPos, nToyPos, cText, HPDF_TALIGN_LEFT, Nil )
   endcase         
   HPDF_Page_EndText( _HMG_SYSDATA[ 150 ][ 7 ] )

   //restore previous line spacing
   HPDF_Page_SetTextLeading(_HMG_SYSDATA[ 150 ][ 7 ], nLineSpacingPrev )
   
   If lDoLog // Pablo June, 2014
     HTML_TABLE_LINE(nFHandle,{{StrZero(nRow,4,0)+" ("+StrZero(nyPos,7,2)+")","#FFFFFF",.t.},;
                               {StrZero(nCol,4,0)+" ("+StrZero(nxPos,7,2)+")","#FFFFFF",.t.},;
                         {StrZero(_HMG_SYSDATA[ 150 ][ 13 ],3,0),"#FFFFFF",.t.},;
                         {PadR(If(Empty(cTtfFnt),"<Default>",cTtfFnt),If(HMG_Len(cTtfFnt)>30,HMG_Len(cTtfFnt),30)),"#FFFFFF",.f.},;
                         {StrZero(nFontSize,2,0),"#FFFFFF",.t.},;
                         {If(lBold,"BOLD" ,Space(4))+If(lItalic," ITALIC",Space(7)),"#FFFFFF",.f.},;
                         {cFontName,If(If(Empty(cTtfFnt),HMG_Len(cFontName),HMG_Len(cTtfFnt))==HMG_Len(cFontName),"#FFFFFF","#FFFF66"),.f.}})
   Endif
endif
Return Nil
***************  The end of this part of the code. *********************
sample.pdf.png
sample.pdf.png (79.27 KiB) Viewed 362 times

User avatar
jairpinho
Posts: 251
Joined: Mon Jul 18, 2011 5:36 pm
Location: Rio Grande do Sul - Brasil
Been thanked: 5 times
Contact:

Post by jairpinho » Thu Nov 29, 2018 4:54 pm

edk wrote:
Thu Nov 29, 2018 2:31 pm
This is because HPDF_Page_TextRect can not automatically wrap lines when there is no split character in the string (space, comma). If the character string is too wide from the declared field size, then it is not printed, the function returns the PDF_STRING_OUT_OF_RANGE error.

Try using my modified command
@ <Row>, <Col> HPDFPRINT [DATE] <xData> TO <nToRow>, <nToCol>
[FONT <cFontName>]
[SIZE <nFontSize>]
[BOLD [IF lBold]]
[ITALIC [IF lItalic]]
[UNDERLINE [IF lUnderline]]
[STRIKEOUT [IF lStrikeout]]
[COLOR <aColor>]
[RIGHT | CENTER | JUSTIFY]
[WRAP]
[FONTSIZEFIT]

Using the WRAP option will wrap the line, even if there is no split character.
Using the FONTSIZEFIT option, if the content from with the declared font size does not fit into the field, will result in adjusting the font size (by reducing it), so that the entire content fits in the field. The font sizes are adjusted to the minimum size of 4.

Code: Select all

#include "hmg.ch"
#include "harupdf.ch"

************* This part of the code can be placed in hmg_hpdf.ch **************

#xcommand @ <Row> , <Col> HPDFPRINT [ DATA ] <cText> ;
	TO <ToRow> , <ToCol> ;
	[ <lfont : FONT> <cFontName> ] ;
	[ <lsize : SIZE> <nFontSize> ] ;
    [ <bold : BOLD> [ IF <lBold> ] ] ;
	[ <italic : ITALIC> [ IF <lItalic> ] ] ;
	[ <underline : UNDERLINE> [ IF <lUnderline> ] ] ;
	[ <strikeout : STRIKEOUT> [ IF <lStrikeout> ] ] ;
	[ <lcolor : COLOR> <aColor> ] ;
	[ <align:CENTER,RIGHT,JUSTIFY> ] ;
	[ <wrap : WRAP> ] ;
	[ <fontsizefit : FONTSIZEFIT> ] ;
	=> ;
	_HMG_HPDF_MULTILINE_PRINT ( <Row> , <Col> , <ToRow> , <ToCol> , <cFontName> , <nFontSize> , <aColor>\[1\] , <aColor>\[2\] , <aColor>\[3\] , <cText> , ;
		<.bold.> .AND. iif( HB_IsLogical(<lBold>), <lBold>, HB_IsNil(<lBold>) ) ,; 
		<.italic.> .AND. iif( HB_IsLogical(<lItalic>), <lItalic>, HB_IsNil(<lItalic>) ) ,;
		<.underline.> .AND. iif( HB_IsLogical(<lUnderline>), <lUnderline>, HB_IsNil(<lUnderline>) ) ,;
		<.strikeout.> .AND. iif( HB_IsLogical(<lStrikeout>), <lStrikeout>, HB_IsNil(<lStrikeout>) ) ,;
		<.lcolor.> , <.lfont.> , <.lsize.> , <"align">, <.wrap.>, <.fontsizefit.> ) 


***************  The end of this part of the code. *********************
		
Function Main()

Local cFonte1:= "Helvetica-Bold"
Local cEdit1 := "1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
Local cEdit2 := "2XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
Local cEdit3 := "3XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
Local cEdit4 := "I am thinking about whether the standard function _HMG_HPDF_MULTILINE_PRINT can be forced to transfer text to the next line "+;
			"when it does not fit in the declared width, not like now - by wrapping the text, but wrapping anywhere in the word."

SELECT HPDFDOC "sample.pdf" PAPERLENGTH 300 PAPERWIDTH 300 LOG
START HPDFDOC
	SET HPDFDOC ENCODING TO "WinAnsiEncoding"
		
	START HPDFPAGE

		@ 95.5, 11 HPDFPRINT "DESCRICAO EQUIPAMENTO: " FONT cFonte1 size 9 COLOR { 0, 0, 0 }

		@ 20, 15 HPDFPRINT RECTANGLE TO 40, 198 PENWIDTH 0.1
		@ 20, 15 HPDFPRINT cEdit1 TO 40, 198 FONT cFonte1 size 9 COLOR { 0, 0, 0 } RIGHT WRAP
		
		@ 150, 15 HPDFPRINT RECTANGLE TO 175, 198 PENWIDTH 0.1
		@ 150, 15 HPDFPRINT cEdit2 TO 175, 198 FONT cFonte1 size 9 COLOR { 0, 0, 0 } JUSTIFY WRAP
		
		@ 180, 15 HPDFPRINT RECTANGLE TO 200, 198 PENWIDTH 0.1
		@ 180, 15 HPDFPRINT cEdit3 TO 200, 198 FONT cFonte1 size 9 COLOR { 0, 0, 0 } JUSTIFY

		@ 205,120 HPDFPRINT "Standard 9px" FONT cFonte1 size 9
		
		@ 205, 15 HPDFPRINT RECTANGLE TO 215, 115 PENWIDTH 0.1
		@ 205, 15 HPDFPRINT cEdit4 TO 215, 115 FONT cFonte1 size 9 CENTER 
		
		@ 225,120 HPDFPRINT "Wrap 9px" FONT cFonte1 size 9
		
		@ 225, 15 HPDFPRINT RECTANGLE TO 235, 115 PENWIDTH 0.1
		@ 225, 15 HPDFPRINT cEdit4 TO 235, 115 FONT cFonte1 size 9 CENTER WRAP
		
		@ 245,120 HPDFPRINT "Standard + Font Size Fit" FONT cFonte1 size 9
		
		@ 245, 15 HPDFPRINT RECTANGLE TO 255, 115 PENWIDTH 0.1
		@ 245, 15 HPDFPRINT cEdit4 TO 255, 115 FONT cFonte1 size 9 CENTER FONTSIZEFIT
		
		@ 265,120 HPDFPRINT "Wrap + Font Size Fit" FONT cFonte1 size 9
		
		@ 265, 15 HPDFPRINT RECTANGLE TO 275, 115 PENWIDTH 0.1
		@ 265, 15 HPDFPRINT cEdit4 TO 275, 115 FONT cFonte1 size 9 CENTER WRAP FONTSIZEFIT
		 
	END HPDFPAGE
END HPDFDOC
Execute File 'sample.pdf'
Return Nil

************ This part of the code can be placed in h_HMG_HPDF.Prg **********
********* Change "STATIC Function _HMG_HPDF_MULTILINE_PRINT" to *************
****************** "Function _HMG_HPDF_MULTILINE_PRINT" *********************
******* Replace the existing _HMG_HPDF_MULTILINE_PRINT function *************
********************** then, HMG needs to be rebuilt ************************

STATIC Function _HMG_HPDF_MULTILINE_PRINT ( nRow, nCol, nToRow, nToCol, cFontName, nFontSize, nRColor, nGColor, nBColor, cText, lBold, lItalic, lUnderline, lStrikeout, lColor, lFont, lSize, cAlign, lWrap, lFontSizeFit )
Local nWidth := _HMG_SYSDATA[ 150 ][ 4 ]
Local nHeight := _HMG_SYSDATA[ 150 ][ 5 ]
Local nTextWidth := 0
Local nxPos := _HMG_HPDF_MM2Pixel( nCol )
Local nyPos := nHeight - _HMG_HPDF_MM2Pixel( nRow )
Local nToxPos := nxPos + _HMG_HPDF_MM2Pixel( nToCol - nCol )
Local nToyPos := nyPos - _HMG_HPDF_MM2Pixel( nToRow - nRow )
Local oFont := Nil
Local cFont := ''
Local cTtfFnt // Pablo June, 2014
Local cTextIn, cTextOut, cLine, nLineSpacingPrev, nLineSpacing, nLineCount
   
default cFontName := ''
//default nFontSize := 12
default nFontSize := _HMG_SYSDATA[ 150 ][ 9 ]
default nRColor := 0
default nGColor := 0
default nBColor := 0
default lBold := .f.
default lItalic := .f.
default lUnderline := .f.
default lStrikeout := .f.
default lColor := .f.
default lFont := .f.
default lSize := .f.
default cAlign := ''
default lWrap := .f.		
default lFontSizeFit := .f.		

cTtfFnt := cFontName // Pablo June, 2014

If _HMG_SYSDATA[ 150 ][ 1 ] == Nil // PDF object not found!
   _HMG_HPDF_Error( 3 )
   Return Nil
endif
If _HMG_SYSDATA[ 150 ][ 7 ] == Nil // PDF Page object not found!
   _HMG_HPDF_Error( 5 )
   Return Nil
endif

// set color
If lColor
   HPDF_Page_SetRGBFill( _HMG_SYSDATA[ 150 ][ 7 ], nRColor/255, nGColor/255, nBColor/255 )
else
   HPDF_Page_SetRGBFill( _HMG_SYSDATA[ 150 ][ 7 ], 0.0, 0.0, 0.0 )
endIf   

// set font
//If HMG_LEN( alltrim( cFontName ) ) == 0
//   cFontName := _HMG_HPDF_SetFont( cFontName, lBold, lItalic )
//   oFont := HPDF_GetFont( _HMG_SYSDATA[ 150 ][ 1 ], cFontName, _HMG_SYSDATA[ 150 ][ 10 ] )
//else
   // cFontName := alltrim( cFontName )
   cFontName := AllTrim(_HMG_HPDF_SetFont( cFontName, lBold, lItalic ))
   
   if HMG_UPPER (cFileExt (cFontName)) == '.TTF' // load ttf font
   
      cFont := HPDF_LOADTTFONTFROMFILE( _HMG_SYSDATA[ 150 ][ 1 ], cFontName, .t. )
      If HMG_LEN( alltrim( cFont ) ) == 0
         _HMG_HPDF_Error( 6 , cFontName )
         Return Nil
      endif
      oFont := HPDF_GetFont( _HMG_SYSDATA[ 150 ][ 1 ], cFont, _HMG_SYSDATA[ 150 ][ 10 ] )
   else
      If HMG_UPPER( alltrim( cFontName ) ) == "SYMBOL" .or. HMG_UPPER( alltrim( cFontName ) ) == "ZAPFDINGBATS"
         oFont := HPDF_GetFont( _HMG_SYSDATA[ 150 ][ 1 ], cFontName, Nil )
      else   
         oFont := HPDF_GetFont( _HMG_SYSDATA[ 150 ][ 1 ], cFontName, _HMG_SYSDATA[ 150 ][ 10 ] )
      endIf   
   endif
//endIf   
If oFont == Nil
   _HMG_HPDF_Error( 6 , cFontName )
   Return Nil
else
   nLineSpacingPrev := HPDF_Page_GetTextLeading(_HMG_SYSDATA[ 150 ][ 7 ])
   nLineSpacing := nLineSpacingPrev
   IF nLineSpacing == 0
      nLineSpacing := nFontSize * ( 1 + ( 47 / 300 ) )
   ENDIF
   
   DO WHILE .T.	//Fitting text
      HPDF_Page_SetFontAndSize( _HMG_SYSDATA[ 150 ][ 7 ], oFont, nFontSize )
      HPDF_Page_SetTextLeading(_HMG_SYSDATA[ 150 ][ 7 ], nLineSpacing )
      
      cTextIn := cText
      cTextOut := ""
      nLineCount := 0
   
      DO WHILE !EMPTY(cTextIn)
         nLineCount ++
         nLineLen := HPDF_Page_MeasureText( _HMG_SYSDATA[ 150 ][ 7 ], cTextIn, nToxPos - nxPos, !lWrap, NIL )
         IF nLineLen = 0
             EXIT
         ENDIF
         cLine := Trim( hb_USubStr( cTextIn , 1 , nLineLen ) )
         cTextIn := hb_USubStr( cTextIn, nLineLen + 1 )
         cTextOut += cLine + IF( !EMPTY( cTextIn ) , hb_eol() , "")
      ENDDO

      IF !lFontSizeFit /* "Don't fit font" */ .OR. ;
         ( nLineCount * HPDF_Page_GetTextLeading(_HMG_SYSDATA[ 150 ][ 7 ]) ) <= nyPos - nToyPos /* "Fitted" */ .OR. ;
         nFontSize <= 4 /* "Abandon further reducing the font" */	
         EXIT
      ENDIF
      nFontSize -= 0.01			 //decrease font size
      nLineSpacing := nFontSize * ( 1 + ( 47 / 300 ) ) //decrease line spacing
   ENDDO

   cText := cTextOut
   
   HPDF_Page_BeginText( _HMG_SYSDATA[ 150 ][ 7 ] )
   do case
      case HMG_UPPER( cAlign ) == 'CENTER'
         HPDF_Page_TextRect( _HMG_SYSDATA[ 150 ][ 7 ], nxPos, nyPos, nToxPos, nToyPos, cText, HPDF_TALIGN_CENTER, Nil )
      case HMG_UPPER( cAlign ) == 'RIGHT'
         HPDF_Page_TextRect( _HMG_SYSDATA[ 150 ][ 7 ], nxPos, nyPos, nToxPos, nToyPos, cText, HPDF_TALIGN_RIGHT, Nil )
      case HMG_UPPER( cAlign ) == 'JUSTIFY'
         HPDF_Page_TextRect( _HMG_SYSDATA[ 150 ][ 7 ], nxPos, nyPos, nToxPos, nToyPos, cText, HPDF_TALIGN_JUSTIFY, Nil )
      otherwise         
         HPDF_Page_TextRect( _HMG_SYSDATA[ 150 ][ 7 ], nxPos, nyPos, nToxPos, nToyPos, cText, HPDF_TALIGN_LEFT, Nil )
   endcase         
   HPDF_Page_EndText( _HMG_SYSDATA[ 150 ][ 7 ] )

   //restore previous line spacing
   HPDF_Page_SetTextLeading(_HMG_SYSDATA[ 150 ][ 7 ], nLineSpacingPrev )
   
   If lDoLog // Pablo June, 2014
     HTML_TABLE_LINE(nFHandle,{{StrZero(nRow,4,0)+" ("+StrZero(nyPos,7,2)+")","#FFFFFF",.t.},;
                               {StrZero(nCol,4,0)+" ("+StrZero(nxPos,7,2)+")","#FFFFFF",.t.},;
                         {StrZero(_HMG_SYSDATA[ 150 ][ 13 ],3,0),"#FFFFFF",.t.},;
                         {PadR(If(Empty(cTtfFnt),"<Default>",cTtfFnt),If(HMG_Len(cTtfFnt)>30,HMG_Len(cTtfFnt),30)),"#FFFFFF",.f.},;
                         {StrZero(nFontSize,2,0),"#FFFFFF",.t.},;
                         {If(lBold,"BOLD" ,Space(4))+If(lItalic," ITALIC",Space(7)),"#FFFFFF",.f.},;
                         {cFontName,If(If(Empty(cTtfFnt),HMG_Len(cFontName),HMG_Len(cTtfFnt))==HMG_Len(cFontName),"#FFFFFF","#FFFF66"),.f.}})
   Endif
endif
Return Nil
***************  The end of this part of the code. *********************
sample.pdf.png


Thank you Edk, exactly this.
Jair Pinho
HMG ALTA REVOLUÇÃO xBASE
HMG xBASE REVOLUTION HIGH
http://www.hmgforum.com.br

User avatar
susviela
Posts: 7
Joined: Wed Oct 17, 2018 4:44 am
DBs Used: DBF, PostgreSql, SQLite
Has thanked: 4 times
Contact:

Post by susviela » Thu Nov 29, 2018 5:18 pm

Gaúcho, te mandei msg no PV ...

User avatar
jairpinho
Posts: 251
Joined: Mon Jul 18, 2011 5:36 pm
Location: Rio Grande do Sul - Brasil
Been thanked: 5 times
Contact:

Post by jairpinho » Thu Nov 29, 2018 5:31 pm

edk wrote:
Thu Nov 29, 2018 2:31 pm
This is because HPDF_Page_TextRect can not automatically wrap lines when there is no split character in the string (space, comma). If the character string is too wide from the declared field size, then it is not printed, the function returns the PDF_STRING_OUT_OF_RANGE error.

Try using my modified command
@ <Row>, <Col> HPDFPRINT [DATE] <xData> TO <nToRow>, <nToCol>
[FONT <cFontName>]
[SIZE <nFontSize>]
[BOLD [IF lBold]]
[ITALIC [IF lItalic]]
[UNDERLINE [IF lUnderline]]
[STRIKEOUT [IF lStrikeout]]
[COLOR <aColor>]
[RIGHT | CENTER | JUSTIFY]
[WRAP]
[FONTSIZEFIT]

Using the WRAP option will wrap the line, even if there is no split character.
Using the FONTSIZEFIT option, if the content from with the declared font size does not fit into the field, will result in adjusting the font size (by reducing it), so that the entire content fits in the field. The font sizes are adjusted to the minimum size of 4.

Code: Select all

#include "hmg.ch"
#include "harupdf.ch"

************* This part of the code can be placed in hmg_hpdf.ch **************

#xcommand @ <Row> , <Col> HPDFPRINT [ DATA ] <cText> ;
	TO <ToRow> , <ToCol> ;
	[ <lfont : FONT> <cFontName> ] ;
	[ <lsize : SIZE> <nFontSize> ] ;
    [ <bold : BOLD> [ IF <lBold> ] ] ;
	[ <italic : ITALIC> [ IF <lItalic> ] ] ;
	[ <underline : UNDERLINE> [ IF <lUnderline> ] ] ;
	[ <strikeout : STRIKEOUT> [ IF <lStrikeout> ] ] ;
	[ <lcolor : COLOR> <aColor> ] ;
	[ <align:CENTER,RIGHT,JUSTIFY> ] ;
	[ <wrap : WRAP> ] ;
	[ <fontsizefit : FONTSIZEFIT> ] ;
	=> ;
	_HMG_HPDF_MULTILINE_PRINT ( <Row> , <Col> , <ToRow> , <ToCol> , <cFontName> , <nFontSize> , <aColor>\[1\] , <aColor>\[2\] , <aColor>\[3\] , <cText> , ;
		<.bold.> .AND. iif( HB_IsLogical(<lBold>), <lBold>, HB_IsNil(<lBold>) ) ,; 
		<.italic.> .AND. iif( HB_IsLogical(<lItalic>), <lItalic>, HB_IsNil(<lItalic>) ) ,;
		<.underline.> .AND. iif( HB_IsLogical(<lUnderline>), <lUnderline>, HB_IsNil(<lUnderline>) ) ,;
		<.strikeout.> .AND. iif( HB_IsLogical(<lStrikeout>), <lStrikeout>, HB_IsNil(<lStrikeout>) ) ,;
		<.lcolor.> , <.lfont.> , <.lsize.> , <"align">, <.wrap.>, <.fontsizefit.> ) 


***************  The end of this part of the code. *********************
		
Function Main()

Local cFonte1:= "Helvetica-Bold"
Local cEdit1 := "1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
Local cEdit2 := "2XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
Local cEdit3 := "3XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
Local cEdit4 := "I am thinking about whether the standard function _HMG_HPDF_MULTILINE_PRINT can be forced to transfer text to the next line "+;
			"when it does not fit in the declared width, not like now - by wrapping the text, but wrapping anywhere in the word."

SELECT HPDFDOC "sample.pdf" PAPERLENGTH 300 PAPERWIDTH 300 LOG
START HPDFDOC
	SET HPDFDOC ENCODING TO "WinAnsiEncoding"
		
	START HPDFPAGE

		@ 95.5, 11 HPDFPRINT "DESCRICAO EQUIPAMENTO: " FONT cFonte1 size 9 COLOR { 0, 0, 0 }

		@ 20, 15 HPDFPRINT RECTANGLE TO 40, 198 PENWIDTH 0.1
		@ 20, 15 HPDFPRINT cEdit1 TO 40, 198 FONT cFonte1 size 9 COLOR { 0, 0, 0 } RIGHT WRAP
		
		@ 150, 15 HPDFPRINT RECTANGLE TO 175, 198 PENWIDTH 0.1
		@ 150, 15 HPDFPRINT cEdit2 TO 175, 198 FONT cFonte1 size 9 COLOR { 0, 0, 0 } JUSTIFY WRAP
		
		@ 180, 15 HPDFPRINT RECTANGLE TO 200, 198 PENWIDTH 0.1
		@ 180, 15 HPDFPRINT cEdit3 TO 200, 198 FONT cFonte1 size 9 COLOR { 0, 0, 0 } JUSTIFY

		@ 205,120 HPDFPRINT "Standard 9px" FONT cFonte1 size 9
		
		@ 205, 15 HPDFPRINT RECTANGLE TO 215, 115 PENWIDTH 0.1
		@ 205, 15 HPDFPRINT cEdit4 TO 215, 115 FONT cFonte1 size 9 CENTER 
		
		@ 225,120 HPDFPRINT "Wrap 9px" FONT cFonte1 size 9
		
		@ 225, 15 HPDFPRINT RECTANGLE TO 235, 115 PENWIDTH 0.1
		@ 225, 15 HPDFPRINT cEdit4 TO 235, 115 FONT cFonte1 size 9 CENTER WRAP
		
		@ 245,120 HPDFPRINT "Standard + Font Size Fit" FONT cFonte1 size 9
		
		@ 245, 15 HPDFPRINT RECTANGLE TO 255, 115 PENWIDTH 0.1
		@ 245, 15 HPDFPRINT cEdit4 TO 255, 115 FONT cFonte1 size 9 CENTER FONTSIZEFIT
		
		@ 265,120 HPDFPRINT "Wrap + Font Size Fit" FONT cFonte1 size 9
		
		@ 265, 15 HPDFPRINT RECTANGLE TO 275, 115 PENWIDTH 0.1
		@ 265, 15 HPDFPRINT cEdit4 TO 275, 115 FONT cFonte1 size 9 CENTER WRAP FONTSIZEFIT
		 
	END HPDFPAGE
END HPDFDOC
Execute File 'sample.pdf'
Return Nil

************ This part of the code can be placed in h_HMG_HPDF.Prg **********
********* Change "STATIC Function _HMG_HPDF_MULTILINE_PRINT" to *************
****************** "Function _HMG_HPDF_MULTILINE_PRINT" *********************
******* Replace the existing _HMG_HPDF_MULTILINE_PRINT function *************
********************** then, HMG needs to be rebuilt ************************

STATIC Function _HMG_HPDF_MULTILINE_PRINT ( nRow, nCol, nToRow, nToCol, cFontName, nFontSize, nRColor, nGColor, nBColor, cText, lBold, lItalic, lUnderline, lStrikeout, lColor, lFont, lSize, cAlign, lWrap, lFontSizeFit )
Local nWidth := _HMG_SYSDATA[ 150 ][ 4 ]
Local nHeight := _HMG_SYSDATA[ 150 ][ 5 ]
Local nTextWidth := 0
Local nxPos := _HMG_HPDF_MM2Pixel( nCol )
Local nyPos := nHeight - _HMG_HPDF_MM2Pixel( nRow )
Local nToxPos := nxPos + _HMG_HPDF_MM2Pixel( nToCol - nCol )
Local nToyPos := nyPos - _HMG_HPDF_MM2Pixel( nToRow - nRow )
Local oFont := Nil
Local cFont := ''
Local cTtfFnt // Pablo June, 2014
Local cTextIn, cTextOut, cLine, nLineSpacingPrev, nLineSpacing, nLineCount
   
default cFontName := ''
//default nFontSize := 12
default nFontSize := _HMG_SYSDATA[ 150 ][ 9 ]
default nRColor := 0
default nGColor := 0
default nBColor := 0
default lBold := .f.
default lItalic := .f.
default lUnderline := .f.
default lStrikeout := .f.
default lColor := .f.
default lFont := .f.
default lSize := .f.
default cAlign := ''
default lWrap := .f.		
default lFontSizeFit := .f.		

cTtfFnt := cFontName // Pablo June, 2014

If _HMG_SYSDATA[ 150 ][ 1 ] == Nil // PDF object not found!
   _HMG_HPDF_Error( 3 )
   Return Nil
endif
If _HMG_SYSDATA[ 150 ][ 7 ] == Nil // PDF Page object not found!
   _HMG_HPDF_Error( 5 )
   Return Nil
endif

// set color
If lColor
   HPDF_Page_SetRGBFill( _HMG_SYSDATA[ 150 ][ 7 ], nRColor/255, nGColor/255, nBColor/255 )
else
   HPDF_Page_SetRGBFill( _HMG_SYSDATA[ 150 ][ 7 ], 0.0, 0.0, 0.0 )
endIf   

// set font
//If HMG_LEN( alltrim( cFontName ) ) == 0
//   cFontName := _HMG_HPDF_SetFont( cFontName, lBold, lItalic )
//   oFont := HPDF_GetFont( _HMG_SYSDATA[ 150 ][ 1 ], cFontName, _HMG_SYSDATA[ 150 ][ 10 ] )
//else
   // cFontName := alltrim( cFontName )
   cFontName := AllTrim(_HMG_HPDF_SetFont( cFontName, lBold, lItalic ))
   
   if HMG_UPPER (cFileExt (cFontName)) == '.TTF' // load ttf font
   
      cFont := HPDF_LOADTTFONTFROMFILE( _HMG_SYSDATA[ 150 ][ 1 ], cFontName, .t. )
      If HMG_LEN( alltrim( cFont ) ) == 0
         _HMG_HPDF_Error( 6 , cFontName )
         Return Nil
      endif
      oFont := HPDF_GetFont( _HMG_SYSDATA[ 150 ][ 1 ], cFont, _HMG_SYSDATA[ 150 ][ 10 ] )
   else
      If HMG_UPPER( alltrim( cFontName ) ) == "SYMBOL" .or. HMG_UPPER( alltrim( cFontName ) ) == "ZAPFDINGBATS"
         oFont := HPDF_GetFont( _HMG_SYSDATA[ 150 ][ 1 ], cFontName, Nil )
      else   
         oFont := HPDF_GetFont( _HMG_SYSDATA[ 150 ][ 1 ], cFontName, _HMG_SYSDATA[ 150 ][ 10 ] )
      endIf   
   endif
//endIf   
If oFont == Nil
   _HMG_HPDF_Error( 6 , cFontName )
   Return Nil
else
   nLineSpacingPrev := HPDF_Page_GetTextLeading(_HMG_SYSDATA[ 150 ][ 7 ])
   nLineSpacing := nLineSpacingPrev
   IF nLineSpacing == 0
      nLineSpacing := nFontSize * ( 1 + ( 47 / 300 ) )
   ENDIF
   
   DO WHILE .T.	//Fitting text
      HPDF_Page_SetFontAndSize( _HMG_SYSDATA[ 150 ][ 7 ], oFont, nFontSize )
      HPDF_Page_SetTextLeading(_HMG_SYSDATA[ 150 ][ 7 ], nLineSpacing )
      
      cTextIn := cText
      cTextOut := ""
      nLineCount := 0
   
      DO WHILE !EMPTY(cTextIn)
         nLineCount ++
         nLineLen := HPDF_Page_MeasureText( _HMG_SYSDATA[ 150 ][ 7 ], cTextIn, nToxPos - nxPos, !lWrap, NIL )
         IF nLineLen = 0
             EXIT
         ENDIF
         cLine := Trim( hb_USubStr( cTextIn , 1 , nLineLen ) )
         cTextIn := hb_USubStr( cTextIn, nLineLen + 1 )
         cTextOut += cLine + IF( !EMPTY( cTextIn ) , hb_eol() , "")
      ENDDO

      IF !lFontSizeFit /* "Don't fit font" */ .OR. ;
         ( nLineCount * HPDF_Page_GetTextLeading(_HMG_SYSDATA[ 150 ][ 7 ]) ) <= nyPos - nToyPos /* "Fitted" */ .OR. ;
         nFontSize <= 4 /* "Abandon further reducing the font" */	
         EXIT
      ENDIF
      nFontSize -= 0.01			 //decrease font size
      nLineSpacing := nFontSize * ( 1 + ( 47 / 300 ) ) //decrease line spacing
   ENDDO

   cText := cTextOut
   
   HPDF_Page_BeginText( _HMG_SYSDATA[ 150 ][ 7 ] )
   do case
      case HMG_UPPER( cAlign ) == 'CENTER'
         HPDF_Page_TextRect( _HMG_SYSDATA[ 150 ][ 7 ], nxPos, nyPos, nToxPos, nToyPos, cText, HPDF_TALIGN_CENTER, Nil )
      case HMG_UPPER( cAlign ) == 'RIGHT'
         HPDF_Page_TextRect( _HMG_SYSDATA[ 150 ][ 7 ], nxPos, nyPos, nToxPos, nToyPos, cText, HPDF_TALIGN_RIGHT, Nil )
      case HMG_UPPER( cAlign ) == 'JUSTIFY'
         HPDF_Page_TextRect( _HMG_SYSDATA[ 150 ][ 7 ], nxPos, nyPos, nToxPos, nToyPos, cText, HPDF_TALIGN_JUSTIFY, Nil )
      otherwise         
         HPDF_Page_TextRect( _HMG_SYSDATA[ 150 ][ 7 ], nxPos, nyPos, nToxPos, nToyPos, cText, HPDF_TALIGN_LEFT, Nil )
   endcase         
   HPDF_Page_EndText( _HMG_SYSDATA[ 150 ][ 7 ] )

   //restore previous line spacing
   HPDF_Page_SetTextLeading(_HMG_SYSDATA[ 150 ][ 7 ], nLineSpacingPrev )
   
   If lDoLog // Pablo June, 2014
     HTML_TABLE_LINE(nFHandle,{{StrZero(nRow,4,0)+" ("+StrZero(nyPos,7,2)+")","#FFFFFF",.t.},;
                               {StrZero(nCol,4,0)+" ("+StrZero(nxPos,7,2)+")","#FFFFFF",.t.},;
                         {StrZero(_HMG_SYSDATA[ 150 ][ 13 ],3,0),"#FFFFFF",.t.},;
                         {PadR(If(Empty(cTtfFnt),"<Default>",cTtfFnt),If(HMG_Len(cTtfFnt)>30,HMG_Len(cTtfFnt),30)),"#FFFFFF",.f.},;
                         {StrZero(nFontSize,2,0),"#FFFFFF",.t.},;
                         {If(lBold,"BOLD" ,Space(4))+If(lItalic," ITALIC",Space(7)),"#FFFFFF",.f.},;
                         {cFontName,If(If(Empty(cTtfFnt),HMG_Len(cFontName),HMG_Len(cTtfFnt))==HMG_Len(cFontName),"#FFFFFF","#FFFF66"),.f.}})
   Endif
endif
Return Nil
***************  The end of this part of the code. *********************
sample.pdf.png


I did the recompilei procedure but did not generate the lib there was error follow the error, could explain in detail step by step what to do in the files maybe I did something wrong
hpdf.png
hpdf.png (19.55 KiB) Viewed 336 times
Jair Pinho
HMG ALTA REVOLUÇÃO xBASE
HMG xBASE REVOLUTION HIGH
http://www.hmgforum.com.br

edk
Posts: 382
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland
Has thanked: 110 times
Been thanked: 278 times

Post by edk » Thu Nov 29, 2018 6:35 pm

jairpinho wrote:
Thu Nov 29, 2018 5:31 pm
I did the recompilei procedure but did not generate the lib there was error follow the error, could explain in detail step by step what to do in the files maybe I did something wrong

hpdf.png
I forgot to declare nLineLen variable, sorry. :oops:
Try to add: Local nLineLen

To reduce the number of loops performed when determining the font size, you can replace the line:

Code: Select all

nFontSize -= 0.01 
with

Code: Select all

nFontSize -= 0.1
To work properly text alignment (justification) change the line:

Code: Select all

cTextOut += cLine + IF( !EMPTY( cTextIn ) , hb_eol() , "")
to

Code: Select all

cTextOut += cLine + IF( !EMPTY( cTextIn ) , " " , "")

User avatar
jairpinho
Posts: 251
Joined: Mon Jul 18, 2011 5:36 pm
Location: Rio Grande do Sul - Brasil
Been thanked: 5 times
Contact:

Post by jairpinho » Fri Nov 30, 2018 4:05 pm

edk wrote:
Thu Nov 29, 2018 6:35 pm
jairpinho wrote:
Thu Nov 29, 2018 5:31 pm
I did the recompilei procedure but did not generate the lib there was error follow the error, could explain in detail step by step what to do in the files maybe I did something wrong

hpdf.png
I forgot to declare nLineLen variable, sorry. :oops:
Try to add: Local nLineLen

To reduce the number of loops performed when determining the font size, you can replace the line:

Code: Select all

nFontSize -= 0.01 
with

Code: Select all

nFontSize -= 0.1
To work properly text alignment (justification) change the line:

Code: Select all

cTextOut += cLine + IF( !EMPTY( cTextIn ) , hb_eol() , "")
to

Code: Select all

cTextOut += cLine + IF( !EMPTY( cTextIn ) , " " , "")

thank you edk, this change and very important to generate reports, worked perfect.

I have another question that you could help I use HPDFPRINT TO to generate a budget table, but some materials have larger texts than others, how can I know the correct height of each text and put in "TO" so each grid line is the same size according to the text of the description.

http://www.hmgforum.com/viewtopic.php?f=5&t=5842
Jair Pinho
HMG ALTA REVOLUÇÃO xBASE
HMG xBASE REVOLUTION HIGH
http://www.hmgforum.com.br

edk
Posts: 382
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland
Has thanked: 110 times
Been thanked: 278 times

Post by edk » Sat Dec 01, 2018 12:11 am

Try this with: http://www.hmgforum.com/viewtopic.php?p=54473#p54473
Tip: Split the string into lines so that each line does not exceed the desired length.

User avatar
jairpinho
Posts: 251
Joined: Mon Jul 18, 2011 5:36 pm
Location: Rio Grande do Sul - Brasil
Been thanked: 5 times
Contact:

Post by jairpinho » Sun Dec 02, 2018 6:56 pm

edk wrote:
Sat Dec 01, 2018 12:11 am
Try this with: http://www.hmgforum.com/viewtopic.php?p=54473#p54473
Tip: Split the string into lines so that each line does not exceed the desired length.
need to know what exact value of all rows to add in to heightlines

@ F, 35 HPDFPRINT cDescricao to F+nDesc_size, 150
Jair Pinho
HMG ALTA REVOLUÇÃO xBASE
HMG xBASE REVOLUTION HIGH
http://www.hmgforum.com.br

Post Reply