OSDN Git Service

binding with libharu.
[putex/putex.git] / src / texsourc / lib / libhpdf / if / freebasic / hpdftest.bas
1 '****************************************************************************** 
2 '*  Program name: hpdftest
3 '*  Version:      0.1
4 '*
5 '*  Author:       Copyright (c) 2008 Klaus Siebke
6 '*                Siebke Unternehmensberatung
7 '*                URL http://www.siebke.com
8 '*
9 '*  Description:
10 '*  -----------
11 '*
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
14 '*
15 '*  License:
16 '*  -------
17 '*
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.
24 '*
25 '*
26 '*  External libraries used by the program:
27 '*  --------------------------------------
28 '*
29 '*  << Haru Free PDF Library 2.0.8 >>
30 '*  URL http://libharu.org/
31 '*  Copyright (c) 1999-2006 Takeshi Kanno
32 '*
33 '****************************************************************************** 
34
35 #include "crt/errno.bi"
36 #include "zlib.bi"       
37
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"
46 #endif
47
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 )
52
53 '****************************************************************************** 
54 '* Constants
55 '****************************************************************************** 
56 #define NULL 0 
57 const page_title = "PDF test document"
58
59 '****************************************************************************** 
60 '* Variables
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
74
75
76 '****************************************************************************** 
77 '* Begin of main program
78 '****************************************************************************** 
79
80 'let's go ... (initialize hpdf)
81 pdf = HPDF_New(@error_handler, NULL)
82
83
84 'add a new page object
85 page = HPDF_AddPage (pdf)
86
87 'specify the document size
88 doc_height = HPDF_Page_GetHeight (page)
89 doc_width = HPDF_Page_GetWidth (page)
90
91 'print a frame
92 HPDF_Page_SetLineWidth (page, .5)
93 HPDF_Page_Rectangle (page, 50, 50, doc_width - 100, doc_height - 110)
94 HPDF_Page_Stroke (page)
95
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)
103
104 'print some text inside the frame 
105 HPDF_Page_BeginText (page)
106
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")
112
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")
118
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")
124
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")
130
131
132 HPDF_Page_EndText (page)
133
134 'save the document
135 HPDF_SaveToFile (pdf, "mydoc.pdf")
136
137 'clean up
138 HPDF_Free (pdf)
139
140 '****************************************************************************** 
141 '* End of main program
142 '****************************************************************************** 
143
144
145 sub error_handler cdecl (byval error_no as HPDF_STATUS, byval detail_no as HPDF_STATUS, byval user_data as any ptr) 
146 '****************************************************************************** 
147 '* Error handler
148 '****************************************************************************** 
149 ' do something here ... 
150   print "error_no: ", error_no
151   print "detail_no:", detail_no
152   print "data:     ", user_data
153
154 end sub