Libharu HPDF library - Export to PDFs part II

Published on by Yousfi Benameur


the previous part began to be heavy, that why i open this part II.
-23 encoding_list demos for Libharu with _libPDF.prg library
this code shows the list of characters for various encodings.
it must be in same folder as _libpdf.prg library and libhpdf.dll (see the previous post and download the zip)

this code is a best way to learn about libharu capabilities:
-creates pages with titles and pagination
-creates outlines with a summary linked to each pointed page(outline ,destination)
-make a page background.
-create a text as pdf page
-load image from disc and display it on a page.
-create grids and multicolor characters embed in

-read the help written in the pdf output.
Note : encoding list for Symbol-Set  &  ZapfDingbats-Set dont work on my system (commented in cursor built)
Note the high speed of vfp performances for working with Libharu library.
Can add this code to the zip in previous post and run it within the executable ytest.exe (can run it simply in its context as prg file).
to run this code must have these files in same folder:
hpdf_const.h
hpdf_types.h
_libhpdf.prg
libhpdf.dll


Click on code to select [then copy] -click outside to deselect


*1*
*yencoding_list.prg demos for Libharu with _pdlLib.prg library
*this code shows the list of characters for various encodings.
*this code is a best way to learn about libharu capabilities:-creates pages with titles and pagination
*-creates outlines with a summary linked to each pointed page(outline ,destination)
*-make a page background.
*-create a text as pdf page
*-load image from disc and display it on a page.
*-create grids and multicolor characters embed in

#include hpdf_types.h
#include hpdf_consts.h
Erase ("ydemo.pdf")   &&acrobat must  dont be opened
Set Defa To Addbs(Justpath(Sys(16,1)))

*download an image from my blog (or point to any jpeg image on disc)
Declare Integer Sleep In kernel32 Integer
Declare Integer URLDownloadToFile In urlmon.Dll Integer pCaller, String szURL, String szFileName, Integer dwReserved, Integer lpfnCB
Declare Integer DeleteUrlCacheEntry In wininet String lpszUrlName

lcDownloadURL = "http://img.over-blog-kiwi.com/1/43/54/07/20160313/ob_1f4998_sam-2260-resized.JPG"
lcDownloadLoc ="kantara.jpg"
lnResult = DeleteUrlCacheEntry(lcDownloadURL)
lnResult = URLDownloadToFile(0, lcDownloadURL, lcDownloadLoc , 0,0)
If lnResult = 0
    Wait Window "Download "+lcDownloadLoc +"  Complete" Nowait
*Else
*!*  Messagebox("Download fails")
Endi


Create Cursor ycurs (yencod c(25))
*comment if problem encoding item
Insert Into ycurs Values("StandardEncoding")
Insert Into ycurs Values("MacRomanEncoding")
Insert Into ycurs Values("WinAnsiEncoding")
Insert Into ycurs Values("ISO8859-2")
Insert Into ycurs Values("ISO8859-3")
Insert Into ycurs Values("ISO8859-4")
Insert Into ycurs Values("ISO8859-5")
Insert Into ycurs Values("ISO8859-6")
Insert Into ycurs Values("ISO8859-7")
Insert Into ycurs Values("ISO8859-9")
Insert Into ycurs Values("ISO8859-10")
Insert Into ycurs Values("ISO8859-13")
Insert Into ycurs Values("ISO8859-14")
Insert Into ycurs Values("ISO8859-15")
Insert Into ycurs Values("ISO8859-16")
Insert Into ycurs Values("CP1250")
Insert Into ycurs Values("CP1251")
Insert Into ycurs Values("CP1252")
Insert Into ycurs Values("CP1253")
Insert Into ycurs Values("CP1254")
Insert Into ycurs Values("CP1256")
Insert Into ycurs Values("CP1257")
Insert Into ycurs Values("KOI8-R")
*Insert Into ycurs Values("Symbol-Set")
*Insert Into ycurs Values("ZapfDingbats-Set")
*Brow

Sele ycurs
Local opdf As 'pdfGen' Of '_libpdf.prg'
Local page_title As String
Local pdf As HPDF_Doc
Local fname As String
Local Page As HPDF_Page
Local def_font As HPDF_Font
Local tw, Height,Width, i
Local printGrid
printGrid=.T.
fname = 'ydemo.pdf'

