Regarding HPDFURLLINK command

Moderator: Rathinagiri

Post Reply
Paramvir
Posts: 44
Joined: Sun Mar 27, 2016 9:46 am
Location: India
Contact:

Regarding HPDFURLLINK command

Post by Paramvir »

Hi

While generating PDF, the command
HPDFURLLINK creates a text link that has border around it. I use this syntax:

@200, 20 HPDFURLLINK xvariable to "URL link" color { 255, 20, 147 } FONT "COURIER-BOLD" SIZE 8

This creates a border around the text. I am not sure how to create a borderless link. Any suggestions ?
Thank you all.
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: Regarding HPDFURLLINK command

Post by Rathinagiri »

I think it is the feature of LibHaru PDF library.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
Paramvir
Posts: 44
Joined: Sun Mar 27, 2016 9:46 am
Location: India
Contact:

Re: Regarding HPDFURLLINK command

Post by Paramvir »

Rathinagiri wrote: Fri Jun 26, 2020 10:47 am I think it is the feature of LibHaru PDF library.
Thank you Rathi ji for the reply. I took this command and syntax from the HMG_HPDF_doc.PDF which I think has been created by you and this PDF file is given in HMG3.4.4\SAMPLES\HPDF\HMG_HPDF.

I want to create a borderless text link but this command doesn't say anything about it. Perhaps you can help.

Regards

Paramvir
edk
Posts: 909
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: Regarding HPDFURLLINK command

Post by edk »

Replace the _HMG_HPDF_SetURLLink function in the h_HMG_HPDF.Prg file with the one below, then rebuild the HMG.

Code: Select all

Function _HMG_HPDF_SetURLLink( nRow, nCol, cText, cLink, cFontName, nFontSize, nRColor, nGColor, nBColor, cAlign, lColor, lFont, lSize, lBold, lItalic  )
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 oFont := Nil
Local cFont := ''
Local aRect := { }
Local aCurXY := {}
Local oAnnot := Nil
Local hUrlLink := Nil
default cFontName := ''
default nFontSize := 12
default nRColor := 0
default nGColor := 0
default nBColor := 0
default lColor := .f.
default lFont := .f.
default lSize := .f.
default lBold := .f.
default lItalic := .f.
default cAlign := ''

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 )
//   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
   HPDF_Page_SetFontAndSize( _HMG_SYSDATA[ 150 ][ 7 ], oFont, nFontSize )
   nTextWidth := HPDF_Page_TextWidth( _HMG_SYSDATA[ 150 ][ 7 ], cText )
   do case
      case HMG_UPPER( alltrim( cAlign ) ) == 'CENTER'
         nxPos := nxPos - ( nTextWidth / 2 )
      case HMG_UPPER( alltrim( cAlign ) ) == 'RIGHT'
         nxPos := nxPos - ( nTextWidth )
   endcase
   HPDF_Page_BeginText( _HMG_SYSDATA[ 150 ][ 7 ] )
   HPDF_PAGE_TEXTOUT( _HMG_SYSDATA[ 150 ][ 7 ], nxPos, nyPos, cText )
   aRect := { nxPos - 4, nyPos + nFontsize + 4, nxPos + nTextWidth + 4, nyPos - 4 }
   hUrlLink := HPDF_Page_CreateURILinkAnnot( _HMG_SYSDATA[ 150 ][ 7 ], aRect, cLink )
   IF hUrlLink != Nil
   	HPDF_Annotation_SetBorderStyle ( hUrlLink, HPDF_BS_UNDERLINED )
   ENDIF
   HPDF_Page_EndText( _HMG_SYSDATA[ 150 ][ 7 ] )
endif
Return Nil   
Paramvir
Posts: 44
Joined: Sun Mar 27, 2016 9:46 am
Location: India
Contact:

Re: Regarding HPDFURLLINK command

Post by Paramvir »

edk wrote: Fri Jun 26, 2020 11:15 am Replace the _HMG_HPDF_SetURLLink function in the h_HMG_HPDF.Prg file with the one below, then rebuild the HMG.

Code: Select all

