pdf grid

Moderator: Rathinagiri

edk
Posts: 164
Joined: Thu Oct 16, 2014 11:35 am
DBs Used: DBF
Location: Poland
Has thanked: 43 times
Been thanked: 96 times

Re: pdf grid

Post by edk » Fri Oct 06, 2017 3:59 pm

It should be in Ansi.
I think Jair was about the word "Mínimo:" as UTF8 in prg, which show as "MÃ-nimo" in PDF Ansi.
In the example I showed both words.
If you save prg in UTF8, then in PDF you will see MÃ-nimo instead of Mínimo (second word)

Maybe this will be helpful for PDF in UTF8 https://github.com/libharu/libharu/issues/27

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

Post by jairpinho » Fri Oct 06, 2017 7:26 pm

edk wrote:
Fri Oct 06, 2017 2:21 pm
I don't see the problem with accents:

Code: Select all

#include "hmg.ch"

Function Main()
Local i

SELECT HPDFDOC "sample.pdf" ORIENTATION HPDF_ORIENT_LANDSCAPE PAPERSIZE HPDF_PAPER_A4
SET HPDFDOC ENCODING TO "WinAnsiEncoding"
START HPDFDOC
    START HPDFPAGE

     print_grid( 400, 150, 160, 200, 5, 5, 20 , 20 , 10 , 10 )
     HPDF_RotateTextPx( 510, 200, 'MĂ-nimo: 119 -> "Mínimo: "', Nil, 7, 90 , , , , 'T' )  //units: pixels

     
     
    END HPDFPAGE
        

END HPDFDOC

Execute File 'sample.pdf'
Return Nil
*******************************
PROCEDURE HPDF_RotateTextPx( nRow, nCol, cTxt, cFont, nFontSize, nAngle, lBold, lItalic, aColors, cAlign)
* Rotating text

   Local nRad, nTextWidth, oFont, cFnt
   
   Local hPdf        := _HMG_SYSDATA[ 150 ][ 1 ]
   Local hPage       := _HMG_SYSDATA[ 150 ][ 7 ]
   Local cPdfEnc     := _HMG_SYSDATA[ 150 ][ 10 ]

   Local nWidth      := _HMG_SYSDATA[ 150 ][ 4 ]
   Local nHeight     := _HMG_SYSDATA[ 150 ][ 5 ]
   Local nxPos       := nCol
   Local nyPos       := nRow

   DEFAULT cFont       := "Helvetica"
   DEFAULT nFontSize   := 12   
   DEFAULT cTXt        := ""
   DEFAULT nAngle      := 0
   DEFAULT lBold       := .F.
   DEFAULT lItalic     := .F.
   DEFAULT aColors     := { 0, 0, 0}
   DEFAULT cAlign      :=""		//Empty - Left and bottom, R - Right, C - Center, T - Top, M - Middle

   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

   
   IF VALTYPE(cAlign)#'C' 
      cAlign := ''		//Left as default
   ENDIF
   
   
   // set color
   If VALTYPE( aColors )#'A' .OR. LEN( aColors )#3 .OR. ;
      VALTYPE( aColors[1] )#'N' .OR. VALTYPE( aColors[2] )#'N' .OR. VALTYPE( aColors[3] )#'N' .OR. ;
      aColors[1]<0 .OR. aColors[1]>255 .OR. ;
      aColors[2]<0 .OR. aColors[2]>255 .OR. ;
      aColors[3]<0 .OR. aColors[3]>255
      
      aColors     := { 0, 0, 0}
   Endif 
   HPDF_Page_SetRGBFill( hPage, aColors[1]/255, aColors[2]/255, aColors[3]/255 )   

   // set font
   If HMG_LEN( AllTrim( cFont ) ) == 0
      cFont := _HMG_HPDF_SetFont( cFont, lBold, lItalic )
      oFont := HPDF_GetFont( hPdf, cFont, cPdfEnc )

   else

      cFont := AllTrim(_HMG_HPDF_SetFont( cFont, lBold, lItalic ))
    
      if HMG_UPPER (cFileExt (cFont)) == '.TTF' // load ttf font
   
         cFnt := HPDF_LOADTTFONTFROMFILE( hPdf, cFont, .t. )

         If HMG_LEN( Alltrim( cFnt ) ) == 0
            _HMG_HPDF_Error( 6 , cFont )
            Return Nil
         endif

         oFont := HPDF_GetFont( hPdf, cFnt, cPdfEnc )
     
      else
     
         If HMG_UPPER( alltrim( cFont ) ) == "SYMBOL" .or. HMG_UPPER( alltrim( cFont ) ) == "ZAPFDINGBATS"
            oFont := HPDF_GetFont( hPdf, cFont, Nil )
         else   
            oFont := HPDF_GetFont( hPdf, cFont, cPdfEnc )
         endIf
   
      endif

   endIf
   
   If oFont == Nil
      _HMG_HPDF_Error( 6 , cFont )
      Return Nil
   Endif

   HPDF_Page_SetFontAndSize( hPage, oFont, nFontSize )
   nTextWidth := HPDF_Page_TextWidth( hPage, cTxt )
   
   nRad := nAngle / 180 * 3.141592 	//radian value
   
   //calculate nxPos
   IF 'R'$HMG_UPPER(cAlign)		//Right
      nxPos:=nxPos - (nTextWidth* cos (nRad))
   ELSEIF 'C'$HMG_UPPER(cAlign)	//Center
   	 nxPos:=nxPos - ((nTextWidth* cos (nRad))/2)
   ENDIF
   
   //calculate nyPos
   IF 'T'$HMG_UPPER(cAlign)		//Top
      nyPos:=nyPos - (nTextWidth* sin (nRad))
   ELSEIF 'M'$HMG_UPPER(cAlign)	//Middle
   	 nyPos:=nyPos - ((nTextWidth* sin (nRad))/2)
   ENDIF
 
   HPDF_Page_BeginText( hPage )
   HPDF_Page_SetTextMatrix ( hPage, cos ( nRad ), sin ( nRad ), -sin ( nRad ), cos ( nRad ), nxPos , nyPos)
   HPDF_Page_ShowText( hPage, cTxt )
   HPDF_Page_EndText( hPage )