opdf = Newobject('pdfGen',Locfile('_libpdf.prg'))
pdf = opdf.New()
opdf.Setcompressionmode( HPDF_COMP_ALL )


*pdf as fullscreen in acrobat default viewer(not needed here because outline)
*opdf.SetPageMode( HPDF_PAGE_MODE_FULL_SCREEN)   &&CTRL+L in acrobat reader

Page = opdf.Addpage()
Local m.pageWidth,m.pageHeight
m.page_Width=420
m.page_Height=500
Height = page_Height
Width = page_Width

* Set page mode to use outlines.
opdf.SetPageMode(HPDF_PAGE_MODE_USE_OUTLINE)

opdf.Page_SetWidth(Page,m.page_Width)
opdf.Page_SetHeight(Page,m.page_Height)

*make page background color
*opdf.Page_SetCMYKFill(Page, 0.13, 0, 0.16,0.11)
opdf.Page_SetRGBFill(Page,0.8,1,1)
opdf.Page_Rectangle(Page,0,0,page_Width,page_Height)
opdf.Page_Fill (Page)

Font = opdf.Getfont("Helvetica-Bold", Null)
opdf.Page_SetTextLeading(Page,20)

Local ypict,Image
*draw a loded image from disc
m.ypict="KANTARA.JPG"
Image = opdf.LoadJpegImageFromFile(m.ypict)
* Draw image to the canvas.
page_Width= Width
page_Height=Height -100
x=30
Y=50
opdf.Page_DrawImage (Page, Image, x, Y, page_Height-40,page_Width-40)
* Print the text.
opdf.Page_SetFontAndSize (Page, Font, 16)
opdf.Page_SetRGBFill (Page, 1,0, 0.1)
opdf.Page_BeginText (Page)
opdf.Page_SetTextLeading (Page,15)
opdf.Page_MoveTextPos (Page, 180, Y+20)
opdf.Page_ShowTextNextLine (Page, "EL "+Juststem(m.ypict))
opdf.Page_EndText (Page)

** print the title of the page (with positioning top center).
m.hTitle=30
m.page_title=" Encoding lists demo ("+Trans(Reccount())+")"
opdf.Page_SetFontAndSize (Page, Font, 18)
tw = opdf.Page_TextWidth (Page, page_title)
opdf.Page_SetRGBFill (Page, .4, 1, 0.6)
opdf.Page_Rectangle(Page,(opdf.Page_GetWidth(Page) - tw) / 2 ,opdf.Page_GetHeight(Page)-m.hTitle,250,25)
opdf.Page_Fill (Page)
opdf.Page_SetRGBFill (Page, 1.0, 0., 0.)
opdf.Page_BeginText (Page)
opdf.Page_TextOut (Page, (opdf.Page_GetWidth(Page) - tw) / 2 ,opdf.Page_GetHeight(Page)-m.hTitle +10 , page_title)
opdf.Page_EndText (Page)

page_title="Author: Yousfi Benameur 18 april 2016"
tw = opdf.Page_TextWidth (Page, page_title)
Font = opdf.Getfont("Helvetica-BoldOblique", Null)
opdf.Page_SetFontAndSize(Page,Font, 9)
opdf.Page_SetRGBFill (Page, 1.0, 0., 0.)
opdf.Page_BeginText (Page)
opdf.Page_TextOut (Page, opdf.Page_GetWidth(Page) - tw ,15 , page_title)
opdf.Page_EndText (Page)

root = opdf.CreateOutline(0, "Libharu Encoding lists demo ", 0)
opdf.Outline_SetOpened(root, HPDF_TRUE)

outline = opdf.CreateOutline(root, "-Cover page", 0)
dst = opdf.Page_CreateDestination(Page)
opdf.Destination_SetXYZ(dst, 0, HPDF_Page_GetHeight(Page), 1)
opdf.Outline_SetDestination(outline, dst)

*help
*iso8859 parts
Local m.myvar
TEXT to m.myvar  noshow
The Parts of ISO/IEC 8859

