1 '******************************************************************************
2 '* Program name: hpdftest
5 '* Author: Copyright (c) 2008 Klaus Siebke
6 '* Siebke Unternehmensberatung
7 '* URL http://www.siebke.com
12 '* Program to test the creation of a PDF file using the Haru Free PDF Library
13 '* for more details see: http://www.freebasic.net/forum/viewtopic.php?t=9014
18 '* Permission to use, copy, modify, distribute and sell this software
19 '* and its documentation for any purpose is hereby granted without fee,
20 '* provided that the above copyright notice appear in all copies and
21 '* that both that copyright notice and this permission notice appear
22 '* in supporting documentation.
23 '* It is provided "as is" without express or implied warranty.
26 '* External libraries used by the program:
27 '* --------------------------------------
29 '* << Haru Free PDF Library 2.0.8 >>
30 '* URL http://libharu.org/
31 '* Copyright (c) 1999-2006 Takeshi Kanno
33 '******************************************************************************
35 #include "crt/errno.bi"
38 '******************************************************************************
39 '* Includes for Haru Free PDF Library
40 '******************************************************************************
41 #ifndef __mod_hpdf_bi__
42 #define __mod_hpdf_bi__
43 #include once "hpdf_consts.bi"
44 #include once "hpdf_types.bi"
45 #include once "hpdf.bi"
48 '******************************************************************************
49 '* Declarations of subroutines and functions
50 '******************************************************************************
51 declare sub error_handler cdecl (byval error_no as HPDF_STATUS, byval detail_no as HPDF_STATUS, byval user_data as any ptr )
53 '******************************************************************************
55 '******************************************************************************
57 const page_title = "PDF test document"
59 '******************************************************************************
61 '******************************************************************************
62 dim shared pdf as HPDF_Doc 'ptr
63 dim shared fname as string * 256
64 dim shared page as HPDF_Page
65 dim shared def_font as HPDF_Font
66 dim shared txt_font as HPDF_Font
67 dim shared tw as HPDF_REAL
68 dim shared doc_height as HPDF_REAL
69 dim shared doc_width as HPDF_REAL
70 dim shared i as HPDF_UINT
71 'dim shared errno as HPDF_STATUS ptr
72 dim shared detno as HPDF_STATUS ptr
73 dim shared userdat as any ptr
76 '******************************************************************************
77 '* Begin of main program
78 '******************************************************************************
80 'let's go ... (initialize hpdf)
81 pdf = HPDF_New(@error_handler, NULL)
84 'add a new page object
85 page = HPDF_AddPage (pdf)
87 'specify the document size
88 doc_height = HPDF_Page_GetHeight (page)
89 doc_width = HPDF_Page_GetWidth (page)
92 HPDF_Page_SetLineWidth (page, .5)
93 HPDF_Page_Rectangle (page, 50, 50, doc_width - 100, doc_height - 110)
94 HPDF_Page_Stroke (page)
96 'print the title of the page (with positioning center) with font Helvetica
97 def_font = HPDF_GetFont (pdf, "Helvetica", NULL)
98 HPDF_Page_SetFontAndSize (page, def_font, 24)
99 tw = HPDF_Page_TextWidth (page, page_title)
100 HPDF_Page_BeginText (page)
101 HPDF_Page_TextOut (page, (doc_width - tw) / 2, doc_height - 50, page_title)
102 HPDF_Page_EndText (page)
104 'print some text inside the frame
105 HPDF_Page_BeginText (page)
107 'first line with font Times Roman 14
108 txt_font = HPDF_GetFont (pdf, "Times-Roman", NULL)
109 HPDF_Page_MoveTextPos (page, 60, doc_height - 105)
110 HPDF_Page_SetFontAndSize (page, txt_font, 14)
111 HPDF_Page_ShowText (page, "This is a first line")
113 'second line with font Courier 12
114 txt_font = HPDF_GetFont (pdf, "Courier", NULL)
115 HPDF_Page_MoveTextPos (page, 0, -20)
116 HPDF_Page_SetFontAndSize (page, txt_font, 12)
117 HPDF_Page_ShowText (page, "This is a second line")
119 'third line with font Symbol 16
120 txt_font = HPDF_GetFont (pdf, "Symbol", NULL)
121 HPDF_Page_MoveTextPos (page, 0, -20)
122 HPDF_Page_SetFontAndSize (page, txt_font, 16)
123 HPDF_Page_ShowText (page, "Here are some symbols")
125 'fourth line with font Helvetica 14
126 txt_font = HPDF_GetFont (pdf, "Helvetica", NULL)
127 HPDF_Page_MoveTextPos (page, 0, -20)
128 HPDF_Page_SetFontAndSize (page, txt_font, 14)
129 HPDF_Page_ShowText (page, "This is arial")
132 HPDF_Page_EndText (page)
135 HPDF_SaveToFile (pdf, "mydoc.pdf")
140 '******************************************************************************
141 '* End of main program
142 '******************************************************************************
145 sub error_handler cdecl (byval error_no as HPDF_STATUS, byval detail_no as HPDF_STATUS, byval user_data as any ptr)
146 '******************************************************************************
148 '******************************************************************************
149 ' do something here ...
150 print "error_no: ", error_no
151 print "detail_no:", detail_no
152 print "data: ", user_data