RETURN

*------------------------------------------------------------------------*
Function print_grid( nRow, nCol, height, width, nScaleLine_X, nScaleLine_Y, nScaleText_X, nScaleText_Y, nTag_x, nTag_Y )
*------------------------------------------------------------------------*
   Local  font,x,y, cLabel, nLabWidth
   Local Pdf        := _HMG_SYSDATA[ 150 ][ 1 ]
   Local Page       := _HMG_SYSDATA[ 150 ][ 7 ]  
   Local cPdfEnc    := _HMG_SYSDATA[ 150 ][ 10 ]

   Local nFontSize   := 5

    font := HPDF_GetFont (pdf, "Helvetica", cPdfEnc)

    HPDF_Page_SetFontAndSize (page, font, nFontSize)
    HPDF_Page_SetGrayFill (page, 0.5)
    HPDF_Page_SetGrayStroke (page, 0.8)


    /* Draw horizontal lines */
    y := 0 // distabcia inicio primeira linha
    while (y <= height )
        if  (y % (nScaleLine_Y*2) == 0)
            HPDF_Page_SetLineWidth (page, 0.5)
        else
           if (HPDF_Page_GetLineWidth (page) != 0.25)
              HPDF_Page_SetLineWidth (page, 0.25)
           Endif
        Endif

        HPDF_Page_MoveTo (page, nCol, y + nRow)
        HPDF_Page_LineTo (page, width + nCol, y + nRow)
        HPDF_Page_Stroke (page)

        if (y % nTag_Y == 0 .and. y > 0)
            HPDF_Page_SetGrayStroke (page, 0.5)

            HPDF_Page_MoveTo (page, nCol, y + nRow)
            HPDF_Page_LineTo (page, nScaleLine_Y + nCol , y + nRow)
            HPDF_Page_Stroke (page)

            HPDF_Page_SetGrayStroke (page, 0.8)
        Endif

        y += nScaleLine_Y
    End

    /* Draw vertical lines */



    x := 0 //distabcia inicio primeira linha
    while (x <= width)
        if (x % (nScaleLine_X*2) == 0)
            HPDF_Page_SetLineWidth (page, 0.5)
        else
            if (HPDF_Page_GetLineWidth (page) != 0.25)
                HPDF_Page_SetLineWidth (page, 0.25)
            Endif
        Endif

        HPDF_Page_MoveTo (page, x + nCol, nRow)
        HPDF_Page_LineTo (page, x + nCol, height + nRow)
        HPDF_Page_Stroke (page)

        if (x % nTag_X == 0 .and. x > 0)  // linha de referencia com a tag texto linha mais forte
            HPDF_Page_SetGrayStroke (page, 0.5)

            //tag esquerda
	    HPDF_Page_MoveTo (page, x + nCol, nRow)
            HPDF_Page_LineTo (page, x + nCol, nScaleLine_X + nRow )
            HPDF_Page_Stroke (page)

            //tag direita
	    HPDF_Page_MoveTo (page, x + nCol, height + nRow)
            HPDF_Page_LineTo (page, x + nCol, height - nScaleLine_X + nRow)
            HPDF_Page_Stroke (page)

            HPDF_Page_SetGrayStroke (page, 0.8)
        Endif

        x += nScaleLine_X
    End



    /* Draw horizontal text */


    y := 0 //distabcia inicio texto
    while (y < height)
        if (y % (nScaleText_Y) == 0 .and. y > 0)
	    cLabel:=ltrim(str(y))
            HPDF_Page_BeginText (page)
            HPDF_Page_MoveTextPos (page, nScaleLine_Y + nCol, y + nRow - (nFontSize/2) + .75  /* Middled Label */)
            HPDF_Page_ShowText (page, cLabel)
            HPDF_Page_EndText (page)
        Endif

        y += nScaleText_Y
    End


    /* Draw virtical text */

    x := 0
    while (x < width)
        if (x % (nScaleText_X) == 0 .and. x > 0)
            cLabel:=ltrim(str(x))
	    nLabWidth:=HPDF_Page_TextWidth( page, cLabel )

            //tag em baixo
	    HPDF_Page_BeginText (page)
            HPDF_Page_MoveTextPos (page, x + nCol - (nLabWidth/2)  /* Centered label */, nScaleLine_X + nRow + 1)
            HPDF_Page_ShowText (page, cLabel)
            HPDF_Page_EndText (page)

            //tag em cima
	    HPDF_Page_BeginText (page)
            HPDF_Page_MoveTextPos (page, x + nCol - (nLabWidth/2)  /* Centered label */, height - (nScaleLine_X * 2) + nRow)
            HPDF_Page_ShowText (page, cLabel)
            HPDF_Page_EndText (page)
        Endif

        x += nScaleText_X
    End

    HPDF_Page_SetGrayFill (page, 0)
    HPDF_Page_SetGrayStroke (page, 0)
	