ISO/IEC 8859 is divided into the following parts:
this code shows the list of characters for various encodings.
Part 1     Latin-1
Western European 	Perhaps the most widely used part of ISO/IEC 8859, covering most
Western European languages:
 Danish (partial),[1] Dutch (partial),[2] English, Faeroese, Finnish (partial),[3]
 French (partial),[3] German,  Icelandic, Irish, Italian, Norwegian, Portuguese,
 Rhaeto-Romanic, Scottish Gaelic, Spanish, Catalan, and Swedish.
  Languages from other parts of the world are also covered, including: Eastern
  European Albanian, Southeast  Asian Indonesian, as well as the African languages
  Afrikaans and Swahili. The missing  euro sign and capital  Ÿ are in the revised
  version ISO/IEC 8859-15 (see below). The corresponding IANA character set is
  ISO-8859-1.

Part 2 	Latin-2
Central European 	Supports those Central and Eastern European languages that use
the Latin alphabet, including Bosnian,Polish, Croatian, Czech, Slovak, Slovene,
Serbian, and Hungarian. The missing euro sign can be found in version ISO/IEC
8859-16.

Part 3 	Latin-3
South European 	Turkish, Maltese, and Esperanto. Largely superseded by ISO/IEC
8859-9 for Turkish and Unicode for Esperanto.

Part 4 	Latin-4
North European 	Estonian, Latvian, Lithuanian, Greenlandic, and Sami.

Part 5 	Latin/Cyrillic 	Covers mostly Slavic languages that use a Cyrillic alphabet,
including Belarusian, Bulgarian, Macedonian, Russian, Serbian, and Ukrainian
(partial).[4]

Part 6 	Latin/Arabic 	Covers the most common Arabic language characters.
Doesn't support other languages using theArabic script. Needs to be BiDi
and cursive joining processed for  display.

Part 7 	Latin/Greek 	Covers the modern Greek language (monotonic orthography).
Can also be used for Ancient Greek written without accents or in monotonic
orthography, but lacks the diacritics for polytonic orthography. These were introduced
with Unicode.

Part 8 	Latin/Hebrew 	Covers the modern Hebrew alphabet as used in Israel. In practice
two different encodings exist, logical order (needs to be BiDi processed for display)
and visual (left-to-right) order (in effect, after bidi processing and line breaking).

Part 9 	Latin-5
Turkish 	Largely the same as ISO/IEC 8859-1, replacing the rarely used Icelandic
letters with Turkish ones.
Part 10 	Latin-6
Nordic 	a rearrangement of Latin-4. Considered more useful for Nordic languages. Baltic
languages use Latin-4 more.
Part 11 	Latin/Thai 	Contains characters needed for the Thai language. Virtually
identical  to TIS 620.
Part 12 	Latin/Devanagari 	The work in making a part of 8859 for Devanagari was
officially abandoned in 1997.
 ISCII and Unicode/ISO/IEC 10646 cover Devanagari.
Part 13 	Latin-7
Baltic Rim 	Added some characters for Baltic languages which were missing from Latin-4
 and Latin-6.
Part 14 	Latin-8
Celtic 	Covers Celtic languages such as Gaelic and the Breton language.
Part 15 	Latin-9 	A revision of 8859-1 that removes some little-used symbols,
replacing them with the euro sign € and the letters Š, š, Ž, ž, Œ, œ, and Ÿ, which
completes the coverage of French, Finnish and Estonian.
Part 16 	Latin-10
Fantasy mix 	Intended for Albanian, Croatian, Hungarian, Italian, Polish, Romanian
and Slovene, but also Finnish, French, German and Irish Gaelic (new orthography). The
focus lies more on  letters than symbols. The currency sign is replaced with the euro sign.

It is named "fantasy mix" because it contains select languages of -1 and -2.
___________________________________________________________________________________________
 this code is a best way to learn about libharu capabilities:-creates pages with titles
 and pagination
-creates outlines with a summary linked to each pointed page(outline ,destination)
-make a page background.
-create a text as pdf page
-load image from disc and display it on a page.
-create grids and multicolor characters embed in

ENDTEXT

page_Width= 420
page_Height=1660

Page = opdf.Addpage()