Function _HMG_HPDF_SetURLLink( nRow, nCol, cText, cLink, cFontName, nFontSize, nRColor, nGColor, nBColor, cAlign, lColor, lFont, lSize, lBold, lItalic  )
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 oFont := Nil
Local cFont := ''
Local aRect := { }
Local aCurXY := {}
Local oAnnot := Nil
Local hUrlLink := Nil
default cFontName := ''
default nFontSize := 12
default nRColor := 0
default nGColor := 0
default nBColor := 0
default lColor := .f.
default lFont := .f.
default lSize := .f.
default lBold := .f.
default lItalic := .f.
default cAlign := ''

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 )
//   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
   HPDF_Page_SetFontAndSize( _HMG_SYSDATA[ 150 ][ 7 ], oFont, nFontSize )
   nTextWidth := HPDF_Page_TextWidth( _HMG_SYSDATA[ 150 ][ 7 ], cText )
   do case
      case HMG_UPPER( alltrim( cAlign ) ) == 'CENTER'
         nxPos := nxPos - ( nTextWidth / 2 )
      case HMG_UPPER( alltrim( cAlign ) ) == 'RIGHT'
         nxPos := nxPos - ( nTextWidth )
   endcase
   HPDF_Page_BeginText( _HMG_SYSDATA[ 150 ][ 7 ] )
   HPDF_PAGE_TEXTOUT( _HMG_SYSDATA[ 150 ][ 7 ], nxPos, nyPos, cText )
   aRect := { nxPos - 4, nyPos + nFontsize + 4, nxPos + nTextWidth + 4, nyPos - 4 }
   hUrlLink := HPDF_Page_CreateURILinkAnnot( _HMG_SYSDATA[ 150 ][ 7 ], aRect, cLink )
   IF hUrlLink != Nil
   	HPDF_Annotation_SetBorderStyle ( hUrlLink, HPDF_BS_UNDERLINED )
   ENDIF
   HPDF_Page_EndText( _HMG_SYSDATA[ 150 ][ 7 ] )
endif
Return Nil   
Thank you Edk for the generous help and sharing your code. I would like to try it although it seems a bit daunting for a person like me with limited programming knowledge. Thank you once again.
Regards
Paramvir
edk
Posts: 909
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: Regarding HPDFURLLINK command

Post by edk »

Paramvir wrote: Sat Jun 27, 2020 2:21 am I would like to try it although it seems a bit daunting for a person like me with limited programming knowledge.
Regards
Paramvir
Look at this video:
ezgif.com-optimize.gif
ezgif.com-optimize.gif (11.12 MiB) Viewed 8769 times
Paramvir
Posts: 44
Joined: Sun Mar 27, 2016 9:46 am
Location: India
Contact:

Re: Regarding HPDFURLLINK command

Post by Paramvir »

edk wrote: Sat Jun 27, 2020 6:23 am
Paramvir wrote: Sat Jun 27, 2020 2:21 am I would like to try it although it seems a bit daunting for a person like me with limited programming knowledge.
Regards
Paramvir
Look at this video:
ezgif.com-optimize.gif
GREAT! Thank you EDK. I just did what you showed in the video and yes! now the link is borderless. Thank you for all the pains you have taken.
Regards
Paramvir
:D
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: Regarding HPDFURLLINK command

Post by Rathinagiri »

edk wrote: Fri Jun 26, 2020 11:15 am Replace the _HMG_HPDF_SetURLLink function in the h_HMG_HPDF.Prg file with the one below, then rebuild the HMG.

Code: Select all

Function _HMG_HPDF_SetURLLink( nRow, nCol, cText, cLink, cFontName, nFontSize, nRColor, nGColor, nBColor, cAlign, lColor, lFont, lSize, lBold, lItalic  )
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 oFont := Nil
Local cFont := ''
Local aRect := { }
Local aCurXY := {}
Local oAnnot := Nil
Local hUrlLink := Nil
default cFontName := ''
default nFontSize := 12
default nRColor := 0
default nGColor := 0
default nBColor := 0
default lColor := .f.
default lFont := .f.
default lSize := .f.
default lBold := .f.
default lItalic := .f.
default cAlign := ''

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 )
//   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
   HPDF_Page_SetFontAndSize( _HMG_SYSDATA[ 150 ][ 7 ], oFont, nFontSize )
   nTextWidth := HPDF_Page_TextWidth( _HMG_SYSDATA[ 150 ][ 7 ], cText )
   do case
      case HMG_UPPER( alltrim( cAlign ) ) == 'CENTER'
         nxPos := nxPos - ( nTextWidth / 2 )
      case HMG_UPPER( alltrim( cAlign ) ) == 'RIGHT'
         nxPos := nxPos - ( nTextWidth )
   endcase
   HPDF_Page_BeginText( _HMG_SYSDATA[ 150 ][ 7 ] )
   HPDF_PAGE_TEXTOUT( _HMG_SYSDATA[ 150 ][ 7 ], nxPos, nyPos, cText )
   aRect := { nxPos - 4, nyPos + nFontsize + 4, nxPos + nTextWidth + 4, nyPos - 4 }
   hUrlLink := HPDF_Page_CreateURILinkAnnot( _HMG_SYSDATA[ 150 ][ 7 ], aRect, cLink )
   IF hUrlLink != Nil
   	HPDF_Annotation_SetBorderStyle ( hUrlLink, HPDF_BS_UNDERLINED )
   ENDIF
   HPDF_Page_EndText( _HMG_SYSDATA[ 150 ][ 7 ] )
endif
Return Nil   
Nice Edk. Have you tried to update to the latest libharupdf? Because it has the feature of Unicode/UTF-8

It is a long pending one to have a native support for unicode pdf.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
Post Reply