Return Nil


sample.7z

Do you have a .prg file saved in UTF-8? Perhaps this is a problem.
Prg in ANSI works fine: Demo.7z
rotatetext () is okay the problem and in print_grid () follows new code

Code: Select all


*------------------------------------------------------------------------*
Function print_grid( nRow_pdf, nCol, height, width, nScaleLine_X, nScaleLine_Y, nScaleText_X, nScaleText_Y, nTag_x, nTag_Y,nMim,nMax )
*------------------------------------------------------------------------*
	Local  ofont, x , y , yMin_max, cLabel, nLabWidth
	Local Pdf        	:= _HMG_SYSDATA[ 150 ][ 1 ]
	Local Page       	:= _HMG_SYSDATA[ 150 ][ 7 ]  
	Local cEncoding 	:= _HMG_SYSDATA[ 150 ] [ 10 ]       //Value of "SET HPDFDOC ENCODING TO".   "SET HPDFDOC ENCODING TO" set _HMG_HPDF_SetEncoding
	Local nHeigth_pdf 	:= HPDF_Page_GetHeight (_HMG_SYSDATA[ 150 ][ 7 ])
	Local nCinza 		:= 0.90  // 1 igual a branco total
	Local nRow 			:= nHeigth_pdf - nRow_pdf
	Local nyPos       	:= 0
	
	Local cFont       := "Helvetica"
	Local nFontSize   	:= 10
  	Local lBold       := .F.
	Local  lItalic     := .F.
	Local  aColors     := { 0, 0, 0}
	Local  cAlign      :=""		//Empty - Left and bottom, R - Right, C - Center, T - Top, M - Middle
	
    

		ofont := HPDF_GetFont (Pdf, cFont, cEncoding)
		HPDF_Page_SetFontAndSize (Page, ofont, nFontSize)
		
	HPDF_Page_SetGrayFill (page, 0.25)
    HPDF_Page_SetGrayStroke (page, nCinza)
	
	/*
		As cores são especificadas usando três números reais (ou seja, com um ponto decimal) na forma R G B onde cada número define a quantidade de vermelho (R), verde (G) e azul (B) em uma cor.
		Os números válidos são de 0,0 a 1,0 inclusive ou divide por 255 
		HPDF_Page_SetRGBFill( hPage, aColors[1]/255, aColors[2]/255, aColors[3]/255 )
	*/
	
    /* Draw horizontal lines */
	
    yMin_max := 0 // linhas de tolerancias 
    while (yMin_max <= height )
	
		if yMin_max == nMim 
			HPDF_Page_SetLineWidth (page, 0.5)
			HPDF_Page_SetDash (page, {3}, 1, 1)
			//HPDF_Page_SetGrayStroke(page, 0,0,0)
			HPDF_Page_SetRGBStroke (page, 0 , 0 , 0 ) // (page, 0.0 , 255/255, 0.0 )
			
			HPDF_Page_MoveTo (page, nCol, yMin_max + nRow)
			HPDF_Page_LineTo (page, width + nCol, yMin_max + nRow)
			HPDF_Page_Stroke (page)	
			
			
			nAngle := 0
			nRad := nAngle / 180 * 3.141592 	//radian value
			nTextWidth := HPDF_Page_TextWidth( page ,"Mínimo: " +alltrim(str(nMim) ))
		   
		    nxPos:= 85  - (nTextWidth* cos (nRad))  // posição coluna do texto
			nyPos := nRow + nMim 
            HPDF_Page_BeginText (page)			
			HPDF_Page_SetTextMatrix ( page , cos ( nRad ), sin ( nRad ), -sin ( nRad ), cos ( nRad ), nxPos , nyPos  - nFontSize/2 + .75 ) // nyPos = posicao Linha(Row)
			HPDF_Page_ShowText (page, "Mínimo: "+alltrim(str(nMim)))
            HPDF_Page_EndText (page)			
			
			
			HPDF_Page_SetDash (page, NIL, 0, 0)
			HPDF_Page_SetGrayStroke (page, nCinza)
			
		elseif yMin_max == nMax
		
			HPDF_Page_SetLineWidth (page, 0.5)
			HPDF_Page_SetDash (page, {3}, 1, 1)
			//HPDF_Page_SetGrayStroke(page, 0,0,0)
			HPDF_Page_SetRGBStroke (page, 0 , 0, 0 ) // (page, 0.0 , 255/255, 0.0 )
			
			HPDF_Page_MoveTo (page, nCol, yMin_max + nRow)
			HPDF_Page_LineTo (page, width + nCol, yMin_max + nRow)
			HPDF_Page_Stroke (page)	

		
			nAngle := 0
			nRad := nAngle / 180 * 3.141592 	//radian value
			nTextWidth := HPDF_Page_TextWidth( page , "Máximo: "+alltrim(str(nMax)))
		   
		    nxPos:= 85  - (nTextWidth* cos (nRad))  // // posição coluna do texto
			nyPos := nRow + nMax
            HPDF_Page_BeginText (page)			
			HPDF_Page_SetTextMatrix ( page , cos ( nRad ), sin ( nRad ), -sin ( nRad ), cos ( nRad ), nxPos , nyPos  - nFontSize/2 + .75 ) // nyPos = posicao Linha(Row)
			HPDF_Page_ShowText (page, "Máximo: "+alltrim(str(nMax)))
            HPDF_Page_EndText (page)
			
			
			HPDF_Page_SetDash (page, NIL, 0, 0)
			HPDF_Page_SetGrayStroke (page, nCinza)

		endif
		
       yMin_max += 1
    End