Local m.pageWidth,m.pageHeight
m.pageWidth=page_Width
m.pageHeight=page_Height

opdf.Page_SetWidth(Page,m.page_Width)
opdf.Page_SetHeight(Page,m.page_Height)

*make page background color
**opdf.Page_SetCMYKFill(Page, 0.13, 0, 0.16,0.11)  &&as option
opdf.Page_SetRGBFill(Page,0.8,1,1)
opdf.Page_Rectangle(Page,0,0,m.page_Width,m.page_Height)
opdf.Page_Fill (Page)
opdf.Page_SetRGBFill(Page,0,0,0)


* create default-font
Font = opdf.Getfont("Helvetica", Null)
opdf.Page_SetTextLeading(Page,20)
page_title="        ISO8859 parts (https://en.wikipedia.org/wiki/ISO/IEC_8859)"
*opdf.Page_SetRGBFill (Page, 1, 0.1, 0.2)


* print the title of the page (with positioning center).
opdf.Page_SetFontAndSize (Page, Font, 14)
tw = opdf.Page_TextWidth (Page, page_title)
opdf.Page_BeginText (Page)
opdf.Page_TextOut (Page,(page_Width - tw) / 2 ,page_Height -20, page_title)
opdf.Page_EndText (Page)

opdf.Page_BeginText (Page)
opdf.Page_MoveTextPos (Page, 20,page_Height-60)


Local gnbre
gnbre=Alines(ArrayName, m.myvar,1) &&better than mline,memline;_mline

For j=1 To gnbre
	opdf.Page_SetTextRenderingMode (Page, HPDF_FILL)
	opdf.Page_SetFontAndSize (Page, Font, 10)
	opdf.Page_MoveTextPos (Page, 0, -20)
	samp_text=ArrayName(j)
	Len = Len(samp_text)
	buf = samp_text
	opdf.Page_ShowText (Page, buf)
Endfor

* Set page mode to use outlines.
opdf.SetPageMode(HPDF_PAGE_MODE_USE_OUTLINE)
root = opdf.CreateOutline(0, "ISO8859 parts help ", 0)
opdf.Outline_SetOpened(root, HPDF_TRUE)
outline = opdf.CreateOutline(root, "-Help", 0)
dst = opdf.Page_CreateDestination(Page)
opdf.Destination_SetXYZ(dst, 0, HPDF_Page_GetHeight(Page), 1)
opdf.Outline_SetDestination(outline, dst)

page_Width= 420
page_Height=400

CELL_WIDTH=  20
CELL_HEIGHT= 20
CELL_HEADER= 10

Sele ycurs
*/* create outline root.
root = opdf.CreateOutline(0, "Encoding_lists", 0)
opdf.Outline_SetOpened(root, HPDF_TRUE)

Scan
	Page= opdf.Addpage()

	Page = opdf.GetCurrentPage()
	opdf.Page_SetWidth(Page,page_Width)
* opdf.Page_SetHeight(Page,PAGE_HEIGHT)

	=ydraw(opdf,Page,ycurs.yencod,Recno())
	Wait Window "page "+Trans(Recno()) Nowait
Endscan

Wait Clea

opdf.SaveToFile(fname)
* clean up
opdf.Free()

*yb Show
If File (m.fname)
	loShell = Newobject('_shellexecute', Home(1) + 'ffc\_environ.vcx')
	loShell.ShellExecute(m.fname,3)
*set defa to (yrep)
Else
	Messagebox("ydemo.pdf not generated",16+4096)
Endi
Return
*end of main

Function ydraw()
Lparameters opdf,Page,encod,rec
Local page_Width,page_Height,CELL_WIDTH,CELL_HEIGHT,CELL_HEADER,xmg,ymg
page_Width= 420
page_Height=400
CELL_WIDTH=  20
CELL_HEIGHT= 20
CELL_HEADER= 10
xmg=0
ymg=390

**Background color  &&(pb zorder)
opdf.Page_SetRGBFill(Page,0.8,1,1)
opdf.Page_Rectangle(Page,0,0, opdf.Page_GetWidth(Page), opdf.Page_GetHeight(Page))
opdf.Page_Fill (Page)
opdf.Page_SetRGBFill(Page,0,0,0)

outline = opdf.CreateOutline(root, "-" +Trans(rec)+"-"+Allt(encod), 0)
dst = opdf.Page_CreateDestination(Page)
opdf.Destination_SetXYZ(dst, 0, HPDF_Page_GetHeight(Page), 1)
opdf.Outline_SetDestination(outline, dst)

*subtitles
Font = opdf.Getfont("Helvetica-Bold", Null)  
opdf.Page_SetFontAndSize (Page, Font, 15)
opdf.Page_BeginText (Page)
opdf.Page_SetFontAndSize (Page, Font, 20)
opdf.Page_MoveTextPos (Page, xmg+40, page_Height - 50+ymg)
opdf.Page_ShowText (Page, yencod)
opdf.Page_ShowText (Page, " Encoding")
opdf.Page_EndText (Page)

* Draw 16 X 15 cells
Font =opdf.Getfont("Helvetica-Bold",Allt(encod))    &&Null)
opdf.Page_SetFontAndSize(Page,Font, 10)
buf=Spac(50)
* Draw vertical lines.
opdf.Page_SetLineWidth (Page, 0.5)
For i=1 To 18
	x =xmg+(i-1) * CELL_WIDTH + 40

	opdf.Page_MoveTo (Page, x, page_Height - 60+ymg)
	opdf.Page_LineTo (Page, x, 40+ymg)
	opdf.Page_Stroke (Page)

	If  Between(i,2,16+1)
		opdf.Page_BeginText (Page)
		opdf.Page_MoveTextPos (Page,x + 5, page_Height - 75+ymg)
		buf=Trans(i-1)
		opdf.Page_ShowText (Page, buf)
		opdf.Page_EndText (Page)
	Endi
Endfor

* Draw horizontal lines.
For i = 0 To 15
	Y = i * CELL_HEIGHT + 40+ymg
	opdf.Page_MoveTo (Page,xmg+ 40, Y)
	opdf.Page_LineTo (Page,xmg+ page_Width - 40, Y)
	opdf.Page_Stroke (Page)
	If (i < 14)
		opdf.Page_BeginText (Page)
		opdf.Page_MoveTextPos (Page, xmg+45, Y + 5)
		buf=Trans(15-i)
		opdf.Page_ShowText (Page, buf)
		opdf.Page_EndText (Page)
	Endi
Endfor

opdf.Page_BeginText (Page)
* Draw all character from 0x20 to 0xFF to the canvas.
k=32
For i = 1 To 16
	For j = 1 To 16
		Y = page_Height - 55 - ((i - 1) * CELL_HEIGHT)+ymg
		x = xmg+j * CELL_WIDTH + 50
		buf = 0x00
		buf0 = (i - 1) * 16 + (j - 1)
		If (buf0 >= 32)
			d  = x -opdf.Page_TextWidth (Page, buf )
			opdf.Page_SetRGBFill (Page, 255*Rand()/255,255*Rand()/255, 255*Rand()/255)
			buf=Chr(k)
			k=k+1
			opdf.Page_TextOut (Page, d, Y,buf )
		Endi
	Endfor
Endfor
opdf.Page_EndText (Page)

*pagination
page_title="page "+Trans(Recno())
tw = opdf.Page_TextWidth (Page, page_title)
Font = opdf.Getfont("Helvetica-BoldOblique", Null)
opdf.Page_SetFontAndSize(Page,Font, 10)
opdf.Page_SetRGBFill (Page, 1, 0., 0.)
opdf.Page_BeginText (Page)
opdf.Page_TextOut (Page, opdf.Page_GetWidth(Page) - tw -30,15 , page_title)
opdf.Page_EndText (Page)

Endfunc


Libharu HPDF library - Export to PDFs part II
Libharu HPDF library - Export to PDFs part II
Libharu HPDF library - Export to PDFs part II

Important:All Codes above are tested on VFP9SP2 & windows 10 pro.

Please come back with any bug.correcting code is usefull to all readers.

To be informed of the latest articles, subscribe:
Comment on this post
C
Very nice job!!!<br /> Congratulations, and thanks for sharing!<br /> Cesar
Reply