Jair Pinho
HMG ALTA REVOLUÇÃO xBASE
HMG xBASE REVOLUTION HIGH
http://www.hmgforum.com.br

EduardoLuis
Posts: 517
Joined: Tue Jun 04, 2013 6:33 pm
Location: Argentina
Been thanked: 28 times

Post by EduardoLuis » Fri Oct 06, 2017 8:44 pm

Hi colleagues:

Edk last code works fine, i've tested.-
Jaipirinho, you must convert prg from UTF8 to ansi, replace ma nimo with Máximo, and save your prg.-
With regards.
Eduardo

User avatar
serge_girard
Posts: 1835
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Has thanked: 275 times
Been thanked: 63 times
Contact:

Post by serge_girard » Sat Oct 07, 2017 6:27 am

Thx Eduardo and Kryzstof ! This works fine.

Serge

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

Post by jairpinho » Wed Oct 11, 2017 4:27 pm

thank you all really my prg file was like utf8 converted to ansi it worked perfectly, it follows the complete design including all the requested topics in a single project, if anyone needs this ready, it was very useful in my project.

Related Posts
http://www.hmgforum.com/viewtopic.php?f=39&t=5404
http://www.hmgforum.com/viewtopic.php?f=40&t=5406


Project
Tendencia_Rev2_ok.rar
(6.69 KiB) Downloaded 14 times
Image
Image
Attachments
Relatoriojpg_Page2jpg_Page1.jpg
Relatoriojpg_Page2jpg_Page1.jpg (83.18 KiB) Viewed 72 times
Relatoriojpg_Page1.jpg
Relatoriojpg_Page1.jpg (79.39 KiB) Viewed 73 times
Jair Pinho
HMG ALTA REVOLUÇÃO xBASE
HMG xBASE REVOLUTION HIGH
http://www.hmgforum.com.br

edk
Posts: 164
Joined: Thu Oct 16, 2014 11:35 am
DBs Used: DBF
Location: Poland
Has thanked: 43 times
Been thanked: 96 times

Post by edk » Wed Oct 11, 2017 4:41 pm

Brawo Ty :D

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

Post by jairpinho » Wed Oct 11, 2017 5:07 pm

edk wrote:
Wed Oct 11, 2017 4:41 pm
Brawo Ty :D
You were important in this project, without your help you would not be able to
Jair Pinho
HMG ALTA REVOLUÇÃO xBASE
HMG xBASE REVOLUTION HIGH
http://www.hmgforum.com.br

Post Reply