1'
2' << Haru Free PDF Library >> -- hpdfvb.vb
3'
4' VB.Net wrapper for libhpdf.dll
5'
6' Copyright (c) 2008 Matthew Underwood <matt@bargolf.net>
7'
8' Permission to use, copy, modify, distribute and sell this software
9' and its documentation for any purpose is hereby granted without fee,
10' provided that the above copyright notice appear in all copies and
11' that both that copyright notice and this permission notice appear
12' in supporting documentation.
13' It is provided "as is" without express or implied warranty.
14'
15'
16
17Imports System
18Imports System.Runtime.InteropServices
19
20Namespace HPdf
21
22    Public Enum HPdfPageLayout As Integer
23        HPDF_PAGE_LAYOUT_SINGLE = 0
24        HPDF_PAGE_LAYOUT_ONE_COLUMN
25        HPDF_PAGE_LAYOUT_TWO_CLUMN_LEFT
26        HPDF_PAGE_LAYOUT_TWO_CLUMN_RIGHT
27        HPDF_PAGE_LAYOUT_EOF
28    End Enum
29    Public Enum HPdfPageMode As Integer
30        HPDF_PAGE_MODE_USE_NONE = 0
31        HPDF_PAGE_MODE_USE_OUTLINE
32        HPDF_PAGE_MODE_USE_THUMBS
33        HPDF_PAGE_MODE_FULL_SCREEN
34        HPDF_PAGE_MODE_EOF
35    End Enum
36    Public Enum HPdfPageSizes As Integer
37        HPDF_PAGE_SIZE_LETTER = 0
38        HPDF_PAGE_SIZE_LEGAL
39        HPDF_PAGE_SIZE_A3
40        HPDF_PAGE_SIZE_A4
41        HPDF_PAGE_SIZE_A5
42        HPDF_PAGE_SIZE_B4
43        HPDF_PAGE_SIZE_B5
44        HPDF_PAGE_SIZE_EXECUTIVE
45        HPDF_PAGE_SIZE_US4x6
46        HPDF_PAGE_SIZE_US4x8
47        HPDF_PAGE_SIZE_US5x7
48        HPDF_PAGE_SIZE_COMM10
49        HPDF_PAGE_SIZE_EOF
50    End Enum
51    Public Enum HPdfPageDirection As Integer
52        HPDF_PAGE_PORTRAIT = 0
53        HPDF_PAGE_LANDSCAPE
54    End Enum
55    Public Enum HPdfPageNumStyle As UInt32
56        HPDF_PAGE_NUM_STYLE_DECIMAL = 0
57        HPDF_PAGE_NUM_STYLE_UPPER_ROMAN
58        HPDF_PAGE_NUM_STYLE_LOWER_ROMAN
59        HPDF_PAGE_NUM_STYLE_UPPER_LETTERS
60        HPDF_PAGE_NUM_STYLE_LOWER_LETTERS
61        HPDF_PAGE_NUM_STYLE_EOF
62    End Enum
63    Public Enum HPdfWritingMode As UInt32
64        HPDF_WMODE_HORIZONTAL = 0
65        HPDF_WMODE_VERTICAL
66        HPDF_WMODE_EOF
67    End Enum
68    Public Enum HPdfEncoderType As UInt32
69        HPDF_ENCODER_TYPE_SINGLE_BYTE = 0
70        HPDF_ENCODER_TYPE_DOUBLE_BYTE
71        HPDF_ENCODER_TYPE_UNINITIALIZED
72        HPDF_ENCODER_UNKNOWN
73    End Enum
74    Public Enum HPdfByteType As UInt32
75        HPDF_BYTE_TYPE_SINGLE = 0
76        HPDF_BYTE_TYPE_LEAD
77        HPDF_BYTE_TYPE_TRIAL
78        HPDF_BYTE_TYPE_UNKNOWN
79    End Enum
80    Public Enum HPdfAnnotHighlightMode As UInt32
81        HPDF_ANNOT_NO_HIGHTLIGHT = 0
82        HPDF_ANNOT_INVERT_BOX
83        HPDF_ANNOT_INVERT_BORDER
84        HPDF_ANNOT_DOWN_APPEARANCE
85        HPDF_ANNOT_HIGHTLIGHT_MODE_EOF
86    End Enum
87    Public Enum HPdfAnnotIcon As UInt32
88        HPDF_ANNOT_ICON_COMMENT = 0
89        HPDF_ANNOT_ICON_KEY
90        HPDF_ANNOT_ICON_NOTE
91        HPDF_ANNOT_ICON_HELP
92        HPDF_ANNOT_ICON_NEW_PARAGRAPH
93        HPDF_ANNOT_ICON_PARAGRAPH
94        HPDF_ANNOT_ICON_INSERT
95        HPDF_ANNOT_ICON_EOF
96    End Enum
97    Public Enum HPdfColorSpace As UInt32
98        HPDF_CS_DEVICE_GRAY = 0
99        HPDF_CS_DEVICE_RGB
100        HPDF_CS_DEVICE_CMYK
101        HPDF_CS_CAL_GRAY
102        HPDF_CS_CAL_RGB
103        HPDF_CS_LAB
104        HPDF_CS_ICC_BASED
105        HPDF_CS_SEPARATION
106        HPDF_CS_DEVICE_N
107        HPDF_CS_INDEXED
108        HPDF_CS_PATTERN
109        HPDF_CS_EOF
110    End Enum
111    Public Enum HPdfInfoType As UInt32
112        ' date-time type parameters
113        HPDF_INFO_CREATION_DATE = 0
114        HPDF_INFO_MOD_DATE = 1
115
116        ' string type parameters
117        HPDF_INFO_AUTHOR = 2
118        HPDF_INFO_CREATOR = 3
119        HPDF_INFO_PRODUCER = 4
120        HPDF_INFO_TITLE = 5
121        HPDF_INFO_SUBJECT = 6
122        HPDF_INFO_KEYWORDS = 7
123        HPDF_INFO_EOF = 8
124    End Enum
125    Public Enum HPdfEncryptMode As UInt32
126        HPDF_ENCRYPT_R2 = 2
127        HPDF_ENCRYPT_R3 = 3
128    End Enum
129    Public Enum HPdfTextRenderingMode As UInt32
130        HPDF_FILL = 0
131        HPDF_STROKE = 1
132        HPDF_FILL_THEN_STROKE = 2
133        HPDF_INVISIBLE = 3
134        HPDF_FILL_CLIPPING = 4
135        HPDF_STROKE_CLIPPING = 5
136        HPDF_FILL_STROKE_CLIPPING = 6
137        HPDF_CLIPPING = 7
138        HPDF_RENDERING_MODE_EOF = 8
139    End Enum
140    Public Enum HPdfLineCap As Integer
141        HPDF_BUTT_END = 0
142        HPDF_ROUND_END = 1
143        HPDF_PROJECTING_SCUARE_END = 2
144        HPDF_LINECAP_EOF = 3
145    End Enum
146    Public Enum HPdfLineJoin As Integer
147        HPDF_MITER_JOIN = 0
148        HPDF_ROUND_JOIN = 1
149        HPDF_BEVEL_JOIN = 2
150        HPDF_LINEJOIN_EOF = 3
151    End Enum
152    Public Enum HPdfTextAlignment As Integer
153        HPDF_TALIGN_LEFT = 0
154        HPDF_TALIGN_RIGHT = 1
155        HPDF_TALIGN_CENTER = 2
156        HPDF_TALIGN_JUSTIFY = 3
157    End Enum
158    Public Enum HPdfTransitionStyle As Integer
159        HPDF_TS_WIPE_RIGHT = 0
160        HPDF_TS_WIPE_UP
161        HPDF_TS_WIPE_LEFT
162        HPDF_TS_WIPE_DOWN
163        HPDF_TS_BARN_DOORS_HORIZONTAL_OUT
164        HPDF_TS_BARN_DOORS_HORIZONTAL_IN
165        HPDF_TS_BARN_DOORS_VERTICAL_OUT
166        HPDF_TS_BARN_DOORS_VERTICAL_IN
167        HPDF_TS_BOX_OUT
168        HPDF_TS_BOX_IN
169        HPDF_TS_BLINDS_HORIZONTAL
170        HPDF_TS_BLINDS_VERTICAL
171        HPDF_TS_DISSOLVE
172        HPDF_TS_GLITTER_RIGHT
173        HPDF_TS_GLITTER_DOWN
174        HPDF_TS_GLITTER_TOP_LEFT_TO_BOTTOM_RIGHT
175        HPDF_TS_REPLACE
176        HPDF_TS_EOF
177    End Enum
178    Public Enum HPdfBlendMode As Integer
179        HPDF_BM_NORMAL = 0
180        HPDF_BM_MULTIPLY
181        HPDF_BM_SCREEN
182        HPDF_BM_OVERLAY
183        HPDF_BM_DARKEN
184        HPDF_BM_LIGHTEN
185        HPDF_BM_COLOR_DODGE
186        HPDF_BM_COLOR_BUM
187        HPDF_BM_HARD_LIGHT
188        HPDF_BM_SOFT_LIGHT
189        HPDF_BM_DIFFERENCE
190        HPDF_BM_EXCLUSHON
191        HPDF_BM_EOF
192    End Enum
193    <StructLayout(LayoutKind.Sequential)> Public Structure HPdfRect
194        Public left As Single
195        Public bottom As Single
196        Public right As Single
197        Public top As Single
198    End Structure
199    <StructLayout(LayoutKind.Sequential)> Public Structure HPdfBox
200        Public left As Single
201        Public bottom As Single
202        Public right As Single
203        Public top As Single
204    End Structure
205    <StructLayout(LayoutKind.Sequential)> Public Structure HPdfPoint
206        Public x As Single
207        Public y As Single
208    End Structure
209    <StructLayout(LayoutKind.Sequential)> Public Structure HPdfDate
210        Public year As Int32
211        Public month As Int32
212        Public day As Int32
213        Public hour As Int32
214        Public minutes As Int32
215        Public seconds As Int32
216        Public ind As Char
217        Public off_hour As Int32
218        Public off_minutes As Int32
219    End Structure
220    <StructLayout(LayoutKind.Sequential)> Public Structure HPdfTextWidth
221        Public numchars As UInt32
222        ' don't use this value (it may be change in the feature). use numspace as alternated. */
223        Public numwords As UInt32
224
225        Public width As UInt32
226        Public numspace As UInt32
227    End Structure
228    <StructLayout(LayoutKind.Sequential)> Public Structure HPdfTransMatrix
229        Public a As Single
230        Public b As Single
231        Public c As Single
232        Public d As Single
233        Public x As Single
234        Public y As Single
235    End Structure
236    <StructLayout(LayoutKind.Sequential)> Public Structure HPdfDashMode_Internal
237        Public ptn0 As UInt16
238        Public ptn1 As UInt16
239        Public ptn2 As UInt16
240        Public ptn3 As UInt16
241        Public ptn4 As UInt16
242        Public ptn5 As UInt16
243        Public ptn6 As UInt16
244        Public ptn7 As UInt16
245        Public num_ptn As UInt32
246        Public phase As UInt32
247    End Structure
248    <StructLayout(LayoutKind.Sequential)> Public Structure HPdfDashMode
249        Public ptn As UInt16()
250        Public phase As UInt32
251    End Structure
252    <StructLayout(LayoutKind.Sequential)> Public Structure HPdfRGBColor
253        Public r As Single
254        Public g As Single
255        Public b As Single
256    End Structure
257    <StructLayout(LayoutKind.Sequential)> Public Structure HPdfCMYKColor
258        Public c As Single
259        Public y As Single
260        Public m As Single
261        Public k As Single
262    End Structure
263
264    ' error handler (call back function)
265    Public Delegate Sub HPDF_ErrorHandler(ByVal error_no As uint32, ByVal detail_no As uint32, ByVal user_data As IntPtr)
266
267    Public Class HPdfDoc
268        Implements IDisposable
269
270        Public Const HPDF_TRUE As Integer = 1
271        Public Const HPDF_FALSE As Integer = 0
272        Public Const HPDF_COMP_NONE As UInt32 = 0
273        Public Const HPDF_COMP_TEXT As UInt32 = 1
274        Public Const HPDF_COMP_IMAGE As UInt32 = 2
275        Public Const HPDF_COMP_METADATA As UInt32 = 4
276        Public Const HPDF_COMP_ALL As UInt32 = 15
277
278        Public Const HPDF_HIDE_TOOLBAR As UInt32 = 1
279        Public Const HPDF_HIDE_MENUBAR As UInt32 = 2
280        Public Const HPDF_HIDE_WINDOW_UI As UInt32 = 4
281        Public Const HPDF_FIT_WINDOW As UInt32 = 8
282        Public Const HPDF_CENTER_WINDOW As UInt32 = 16
283
284        Public Const HPDF_ENABLE_READ As UInt32 = 0
285        Public Const HPDF_ENABLE_PRINT As UInt32 = 4
286        Public Const HPDF_ENABLE_EDIT_ALL As UInt32 = 8
287        Public Const HPDF_ENABLE_COPY As UInt32 = 16
288        Public Const HPDF_ENABLE_EDIT As UInt32 = 32
289
290        Private Declare Function HPDF_GetVersion Lib "libhpdf.dll" Alias "HPDF_GetVersion" () As String
291        Private Declare Function HPDF_New Lib "libhpdf.dll" Alias "HPDF_New" (ByVal user_error_fn As HPDF_ErrorHandler, ByVal user_data As IntPtr) As IntPtr
292        Private Declare Sub HPDF_Free Lib "libhpdf.dll" Alias "HPDF_Free" (ByVal pdf As IntPtr)
293        Private Declare Function HPDF_NewDoc Lib "libhpdf.dll" Alias "HPDF_NewDoc" (ByVal pdf As IntPtr) As UInt32
294        Private Declare Function HPDF_FreeDoc Lib "libhpdf.dll" Alias "HPDF_FreeDoc" (ByVal pdf As IntPtr) As UInt32
295        Private Declare Function HPDF_FreeDocAll Lib "libhpdf.dll" Alias "HPDF_FreeDocAll" (ByVal pdf As IntPtr) As UInt32
296        Private Declare Function HPDF_HasDoc Lib "libhpdf.dll" Alias "HPDF_HasDoc" (ByVal pdf As IntPtr) As UInt32
297        Private Declare Function HPDF_SaveToFile Lib "libhpdf.dll" Alias "HPDF_SaveToFile" (ByVal pdf As IntPtr, ByVal file_name As String) As UInt32
298        Private Declare Function HPDF_GetError Lib "libhpdf.dll" Alias "HPDF_GetError" (ByVal pdf As IntPtr) As UInt32
299        Private Declare Function HPDF_GetErrorDetail Lib "libhpdf.dll" Alias "HPDF_GetErrorDetail" (ByVal pdf As IntPtr) As UInt32
300        Private Declare Sub HPDF_ResetError Lib "libhpdf.dll" Alias "HPDF_ResetError" (ByVal pdf As IntPtr)
301        Private Declare Function HPDF_SetPagesConfiguration Lib "libhpdf.dll" Alias "HPDF_SetPagesConfiguration" (ByVal pdf As IntPtr, ByVal page_per_pages As UInt32) As UInt32
302        Private Declare Function HPDF_GetPageByIndex Lib "libhpdf.dll" Alias "HPDF_GetPageByIndex" (ByVal pdf As IntPtr, ByVal index As UInt32) As IntPtr
303        Private Declare Function HPDF_GetPageLayout Lib "libhpdf.dll" Alias "HPDF_GetPageLayout" (ByVal pdf As IntPtr) As HPdfPageLayout
304        Private Declare Function HPDF_SetPageLayout Lib "libhpdf.dll" Alias "HPDF_SetPageLayout" (ByVal pdf As IntPtr, ByVal layout As HPdfPageLayout) As UInt32
305        Private Declare Function HPDF_GetPageMode Lib "libhpdf.dll" Alias "HPDF_GetPageMode" (ByVal pdf As IntPtr) As HPdfPageMode
306        Private Declare Function HPDF_SetPageMode Lib "libhpdf.dll" Alias "HPDF_SetPageMode" (ByVal pdf As IntPtr, ByVal layout As HPdfPageMode) As UInt32
307        Private Declare Function HPDF_SetOpenAction Lib "libhpdf.dll" Alias "HPDF_SetOpenAction" (ByVal pdf As IntPtr, ByVal open_action As IntPtr) As UInt32
308        Private Declare Function HPDF_GetViewerPreference Lib "libhpdf.dll" Alias "HPDF_GetViewerPreference" (ByVal pdf As IntPtr) As UInt32
309        Private Declare Function HPDF_SetViewerPreference Lib "libhpdf.dll" Alias "HPDF_SetViewerPreference" (ByVal pdf As IntPtr, ByVal value As UInt32) As UInt32
310        Private Declare Function HPDF_GetCurrentPage Lib "libhpdf.dll" Alias "HPDF_GetCurrentPage" (ByVal pdf As IntPtr) As IntPtr
311        Private Declare Function HPDF_AddPage Lib "libhpdf.dll" Alias "HPDF_AddPage" (ByVal pdf As IntPtr) As IntPtr
312        Private Declare Function HPDF_InsertPage Lib "libhpdf.dll" Alias "HPDF_InsertPage" (ByVal pdf As IntPtr, ByVal page As IntPtr) As IntPtr
313        Private Declare Function HPDF_GetFont Lib "libhpdf.dll" Alias "HPDF_GetFont" (ByVal pdf As IntPtr, ByVal font_name As String, ByVal encoding_name As String) As IntPtr
314        Private Declare Function HPDF_LoadType1FontFromFile Lib "libhpdf.dll" Alias "HPDF_LoadType1FontFromFile" (ByVal pdf As IntPtr, ByVal afmfilename As String, ByVal pfmfilename As String) As String
315        Private Declare Function HPDF_LoadTTFontFromFile Lib "libhpdf.dll" Alias "HPDF_LoadTTFontFromFile" (ByVal pdf As IntPtr, ByVal file_name As String, ByVal embedding As Int32) As String
316        Private Declare Function HPDF_LoadTTFontFromFile2 Lib "libhpdf.dll" Alias "HPDF_LoadTTFontFromFile2" (ByVal pdf As IntPtr, ByVal file_name As String, ByVal index As UInt32, ByVal embedding As Int32) As String
317        Private Declare Function HPDF_AddPageLabel Lib "libhpdf.dll" Alias "HPDF_AddPageLabel" (ByVal pdf As IntPtr, ByVal page_num As UInt32, ByVal style As HPdfPageNumStyle, ByVal first_page As UInt32, ByVal prefix As UInt32) As IntPtr
318        Private Declare Function HPDF_UseJPFonts Lib "libhpdf.dll" Alias "HPDF_UseJPFonts" (ByVal pdf As IntPtr) As UInt32
319        Private Declare Function HPDF_UseKRFonts Lib "libhpdf.dll" Alias "HPDF_UseKRFonts" (ByVal pdf As IntPtr) As UInt32
320        Private Declare Function HPDF_UseCNSFonts Lib "libhpdf.dll" Alias "HPDF_UseCNSFonts" (ByVal pdf As IntPtr) As UInt32
321        Private Declare Function HPDF_UseCNTFonts Lib "libhpdf.dll" Alias "HPDF_UseCNTFonts" (ByVal pdf As IntPtr) As UInt32
322        Private Declare Function HPDF_CreateOutline Lib "libhpdf.dll" Alias "HPDF_CreateOutline" (ByVal pdf As IntPtr, ByVal parent As IntPtr, ByVal title As String, ByVal encoded As IntPtr) As UInt32
323        Private Declare Function HPDF_GetEncoder Lib "libhpdf.dll" Alias "HPDF_GetEncoder" (ByVal pdf As IntPtr, ByVal encoding_name As String) As IntPtr
324        Private Declare Function HPDF_GetCurrentEncoder Lib "libhpdf.dll" Alias "HPDF_GetCurrentEncoder" (ByVal pdf As IntPtr) As IntPtr
325        Private Declare Function HPDF_SetCurrentEncoder Lib "libhpdf.dll" Alias "HPDF_SetCurrentEncoder" (ByVal pdf As IntPtr, ByVal encoding_name As String) As UInt32
326        Private Declare Function HPDF_UseJPEncodings Lib "libhpdf.dll" Alias "HPDF_UseJPEncodings" (ByVal pdf As IntPtr) As UInt32
327        Private Declare Function HPDF_UseKREncodings Lib "libhpdf.dll" Alias "HPDF_UseKREncodings" (ByVal pdf As IntPtr) As UInt32
328        Private Declare Function HPDF_UseCNSEncodings Lib "libhpdf.dll" Alias "HPDF_UseCNSEncodings" (ByVal pdf As IntPtr) As UInt32
329        Private Declare Function HPDF_UseCNTEncodings Lib "libhpdf.dll" Alias "HPDF_UseCNTEncodings" (ByVal pdf As IntPtr) As UInt32
330        Private Declare Function HPDF_LoadPngImageFromFile Lib "libhpdf.dll" Alias "HPDF_LoadPngImageFromFile" (ByVal pdf As IntPtr, ByVal filename As String) As IntPtr
331        Private Declare Function HPDF_LoadPngImageFromFile2 Lib "libhpdf.dll" Alias "HPDF_LoadPngImageFromFile2" (ByVal pdf As IntPtr, ByVal filename As String) As IntPtr
332        Private Declare Function HPDF_LoadJpegImageFromFile Lib "libhpdf.dll" Alias "HPDF_LoadJpegImageFromFile" (ByVal pdf As IntPtr, ByVal filename As String) As IntPtr
333        Private Declare Function HPDF_LoadRawImageFromFile Lib "libhpdf.dll" Alias "HPDF_LoadRawImageFromFile" (ByVal pdf As IntPtr, ByVal filename As String, ByVal width As UInt32, ByVal height As UInt32, ByVal color_space As HPdfColorSpace) As IntPtr
334        Private Declare Function HPDF_LoadRawImageFromMem Lib "libhpdf.dll" Alias "HPDF_LoadRawImageFromMem" (ByVal pdf As IntPtr, ByVal data As Byte(), ByVal width As UInt32, ByVal height As UInt32, ByVal color_space As HPdfColorSpace, ByVal bits_per_component As UInt32) As IntPtr
335        Private Declare Function HPDF_SetInfoAttr Lib "libhpdf.dll" Alias "HPDF_SetInfoAttr" (ByVal pdf As IntPtr, ByVal type As HPdfInfoType, ByVal value As String) As UInt32
336        Private Declare Function HPDF_SetInfoDateAttr Lib "libhpdf.dll" Alias "HPDF_SetInfoDateAttr" (ByVal pdf As IntPtr, ByVal type As HPdfInfoType, ByVal value As HPdfDate) As UInt32
337        Private Declare Function HPDF_GetInfoAttr Lib "libhpdf.dll" Alias "HPDF_GetInfoAttr" (ByVal pdf As IntPtr, ByVal type As HPdfInfoType) As String
338        Private Declare Function HPDF_SetPassword Lib "libhpdf.dll" Alias "HPDF_SetPassword" (ByVal pdf As IntPtr, ByVal owner_passwd As String, ByVal user_passwd As String) As UInt32
339        Private Declare Function HPDF_SetPermission Lib "libhpdf.dll" Alias "HPDF_SetPermission" (ByVal pdf As IntPtr, ByVal permission As UInt32) As UInt32
340        Private Declare Function HPDF_SetEncryptionMode Lib "libhpdf.dll" Alias "HPDF_SetEncryptionMode" (ByVal pdf As IntPtr, ByVal mode As HPdfEncryptMode, ByVal key_len As UInt32) As UInt32
341        Private Declare Function HPDF_SetCompressionMode Lib "libhpdf.dll" Alias "HPDF_SetCompressionMode" (ByVal pdf As IntPtr, ByVal mode As UInt32) As UInt32
342        Private Declare Function HPDF_CreateExtGState Lib "libhpdf.dll" Alias "HPDF_CreateExtGState" (ByVal pdf As IntPtr) As IntPtr
343
344        Private hpdf As IntPtr
345
346        Public Sub New()
347            Dim error_handler As HPDF_ErrorHandler = New HPDF_ErrorHandler(AddressOf ErrorProc)
348            hpdf = HPDF_New(error_handler, IntPtr.Zero)
349            If (hpdf = IntPtr.Zero) Then
350                Throw New Exception("cannot create HPdfDoc object.")
351            End If
352        End Sub
353
354        Public Sub Dispose() Implements IDisposable.Dispose
355            If (hpdf <> IntPtr.Zero) Then
356                HPDF_Free(hpdf)
357            End If
358
359            hpdf = IntPtr.Zero
360        End Sub
361
362        Public Shared Function HPdfGetVersion() As String
363            Return HPDF_GetVersion()
364        End Function
365
366        Public Shared Sub ErrorProc(ByVal error_no As UInt32, ByVal detail_no As UInt32, ByVal user_data As IntPtr)
367            Dim s As String = "error-code=0x" & error_no.ToString("X") & " detail-code=" & detail_no
368            Throw New Exception(s)
369        End Sub
370
371        Public Sub NewDoc()
372            HPDF_NewDoc(hpdf)
373        End Sub
374
375        Public Sub FreeDoc()
376            HPDF_FreeDoc(hpdf)
377        End Sub
378
379        Public Sub FreeDocAll()
380            HPDF_FreeDocAll(hpdf)
381        End Sub
382
383        Public Function HasDoc() As Boolean
384            Return (HPDF_HasDoc(hpdf) <> 0)
385        End Function
386
387        Public Sub SaveToFile(ByVal file_name As String)
388            HPDF_SaveToFile(hpdf, file_name)
389        End Sub
390
391        Public Function GetError() As UInt32
392            Return HPDF_GetError(hpdf)
393        End Function
394
395        Public Function GetErrorDetail() As UInt32
396            Return HPDF_GetErrorDetail(hpdf)
397        End Function
398
399        Public Sub ResetError()
400            HPDF_ResetError(hpdf)
401        End Sub
402
403        Public Sub SetPagesConfiguration(ByVal page_per_pages As UInt32)
404            HPDF_SetPagesConfiguration(hpdf, page_per_pages)
405        End Sub
406
407        Public Function GetPageByIndex(ByVal index As UInt32) As HPdfPage
408            Dim hpage As IntPtr = HPDF_GetPageByIndex(hpdf, index)
409            Return New HPdfPage(hpage)
410        End Function
411
412        Public Function GetPageLayout() As HPdfPageLayout
413            Return HPDF_GetPageLayout(hpdf)
414        End Function
415
416        Public Sub SetPageLayout(ByRef layout As HPdfPageLayout)
417            HPDF_SetPageLayout(hpdf, layout)
418        End Sub
419
420        Public Function GetPageMode() As HPdfPageMode
421            Return HPDF_GetPageMode(hpdf)
422        End Function
423
424        Public Sub SetPageMode(ByRef mode As HPdfPageMode)
425            HPDF_SetPageMode(hpdf, mode)
426        End Sub
427
428        Public Sub SetOpenAction(ByRef open_action As HPdfDestination)
429            HPDF_SetOpenAction(hpdf, open_action.GetHandle())
430        End Sub
431
432        Public Function GetViewerPreference() As UInt32
433            Return HPDF_GetViewerPreference(hpdf)
434        End Function
435
436        Public Sub SetViewerPreference(ByVal value As UInt32)
437            HPDF_SetViewerPreference(hpdf, value)
438        End Sub
439
440        Public Function GetCurrentPage() As HPdfPage
441            Dim hpage As IntPtr = HPDF_GetCurrentPage(hpdf)
442            Return New HPdfPage(hpage)
443        End Function
444
445        Public Function AddPage() As HPdfPage
446            Dim hpage As IntPtr = HPDF_AddPage(hpdf)
447            Return New HPdfPage(hpage)
448        End Function
449
450        Public Function InsertPage(ByRef page As HPdfPage) As HPdfPage
451            Dim hpage As IntPtr = HPDF_InsertPage(hpdf, page.GetHandle())
452            Return New HPdfPage(hpage)
453        End Function
454
455        Public Function GetFont(ByVal font_name As String, ByVal encoding_name As String) As HPdfFont
456            Dim hfont As IntPtr = HPDF_GetFont(hpdf, font_name, encoding_name)
457            Return New HPdfFont(hfont)
458        End Function
459
460        Public Function LoadType1FontFromFile(ByVal afmfilename As String, ByVal pfmfilename As String) As String
461            Dim font_name As String = HPDF_LoadType1FontFromFile(hpdf, afmfilename, pfmfilename)
462            Return font_name
463        End Function
464
465        Public Function LoadTTFontFromFile(ByVal file_name As String, ByVal embedding As Boolean) As String
466            Dim font_name As String
467            Dim emb As Integer
468
469            If (embedding) Then
470                emb = HPDF_TRUE
471            Else
472                emb = HPDF_FALSE
473            End If
474
475            font_name = HPDF_LoadTTFontFromFile(hpdf, file_name, emb)
476            Return font_name
477        End Function
478
479        Public Function LoadTTFontFromFile2(ByVal file_name As String, ByVal index As UInt32, ByVal embedding As Boolean) As String
480            Dim font_name As String
481            Dim emb As Integer
482
483            If (embedding) Then
484                emb = HPDF_TRUE
485            Else
486                emb = HPDF_FALSE
487            End If
488
489            font_name = HPDF_LoadTTFontFromFile2(hpdf, file_name, index, emb)
490            Return font_name
491        End Function
492
493        Public Sub AddPageLabel(ByVal page_num As UInt32, ByVal style As HPdfPageNumStyle, ByVal first_page As UInt32, ByVal prefix As String)
494            HPDF_AddPageLabel(hpdf, page_num, style, first_page, prefix)
495        End Sub
496
497        Public Function UseJPFonts() As UInt32
498            Return HPDF_UseJPFonts(hpdf)
499        End Function
500
501        Public Function UseKRFonts() As UInt32
502            Return HPDF_UseKRFonts(hpdf)
503        End Function
504
505        Public Function UseCNSFonts() As UInt32
506            Return HPDF_UseCNSFonts(hpdf)
507        End Function
508
509        Public Function UseCNTFonts() As UInt32
510            Return HPDF_UseCNTFonts(hpdf)
511        End Function
512
513        Public Function CreateOutline(ByRef parent As HPdfOutline, ByVal title As String, ByRef encoder As HPdfEncoder) As HPdfOutline
514            Dim hparent As IntPtr
515            Dim hencoder As IntPtr
516            Dim houtline As IntPtr
517
518            If (encoder Is Nothing) Then
519                hencoder = Nothing
520            Else
521                hencoder = encoder.GetHandle()
522            End If
523
524            If (parent Is Nothing) Then
525                hparent = Nothing
526            Else
527                hparent = parent.GetHandle()
528            End If
529
530            houtline = HPDF_CreateOutline(hpdf, hparent, title, hencoder)
531            Return New HPdfOutline(houtline)
532        End Function
533        Public Function GetEncoder(ByVal encoding_name As String) As HPdfEncoder
534            Dim hencoder As IntPtr = HPDF_GetEncoder(hpdf, encoding_name)
535
536            Return New HPdfEncoder(hencoder)
537        End Function
538
539        Public Function GetCurrentEncoder() As HPdfEncoder
540            Dim hencoder As IntPtr = HPDF_GetCurrentEncoder(hpdf)
541
542            Return New HPdfEncoder(hencoder)
543        End Function
544
545        Public Sub SetCurrentEncoder(ByVal encoding_name As String)
546            HPDF_SetCurrentEncoder(hpdf, encoding_name)
547        End Sub
548
549        Public Function UseJPEncodings() As UInt32
550            Return HPDF_UseJPEncodings(hpdf)
551        End Function
552
553        Public Function UseKREncodings() As UInt32
554            Return HPDF_UseKREncodings(hpdf)
555        End Function
556
557        Public Function UseCNSEncodings() As UInt32
558            Return HPDF_UseCNSEncodings(hpdf)
559        End Function
560
561        Public Function UseCNTEncodings() As UInt32
562            Return HPDF_UseCNTEncodings(hpdf)
563        End Function
564
565        Public Function LoadPngImageFromFile(ByVal filename As String) As HPdfImage
566            Dim hobj As IntPtr = HPDF_LoadPngImageFromFile(hpdf, filename)
567
568            Return New HPdfImage(hobj)
569        End Function
570
571        Public Function LoadPngImageFromFile2(ByVal filename As String) As HPdfImage
572            Dim hobj As IntPtr = HPDF_LoadPngImageFromFile2(hpdf, filename)
573
574            Return New HPdfImage(hobj)
575        End Function
576
577        Public Function LoadJpegImageFromFile(ByVal filename As String) As HPdfImage
578            Dim hobj As IntPtr = HPDF_LoadJpegImageFromFile(hpdf, filename)
579
580            Return New HPdfImage(hobj)
581        End Function
582
583        Public Function LoadRawImageFromFile(ByVal filename As String, ByVal width As UInt32, ByVal height As UInt32, ByRef color_space As HPdfColorSpace) As HPdfImage
584            Dim hobj As IntPtr = HPDF_LoadRawImageFromFile(hpdf, filename, width, height, color_space)
585
586            Return New HPdfImage(hobj)
587        End Function
588
589        Public Function LoadRawImageFromMem(ByVal data As Byte(), ByVal width As Int32, ByVal height As Int32, ByRef color_space As HPdfColorSpace, ByVal bits_per_component As UInt32) As HPdfImage
590            If (width * height < data.Length) Then
591                Dim s As String = "error-code=0x1030 detail-code=0"
592                Throw New Exception(s)
593            End If
594
595            Dim hobj As IntPtr = HPDF_LoadRawImageFromMem(hpdf, data, width, height, color_space, bits_per_component)
596
597            Return New HPdfImage(hobj)
598        End Function
599
600        Public Sub SetInfoAttr(ByVal type As HPdfInfoType, ByVal value As String)
601            HPDF_SetInfoAttr(hpdf, type, value)
602        End Sub
603
604        Public Sub SetInfoDateAttr(ByVal type As HPdfInfoType, ByRef value As HPdfDate)
605            HPDF_SetInfoDateAttr(hpdf, type, value)
606        End Sub
607
608        Public Function GetInfoAttr(ByVal type As HPdfInfoType) As String
609            Return HPDF_GetInfoAttr(hpdf, type)
610        End Function
611
612        Public Sub SetPassword(ByVal owner_passwd As String, ByVal user_passwd As String)
613            HPDF_SetPassword(hpdf, owner_passwd, user_passwd)
614        End Sub
615
616        Public Sub SetPermission(ByVal permission As UInt32)
617            HPDF_SetPermission(hpdf, permission)
618        End Sub
619
620        Public Sub SetEncryptionMode(ByVal mode As HPdfEncryptMode, ByVal key_len As UInt32)
621            HPDF_SetEncryptionMode(hpdf, mode, key_len)
622        End Sub
623
624        Public Sub SetCompressionMode(ByVal mode As UInt32)
625            HPDF_SetCompressionMode(hpdf, mode)
626        End Sub
627
628        Public Function CreateExtGState() As HPdfExtGState
629            Dim hgstate As IntPtr = HPDF_CreateExtGState(hpdf)
630
631            Return New HPdfExtGState(hgstate)
632        End Function
633    End Class
634    Public Class HPdfPage
635        Public Const HPDF_TRUE As Integer = 1
636        Public Const HPDF_FALSE As Integer = 0
637
638        Private Declare Function HPDF_Page_SetWidth Lib "libhpdf.dll" Alias "HPDF_Page_SetWidth" (ByVal page As IntPtr, ByVal value As Single) As UInt32
639        Private Declare Function HPDF_Page_SetHeight Lib "libhpdf.dll" Alias "HPDF_Page_SetHeight" (ByVal page As IntPtr, ByVal value As Single) As UInt32
640        Private Declare Function HPDF_Page_SetSize Lib "libhpdf.dll" Alias "HPDF_Page_SetSize" (ByVal page As IntPtr, ByVal size As HPdfPageSizes, ByVal direction As HPdfPageDirection) As UInt32
641        Private Declare Function HPDF_Page_SetRotate Lib "libhpdf.dll" Alias "HPDF_Page_SetRotate" (ByVal page As IntPtr, ByVal angle As UInt16) As UInt16
642        Private Declare Function HPDF_Page_CreateDestination Lib "libhpdf.dll" Alias "HPDF_Page_CreateDestination" (ByVal page As IntPtr) As IntPtr
643        Private Declare Function HPDF_Page_CreateTextAnnot Lib "libhpdf.dll" Alias "HPDF_Page_CreateTextAnnot" (ByVal page As IntPtr, ByVal rect As HPdfRect, ByVal text As String, ByVal encoder As IntPtr) As IntPtr
644        Private Declare Function HPDF_Page_CreateLinkAnnot Lib "libhpdf.dll" Alias "HPDF_Page_CreateLinkAnnot" (ByVal page As IntPtr, ByVal rect As HPdfRect, ByVal dst As IntPtr) As IntPtr
645        Private Declare Function HPDF_Page_CreateURILinkAnnot Lib "libhpdf.dll" Alias "HPDF_Page_CreateURILinkAnnot" (ByVal page As IntPtr, ByVal rect As HPdfRect, ByVal url As String) As IntPtr
646        Private Declare Function HPDF_Page_TextWidth Lib "libhpdf.dll" Alias "HPDF_Page_TextWidth" (ByVal page As IntPtr, ByVal text As String) As Single
647        Private Declare Function HPDF_Page_MeasureText Lib "libhpdf.dll" Alias "HPDF_Page_MeasureText" (ByVal page As IntPtr, ByVal text As String, ByVal width As Single, ByVal wordwrap As Int32, ByRef real_width As Single) As UInt32
648        Private Declare Function HPDF_Page_GetWidth Lib "libhpdf.dll" Alias "HPDF_Page_GetWidth" (ByVal page As IntPtr) As Single
649        Private Declare Function HPDF_Page_GetHeight Lib "libhpdf.dll" Alias "HPDF_Page_GetHeight" (ByVal page As IntPtr) As Single
650        Private Declare Function HPDF_Page_GetGMode Lib "libhpdf.dll" Alias "HPDF_Page_GetGMode" (ByVal page As IntPtr) As UInt16
651        Private Declare Function HPDF_Page_GetCurrentPos Lib "libhpdf.dll" Alias "HPDF_Page_GetCurrentPos" (ByVal page As IntPtr) As HPdfPoint
652        Private Declare Function HPDF_Page_GetCurrentTextPos Lib "libhpdf.dll" Alias "HPDF_Page_GetCurrentTextPos" (ByVal page As IntPtr) As HPdfPoint
653        Private Declare Function HPDF_Page_GetCurrentFont Lib "libhpdf.dll" Alias "HPDF_Page_GetCurrentFont" (ByVal page As IntPtr) As IntPtr
654        Private Declare Function HPDF_Page_GetCurrentFontSize Lib "libhpdf.dll" Alias "HPDF_Page_GetCurrentFontSize" (ByVal page As IntPtr) As Single
655        Private Declare Function HPDF_Page_GetTransMatrix Lib "libhpdf.dll" Alias "HPDF_Page_GetTransMatrix" (ByVal page As IntPtr) As HPdfTransMatrix
656        Private Declare Function HPDF_Page_GetLineWidth Lib "libhpdf.dll" Alias "HPDF_Page_GetLineWidth" (ByVal page As IntPtr) As Single
657        Private Declare Function HPDF_Page_GetLineCap Lib "libhpdf.dll" Alias "HPDF_Page_GetLineCap" (ByVal page As IntPtr) As HPdfLineCap
658        Private Declare Function HPDF_Page_GetLineJoin Lib "libhpdf.dll" Alias "HPDF_Page_GetLineJoin" (ByVal page As IntPtr) As HPdfLineJoin
659        Private Declare Function HPDF_Page_GetMiterLimit Lib "libhpdf.dll" Alias "HPDF_Page_GetMiterLimit" (ByVal page As IntPtr) As Single
660        Private Declare Function HPDF_Page_GetDash Lib "libhpdf.dll" Alias "HPDF_Page_GetDash" (ByVal page As IntPtr) As HPdfDashMode_Internal
661        Private Declare Function HPDF_Page_GetFlat Lib "libhpdf.dll" Alias "HPDF_Page_GetFlat" (ByVal page As IntPtr) As Single
662        Private Declare Function HPDF_Page_GetCharSpace Lib "libhpdf.dll" Alias "HPDF_Page_GetCharSpace" (ByVal page As IntPtr) As Single
663        Private Declare Function HPDF_Page_GetWordSpace Lib "libhpdf.dll" Alias "HPDF_Page_GetWordSpace" (ByVal page As IntPtr) As Single
664        Private Declare Function HPDF_Page_GetHorizontalScalling Lib "libhpdf.dll" Alias "HPDF_Page_GetHorizontalScalling" (ByVal page As IntPtr) As Single
665        Private Declare Function HPDF_Page_GetTextLeading Lib "libhpdf.dll" Alias "HPDF_Page_GetTextLeading" (ByVal page As IntPtr) As Single
666        Private Declare Function HPDF_Page_GetTextRenderingMode Lib "libhpdf.dll" Alias "HPDF_Page_GetTextRenderingMode" (ByVal page As IntPtr) As HPdfTextRenderingMode
667        Private Declare Function HPDF_Page_GetTextRaise Lib "libhpdf.dll" Alias "HPDF_Page_GetTextRaise" (ByVal page As IntPtr) As Single
668        Private Declare Function HPDF_Page_GetRGBFill Lib "libhpdf.dll" Alias "HPDF_Page_GetRGBFill" (ByVal page As IntPtr) As HPdfRGBColor
669        Private Declare Function HPDF_Page_GetRGBStroke Lib "libhpdf.dll" Alias "HPDF_Page_GetRGBStroke" (ByVal page As IntPtr) As HPdfRGBColor
670        Private Declare Function HPDF_Page_GetCMYKFill Lib "libhpdf.dll" Alias "HPDF_Page_GetCMYKFill" (ByVal page As IntPtr) As HPdfCMYKColor
671        Private Declare Function HPDF_Page_GetCMYKStroke Lib "libhpdf.dll" Alias "HPDF_Page_GetCMYKStroke" (ByVal page As IntPtr) As HPdfCMYKColor
672        Private Declare Function HPDF_Page_GetGrayFill Lib "libhpdf.dll" Alias "HPDF_Page_GetGrayFill" (ByVal page As IntPtr) As Single
673        Private Declare Function HPDF_Page_GetGrayStroke Lib "libhpdf.dll" Alias "HPDF_Page_GetGrayStroke" (ByVal page As IntPtr) As Single
674        Private Declare Function HPDF_Page_GetStrokingColorSpace Lib "libhpdf.dll" Alias "HPDF_Page_GetStrokingColorSpace" (ByVal page As IntPtr) As HPdfColorSpace
675        Private Declare Function HPDF_Page_GetFillingColorSpace Lib "libhpdf.dll" Alias "HPDF_Page_GetFillingColorSpace" (ByVal page As IntPtr) As HPdfColorSpace
676        Private Declare Function HPDF_Page_GetTextMatrix Lib "libhpdf.dll" Alias "HPDF_Page_GetTextMatrix" (ByVal page As IntPtr) As HPdfTransMatrix
677        Private Declare Function HPDF_Page_GetGStateDepth Lib "libhpdf.dll" Alias "HPDF_Page_GetGStateDepth" (ByVal page As IntPtr) As UInt32
678
679        ' --- General graphics state -----------------------------------------------
680        Private Declare Function HPDF_Page_SetLineWidth Lib "libhpdf.dll" Alias "HPDF_Page_SetLineWidth" (ByVal page As IntPtr, ByVal line_width As Single) As UInt32
681        Private Declare Function HPDF_Page_SetLineCap Lib "libhpdf.dll" Alias "HPDF_Page_SetLineCap" (ByVal page As IntPtr, ByVal line_cap As HPdfLineCap) As UInt32
682        Private Declare Function HPDF_Page_SetLineJoin Lib "libhpdf.dll" Alias "HPDF_Page_SetLineJoin" (ByVal page As IntPtr, ByVal line_join As HPdfLineJoin) As UInt32
683        Private Declare Function HPDF_Page_SetMiterLimit Lib "libhpdf.dll" Alias "HPDF_Page_SetMiterLimit" (ByVal page As IntPtr, ByVal miter_limit As Single) As UInt32
684        Private Declare Function HPDF_Page_SetDash Lib "libhpdf.dll" Alias "HPDF_Page_SetDash" (ByVal page As IntPtr, ByVal array As UInt16(), ByVal num_param As UInt32, ByVal phase As UInt32) As UInt32
685        Private Declare Function HPDF_Page_SetFlat Lib "libhpdf.dll" Alias "HPDF_Page_SetFlat" (ByVal page As IntPtr, ByVal flatness As Single) As UInt32
686        Private Declare Function HPDF_Page_SetExtGState Lib "libhpdf.dll" Alias "HPDF_Page_SetExtGState" (ByVal page As IntPtr, ByVal ext_gstate As IntPtr) As UInt32
687        Private Declare Function HPDF_Page_GSave Lib "libhpdf.dll" Alias "HPDF_Page_GSave" (ByVal page As IntPtr) As UInt32
688        Private Declare Function HPDF_Page_GRestore Lib "libhpdf.dll" Alias "HPDF_Page_GRestore" (ByVal page As IntPtr) As UInt32
689        Private Declare Function HPDF_Page_Concat Lib "libhpdf.dll" Alias "HPDF_Page_Concat" (ByVal page As IntPtr, ByVal a As Single, ByVal b As Single, ByVal c As Single, ByVal d As Single, ByVal x As Single, ByVal y As Single) As UInt32
690        Private Declare Function HPDF_Page_MoveTo Lib "libhpdf.dll" Alias "HPDF_Page_MoveTo" (ByVal page As IntPtr, ByVal x As Single, ByVal y As Single) As UInt32
691        Private Declare Function HPDF_Page_LineTo Lib "libhpdf.dll" Alias "HPDF_Page_LineTo" (ByVal page As IntPtr, ByVal x As Single, ByVal y As Single) As UInt32
692        Private Declare Function HPDF_Page_CurveTo Lib "libhpdf.dll" Alias "HPDF_Page_CurveTo" (ByVal page As IntPtr, ByVal x1 As Single, ByVal y1 As Single, ByVal x2 As Single, ByVal y2 As Single, ByVal x3 As Single, ByVal y3 As Single) As UInt32
693        Private Declare Function HPDF_Page_CurveTo2 Lib "libhpdf.dll" Alias "HPDF_Page_CurveTo2" (ByVal page As IntPtr, ByVal x2 As Single, ByVal y2 As Single, ByVal x3 As Single, ByVal y3 As Single) As UInt32
694        Private Declare Function HPDF_Page_CurveTo3 Lib "libhpdf.dll" Alias "HPDF_Page_CurveTo3" (ByVal page As IntPtr, ByVal x1 As Single, ByVal y1 As Single, ByVal x3 As Single, ByVal y3 As Single) As UInt32
695        Private Declare Function HPDF_Page_ClosePath Lib "libhpdf.dll" Alias "HPDF_Page_ClosePath" (ByVal page As IntPtr) As UInt32
696        Private Declare Function HPDF_Page_Rectangle Lib "libhpdf.dll" Alias "HPDF_Page_Rectangle" (ByVal page As IntPtr, ByVal x As Single, ByVal y As Single, ByVal width As Single, ByVal height As Single) As UInt32
697        Private Declare Function HPDF_Page_Stroke Lib "libhpdf.dll" Alias "HPDF_Page_Stroke" (ByVal page As IntPtr) As UInt32
698        Private Declare Function HPDF_Page_ClosePathStroke Lib "libhpdf.dll" Alias "HPDF_Page_ClosePathStroke" (ByVal page As IntPtr) As UInt32
699        Private Declare Function HPDF_Page_Fill Lib "libhpdf.dll" Alias "HPDF_Page_Fill" (ByVal page As IntPtr) As UInt32
700        Private Declare Function HPDF_Page_Eofill Lib "libhpdf.dll" Alias "HPDF_Page_Eofill" (ByVal page As IntPtr) As UInt32
701        Private Declare Function HPDF_Page_FillStroke Lib "libhpdf.dll" Alias "HPDF_Page_FillStroke" (ByVal page As IntPtr) As UInt32
702        Private Declare Function HPDF_Page_EofillStroke Lib "libhpdf.dll" Alias "HPDF_Page_EofillStroke" (ByVal page As IntPtr) As UInt32
703        Private Declare Function HPDF_Page_ClosePathFillStroke Lib "libhpdf.dll" Alias "HPDF_Page_ClosePathFillStroke" (ByVal page As IntPtr) As UInt32
704        Private Declare Function HPDF_Page_ClosePathEofillStroke Lib "libhpdf.dll" Alias "HPDF_Page_ClosePathEofillStroke" (ByVal page As IntPtr) As UInt32
705        Private Declare Function HPDF_Page_EndPath Lib "libhpdf.dll" Alias "HPDF_Page_EndPath" (ByVal page As IntPtr) As UInt32
706
707        ' --- Clipping paths operator --------------------------------------------
708        Private Declare Function HPDF_Page_Clip Lib "libhpdf.dll" Alias "HPDF_Page_Clip" (ByVal page As IntPtr) As UInt32
709        Private Declare Function HPDF_Page_Eoclip Lib "libhpdf.dll" Alias "HPDF_Page_Eoclip" (ByVal page As IntPtr) As UInt32
710
711        ' --- Text object operator -----------------------------------------------
712        Private Declare Function HPDF_Page_BeginText Lib "libhpdf.dll" Alias "HPDF_Page_BeginText" (ByVal page As IntPtr) As UInt32
713        Private Declare Function HPDF_Page_EndText Lib "libhpdf.dll" Alias "HPDF_Page_EndText" (ByVal page As IntPtr) As UInt32
714
715        ' --- Text state ---------------------------------------------------------
716        Private Declare Function HPDF_Page_SetCharSpace Lib "libhpdf.dll" Alias "HPDF_Page_SetCharSpace" (ByVal page As IntPtr, ByVal value As Single) As UInt32
717        Private Declare Function HPDF_Page_SetWordSpace Lib "libhpdf.dll" Alias "HPDF_Page_SetWordSpace" (ByVal page As IntPtr, ByVal value As Single) As UInt32
718        Private Declare Function HPDF_Page_SetHorizontalScalling Lib "libhpdf.dll" Alias "HPDF_Page_SetHorizontalScalling" (ByVal page As IntPtr, ByVal value As Single) As UInt32
719        Private Declare Function HPDF_Page_SetTextLeading Lib "libhpdf.dll" Alias "HPDF_Page_SetTextLeading" (ByVal page As IntPtr, ByVal value As Single) As UInt32
720        Private Declare Function HPDF_Page_SetFontAndSize Lib "libhpdf.dll" Alias "HPDF_Page_SetFontAndSize" (ByVal page As IntPtr, ByVal hfont As IntPtr, ByVal size As Single) As UInt32
721        Private Declare Function HPDF_Page_SetTextRenderingMode Lib "libhpdf.dll" Alias "HPDF_Page_SetTextRenderingMode" (ByVal page As IntPtr, ByVal mode As HPdfTextRenderingMode) As UInt32
722        Private Declare Function HPDF_Page_SetTextRaise Lib "libhpdf.dll" Alias "HPDF_Page_SetTextRaise" (ByVal page As IntPtr, ByVal value As Single) As UInt32
723
724        ' --- Text positioning ---------------------------------------------------
725        Private Declare Function HPDF_Page_MoveTextPos Lib "libhpdf.dll" Alias "HPDF_Page_MoveTextPos" (ByVal page As IntPtr, ByVal x As Single, ByVal y As Single) As UInt32
726        Private Declare Function HPDF_Page_MoveTextPos2 Lib "libhpdf.dll" Alias "HPDF_Page_MoveTextPos2" (ByVal page As IntPtr, ByVal x As Single, ByVal y As Single) As UInt32
727        Private Declare Function HPDF_Page_SetTextMatrix Lib "libhpdf.dll" Alias "HPDF_Page_SetTextMatrix" (ByVal page As IntPtr, ByVal a As Single, ByVal b As Single, ByVal c As Single, ByVal d As Single, ByVal x As Single, ByVal y As Single) As UInt32
728        Private Declare Function HPDF_Page_MoveToNextLine Lib "libhpdf.dll" Alias "HPDF_Page_MoveToNextLine" (ByVal page As IntPtr) As UInt32
729
730        ' --- Text showing -------------------------------------------------------
731        Private Declare Function HPDF_Page_ShowText Lib "libhpdf.dll" Alias "HPDF_Page_ShowText" (ByVal page As IntPtr, ByVal text As String) As UInt32
732        Private Declare Function HPDF_Page_ShowTextNextLine Lib "libhpdf.dll" Alias "HPDF_Page_ShowTextNextLine" (ByVal page As IntPtr, ByVal text As String) As UInt32
733        Private Declare Function HPDF_Page_ShowTextNextLineEx Lib "libhpdf.dll" Alias "HPDF_Page_ShowTextNextLineEx" (ByVal page As IntPtr, ByVal word_space As Single, ByVal char_space As Single, ByVal text As String) As UInt32
734
735        ' --- Color showing ------------------------------------------------------
736        Private Declare Function HPDF_Page_SetGrayFill Lib "libhpdf.dll" Alias "HPDF_Page_SetGrayFill" (ByVal page As IntPtr, ByVal gray As Single) As UInt32
737        Private Declare Function HPDF_Page_SetGrayStroke Lib "libhpdf.dll" Alias "HPDF_Page_SetGrayStroke" (ByVal page As IntPtr, ByVal gray As Single) As UInt32
738        Private Declare Function HPDF_Page_SetRGBFill Lib "libhpdf.dll" Alias "HPDF_Page_SetRGBFill" (ByVal page As IntPtr, ByVal r As Single, ByVal g As Single, ByVal b As Single) As UInt32
739        Private Declare Function HPDF_Page_SetRGBStroke Lib "libhpdf.dll" Alias "HPDF_Page_SetRGBStroke" (ByVal page As IntPtr, ByVal r As Single, ByVal g As Single, ByVal b As Single) As UInt32
740        Private Declare Function HPDF_Page_SetCMYKFill Lib "libhpdf.dll" Alias "HPDF_Page_SetCMYKFill" (ByVal page As IntPtr, ByVal c As Single, ByVal m As Single, ByVal y As Single, ByVal k As Single) As UInt32
741        Private Declare Function HPDF_Page_SetCMYKStroke Lib "libhpdf.dll" Alias "HPDF_Page_SetCMYKStroke" (ByVal page As IntPtr, ByVal c As Single, ByVal m As Single, ByVal y As Single, ByVal k As Single) As UInt32
742        Private Declare Function HPDF_Page_ExecuteXObject Lib "libhpdf.dll" Alias "HPDF_Page_ExecuteXObject" (ByVal page As IntPtr, ByVal obj As IntPtr) As UInt32
743
744        ' ---------------------------------------------------------------------
745        Private Declare Function HPDF_Page_DrawImage Lib "libhpdf.dll" Alias "HPDF_Page_DrawImage" (ByVal page As IntPtr, ByVal image As IntPtr, ByVal x As Single, ByVal y As Single, ByVal width As Single, ByVal height As Single) As UInt32
746        Private Declare Function HPDF_Page_Circle Lib "libhpdf.dll" Alias "HPDF_Page_Circle" (ByVal page As IntPtr, ByVal x As Single, ByVal y As Single, ByVal ray As Single) As UInt32
747        Private Declare Function HPDF_Page_Arc Lib "libhpdf.dll" Alias "HPDF_Page_Arc" (ByVal page As IntPtr, ByVal x As Single, ByVal y As Single, ByVal ray As Single, ByVal ang1 As Single, ByVal ang2 As Single) As UInt32
748        Private Declare Function HPDF_Page_Ellipse Lib "libhpdf.dll" Alias "HPDF_Page_Ellipse" (ByVal page As IntPtr, ByVal x As Single, ByVal y As Single, ByVal xray As Single, ByVal yray As Single) As UInt32
749        Private Declare Function HPDF_Page_TextOut Lib "libhpdf.dll" Alias "HPDF_Page_TextOut" (ByVal page As IntPtr, ByVal xpos As Single, ByVal ypos As Single, ByVal text As String) As UInt32
750        Private Declare Function HPDF_Page_TextRect Lib "libhpdf.dll" Alias "HPDF_Page_TextRect" (ByVal page As IntPtr, ByVal left As Single, ByVal top As Single, ByVal right As Single, ByVal bottom As Single, ByVal text As String, ByVal align As HPdfTextAlignment, ByRef len As UInt32) As UInt32
751        Private Declare Function HPDF_Page_SetSlideShow Lib "libhpdf.dll" Alias "HPDF_Page_SetSlideShow" (ByVal page As IntPtr, ByVal type As HPdfTransitionStyle, ByVal disp_time As Single, ByVal trans_time As Single) As UInt32
752
753        ' handle to an instance of a HPDF_Doc object.
754        Private hpage As IntPtr
755
756        Public Sub New(ByVal hpage As IntPtr)
757            If (hpage = IntPtr.Zero) Then
758                Throw New Exception("cannot create HPdfPage object.")
759            End If
760
761            Me.hpage = hpage
762        End Sub
763
764        Public Sub SetWidth(ByVal value As Single)
765            HPDF_Page_SetWidth(hpage, value)
766        End Sub
767
768        Public Sub SetHeight(ByVal value As Single)
769            HPDF_Page_SetHeight(hpage, value)
770        End Sub
771
772        Public Sub SetSize(ByVal size As HPdfPageSizes, ByVal direction As HPdfPageDirection)
773            HPDF_Page_SetSize(hpage, size, direction)
774        End Sub
775
776        Public Sub SetRotate(ByVal angle As UInt16)
777            HPDF_Page_SetRotate(hpage, angle)
778        End Sub
779
780        Public Function CreateDestination() As HPdfDestination
781            Dim hdest As IntPtr = HPDF_Page_CreateDestination(hpage)
782            Return New HPdfDestination(hdest)
783        End Function
784
785        Public Function CreateTextAnnot(ByVal rect As HPdfRect, ByVal text As String, ByRef encoder As HPdfEncoder) As HPdfAnnotation
786            Dim hannot As IntPtr = HPDF_Page_CreateTextAnnot(hpage, rect, text, encoder.GetHandle())
787            Return New HPdfAnnotation(hannot)
788        End Function
789
790        Public Function CreateLinkAnnot(ByVal rect As HPdfRect, ByRef dst As HPdfDestination) As HPdfAnnotation
791            Dim hannot As IntPtr = HPDF_Page_CreateLinkAnnot(hpage, rect, dst.GetHandle())
792            Return New HPdfAnnotation(hannot)
793        End Function
794
795        Public Function CreateURILinkAnnot(ByVal rect As HPdfRect, ByVal uri As String) As HPdfAnnotation
796            Dim hannot As IntPtr = HPDF_Page_CreateURILinkAnnot(hpage, rect, uri)
797            Return New HPdfAnnotation(hannot)
798        End Function
799
800        Public Function TextWidth(ByVal text As String) As Single
801            Return HPDF_Page_TextWidth(hpage, text)
802        End Function
803
804        Public Function MeasureText(ByVal text As String, ByVal width As Single, ByVal wordwrap As Boolean, ByRef real_width As Single) As UInt32
805            Dim ww As Int32
806
807            If (wordwrap) Then
808                ww = HPDF_TRUE
809            Else
810                ww = HPDF_FALSE
811            End If
812
813            Return HPDF_Page_MeasureText(hpage, text, width, ww, real_width)
814        End Function
815
816        Public Function MeasureText(ByVal text As String, ByVal width As Single, ByVal wordwrap As Boolean) As UInt32
817            Dim dummy As Single
818            Dim ww As Int32
819
820            If (wordwrap) Then
821                ww = HPDF_TRUE
822            Else
823                ww = HPDF_FALSE
824            End If
825
826            Return HPDF_Page_MeasureText(hpage, text, width, ww, dummy)
827        End Function
828
829        Public Function GetWidth() As Single
830            Return HPDF_Page_GetWidth(hpage)
831        End Function
832
833        Public Function GetHeight() As Single
834            Return HPDF_Page_GetHeight(hpage)
835        End Function
836
837        Public Function GetGMode() As UInt16
838            Return HPDF_Page_GetGMode(hpage)
839        End Function
840
841        Public Function GetCurrentPos() As HPdfPoint
842            Return HPDF_Page_GetCurrentPos(hpage)
843        End Function
844
845        Public Function GetCurrentTextPos() As HPdfPoint
846            Return HPDF_Page_GetCurrentTextPos(hpage)
847        End Function
848
849        Public Function GetCurrentFont() As HPdfFont
850            Return New HPdfFont(HPDF_Page_GetCurrentFont(hpage))
851        End Function
852
853        Public Function GetCurrentFontSize() As Single
854            Return HPDF_Page_GetCurrentFontSize(hpage)
855        End Function
856
857        Public Function GetTransMatrix() As HPdfTransMatrix
858            Return HPDF_Page_GetTransMatrix(hpage)
859        End Function
860
861        Public Function GetLineWidth() As Single
862            Return HPDF_Page_GetLineWidth(hpage)
863        End Function
864
865        Public Function GetLineCap() As HPdfLineCap
866            Return HPDF_Page_GetLineCap(hpage)
867        End Function
868
869        Public Function GetLineJoin() As HPdfLineJoin
870            Return HPDF_Page_GetLineJoin(hpage)
871        End Function
872
873        Public Function GetMiterLimit() As Single
874            Return HPDF_Page_GetMiterLimit(hpage)
875        End Function
876
877        Public Function GetDash() As HPdfDashMode
878            Dim mode1 As HPdfDashMode_Internal = HPDF_Page_GetDash(hpage)
879            Dim mode2 As HPdfDashMode
880
881            mode2.phase = mode1.phase
882            ReDim mode2.ptn(mode1.num_ptn)
883
884            If (mode1.num_ptn >= 1) Then
885                mode2.ptn(0) = mode1.ptn0
886            End If
887
888            If (mode1.num_ptn >= 2) Then
889                mode2.ptn(1) = mode1.ptn1
890            End If
891
892            If (mode1.num_ptn >= 3) Then
893                mode2.ptn(2) = mode1.ptn2
894            End If
895
896            If (mode1.num_ptn >= 4) Then
897                mode2.ptn(3) = mode1.ptn3
898            End If
899
900            If (mode1.num_ptn >= 5) Then
901                mode2.ptn(4) = mode1.ptn4
902            End If
903
904            If (mode1.num_ptn >= 6) Then
905                mode2.ptn(5) = mode1.ptn5
906            End If
907
908            If (mode1.num_ptn >= 7) Then
909                mode2.ptn(6) = mode1.ptn6
910            End If
911
912            If (mode1.num_ptn >= 8) Then
913                mode2.ptn(7) = mode1.ptn7
914            End If
915
916            Return mode2
917        End Function
918
919        Public Function GetFlat() As Single
920            Return HPDF_Page_GetFlat(hpage)
921        End Function
922
923        Public Function GetCharSpace() As Single
924            Return HPDF_Page_GetCharSpace(hpage)
925        End Function
926
927        Public Function GetWordSpace() As Single
928            Return HPDF_Page_GetWordSpace(hpage)
929        End Function
930
931        Public Function GetHorizontalScalling() As Single
932            Return HPDF_Page_GetHorizontalScalling(hpage)
933        End Function
934
935        Public Function GetTextLeading() As Single
936            Return HPDF_Page_GetTextLeading(hpage)
937        End Function
938
939        Public Function GetTextRenderingMode() As HPdfTextRenderingMode
940            Return HPDF_Page_GetTextRenderingMode(hpage)
941        End Function
942
943        Public Function GetTextRaise() As Single
944            Return HPDF_Page_GetTextRaise(hpage)
945        End Function
946
947        Public Function GetRGBFill() As HPdfRGBColor
948            Return HPDF_Page_GetRGBFill(hpage)
949        End Function
950
951        Public Function GetRGBStroke() As HPdfRGBColor
952            Return HPDF_Page_GetRGBStroke(hpage)
953        End Function
954
955        Public Function GetCMYKFill() As HPdfCMYKColor
956            Return HPDF_Page_GetCMYKFill(hpage)
957        End Function
958
959        Public Function GetCMYKStroke() As HPdfCMYKColor
960            Return HPDF_Page_GetCMYKStroke(hpage)
961        End Function
962
963        Public Function GetGrayFill() As Single
964            Return HPDF_Page_GetGrayFill(hpage)
965        End Function
966
967        Public Function GetGrayStroke() As Single
968            Return HPDF_Page_GetGrayStroke(hpage)
969        End Function
970
971        Public Function GetStrokingColorSpace() As HPdfColorSpace
972            Return HPDF_Page_GetStrokingColorSpace(hpage)
973        End Function
974
975        Public Function GetFillingColorSpace() As HPdfColorSpace
976            Return HPDF_Page_GetFillingColorSpace(hpage)
977        End Function
978
979        Public Function GetTextMatrix() As HPdfTransMatrix
980            Return HPDF_Page_GetTextMatrix(hpage)
981        End Function
982
983        Public Function GetGStateDepth() As UInt32
984            Return HPDF_Page_GetGStateDepth(hpage)
985        End Function
986
987        Public Sub SetLineWidth(ByVal line_width As Single)
988            HPDF_Page_SetLineWidth(hpage, line_width)
989        End Sub
990
991        Public Sub SetLineCap(ByVal line_cap As HPdfLineCap)
992            HPDF_Page_SetLineCap(hpage, line_cap)
993        End Sub
994
995        Public Sub SetLineJoin(ByVal line_join As HPdfLineJoin)
996            HPDF_Page_SetLineJoin(hpage, line_join)
997        End Sub
998
999        Public Sub SetMiterLimit(ByVal miter_limit As Single)
1000            HPDF_Page_SetMiterLimit(hpage, miter_limit)
1001        End Sub
1002
1003        Public Sub SetDash(ByRef dash_ptn As UInt16(), ByVal phase As UInt32)
1004            If (dash_ptn Is Nothing) Then
1005                HPDF_Page_SetDash(hpage, dash_ptn, 0, 0)
1006                Return
1007            End If
1008
1009            Dim len As UInt32 = dash_ptn.Length
1010
1011            HPDF_Page_SetDash(hpage, dash_ptn, len, phase)
1012
1013        End Sub
1014
1015        Public Sub SetFlat(ByVal flatness As Single)
1016            HPDF_Page_SetFlat(hpage, flatness)
1017        End Sub
1018
1019        Public Sub SetExtGState(ByVal gstate As HPdfExtGState)
1020            HPDF_Page_SetExtGState(hpage, gstate.GetHandle())
1021        End Sub
1022
1023        Public Sub GSave()
1024            HPDF_Page_GSave(hpage)
1025        End Sub
1026
1027        Public Sub GRestore()
1028            HPDF_Page_GRestore(hpage)
1029        End Sub
1030
1031        Public Sub Concat(ByVal a As Single, ByVal b As Single, ByVal c As Single, ByVal d As Single, ByVal x As Single, ByVal y As Single)
1032            HPDF_Page_Concat(hpage, a, b, c, d, x, y)
1033        End Sub
1034
1035        Public Sub MoveTo(ByVal x As Single, ByVal y As Single)
1036            HPDF_Page_MoveTo(hpage, x, y)
1037        End Sub
1038
1039        Public Sub LineTo(ByVal x As Single, ByVal y As Single)
1040            HPDF_Page_LineTo(hpage, x, y)
1041        End Sub
1042
1043        Public Sub CurveTo(ByVal x1 As Single, ByVal y1 As Single, ByVal x2 As Single, ByVal y2 As Single, ByVal x3 As Single, ByVal y3 As Single)
1044            HPDF_Page_CurveTo(hpage, x1, y1, x2, y2, x3, y3)
1045        End Sub
1046
1047        Public Sub CurveTo2(ByVal x2 As Single, ByVal y2 As Single, ByVal x3 As Single, ByVal y3 As Single)
1048            HPDF_Page_CurveTo2(hpage, x2, y2, x3, y3)
1049        End Sub
1050        Public Sub CurveTo3(ByVal x1 As Single, ByVal y1 As Single, ByVal x3 As Single, ByVal y3 As Single)
1051            HPDF_Page_CurveTo2(hpage, x1, y1, x3, y3)
1052        End Sub
1053
1054        Public Sub ClosePath()
1055            HPDF_Page_ClosePath(hpage)
1056        End Sub
1057
1058        Public Sub Rectangle(ByVal x As Single, ByVal y As Single, ByVal width As Single, ByVal height As Single)
1059            HPDF_Page_Rectangle(hpage, x, y, width, height)
1060        End Sub
1061
1062        Public Sub Stroke()
1063            HPDF_Page_Stroke(hpage)
1064        End Sub
1065
1066        Public Sub ClosePathStroke()
1067            HPDF_Page_ClosePathStroke(hpage)
1068        End Sub
1069
1070        Public Sub Fill()
1071            HPDF_Page_Fill(hpage)
1072        End Sub
1073
1074        Public Sub Eofill()
1075            HPDF_Page_Eofill(hpage)
1076        End Sub
1077
1078        Public Sub FillStroke()
1079            HPDF_Page_FillStroke(hpage)
1080        End Sub
1081
1082        Public Sub EofillStroke()
1083            HPDF_Page_EofillStroke(hpage)
1084        End Sub
1085
1086        Public Sub ClosePathFillStroke()
1087            HPDF_Page_ClosePathFillStroke(hpage)
1088        End Sub
1089
1090        Public Sub ClosePathEofillStroke()
1091            HPDF_Page_ClosePathEofillStroke(hpage)
1092        End Sub
1093
1094        Public Sub EndPath()
1095            HPDF_Page_EndPath(hpage)
1096        End Sub
1097
1098        Public Sub Clip()
1099            HPDF_Page_Clip(hpage)
1100        End Sub
1101
1102        Public Sub Eoclip()
1103            HPDF_Page_Eoclip(hpage)
1104        End Sub
1105
1106        Public Sub BeginText()
1107            HPDF_Page_BeginText(hpage)
1108        End Sub
1109
1110        Public Sub EndText()
1111            HPDF_Page_EndText(hpage)
1112        End Sub
1113
1114        Public Sub SetCharSpace(ByVal value As Single)
1115            HPDF_Page_SetCharSpace(hpage, value)
1116        End Sub
1117
1118        Public Sub SetWordSpace(ByVal value As Single)
1119            HPDF_Page_SetWordSpace(hpage, value)
1120        End Sub
1121
1122        Public Sub SetHorizontalScalling(ByVal value As Single)
1123            HPDF_Page_SetHorizontalScalling(hpage, value)
1124        End Sub
1125
1126        Public Sub SetTextLeading(ByVal value As Single)
1127            HPDF_Page_SetTextLeading(hpage, value)
1128        End Sub
1129
1130        Public Sub SetFontAndSize(ByRef font As HPdfFont, ByVal size As Single)
1131            HPDF_Page_SetFontAndSize(hpage, font.GetHandle(), size)
1132        End Sub
1133
1134        Public Sub SetTextRenderingMode(ByVal mode As HPdfTextRenderingMode)
1135            HPDF_Page_SetTextRenderingMode(hpage, mode)
1136        End Sub
1137
1138        Public Sub SetTextRaise(ByVal value As Single)
1139            HPDF_Page_SetTextRaise(hpage, value)
1140        End Sub
1141
1142        Public Sub MoveTextPos(ByVal x As Single, ByVal y As Single)
1143            HPDF_Page_MoveTextPos(hpage, x, y)
1144        End Sub
1145
1146        Public Sub MoveTextPos2(ByVal x As Single, ByVal y As Single)
1147            HPDF_Page_MoveTextPos2(hpage, x, y)
1148        End Sub
1149
1150        Public Sub SetTextMatrix(ByVal a As Single, ByVal b As Single, ByVal c As Single, ByVal d As Single, ByVal x As Single, ByVal y As Single)
1151            HPDF_Page_SetTextMatrix(hpage, a, b, c, d, x, y)
1152        End Sub
1153
1154        Public Sub MoveToNextLine()
1155            HPDF_Page_MoveToNextLine(hpage)
1156        End Sub
1157
1158        Public Sub ShowText(ByVal text As String)
1159            HPDF_Page_ShowText(hpage, text)
1160        End Sub
1161
1162        Public Sub ShowTextNextLine(ByVal text As String)
1163            HPDF_Page_ShowTextNextLine(hpage, text)
1164        End Sub
1165
1166        Public Sub ShowTextNextLineEx(ByVal word_space As Single, ByVal char_space As Single, ByVal text As String)
1167            HPDF_Page_ShowTextNextLineEx(hpage, word_space, char_space, text)
1168        End Sub
1169
1170        Public Sub SetGrayFill(ByVal gray As Single)
1171            HPDF_Page_SetGrayFill(hpage, gray)
1172        End Sub
1173
1174        Public Sub SetGrayStroke(ByVal gray As Single)
1175            HPDF_Page_SetGrayStroke(hpage, gray)
1176        End Sub
1177
1178        Public Sub SetRGBFill(ByVal r As Single, ByVal g As Single, ByVal b As Single)
1179            HPDF_Page_SetRGBFill(hpage, r, g, b)
1180        End Sub
1181
1182        Public Sub SetRGBStroke(ByVal r As Single, ByVal g As Single, ByVal b As Single)
1183            HPDF_Page_SetRGBStroke(hpage, r, g, b)
1184        End Sub
1185
1186        Public Sub SetCMYKFill(ByVal c As Single, ByVal m As Single, ByVal y As Single, ByVal k As Single)
1187            HPDF_Page_SetCMYKFill(hpage, c, m, y, k)
1188        End Sub
1189
1190        Public Sub SetCMYKStroke(ByVal c As Single, ByVal m As Single, ByVal y As Single, ByVal k As Single)
1191            HPDF_Page_SetCMYKStroke(hpage, c, m, y, k)
1192        End Sub
1193
1194        Public Sub ExecuteXObject(ByRef xobj As HPdfImage)
1195            HPDF_Page_ExecuteXObject(hpage, xobj.GetHandle())
1196        End Sub
1197
1198        Public Sub DrawImage(ByRef image As HPdfImage, ByVal x As Single, ByVal y As Single, ByVal width As Single, ByVal height As Single)
1199            HPDF_Page_DrawImage(hpage, image.GetHandle(), x, y, width, height)
1200        End Sub
1201
1202        Public Sub Circle(ByVal x As Single, ByVal y As Single, ByVal ray As Single)
1203            HPDF_Page_Circle(hpage, x, y, ray)
1204        End Sub
1205
1206        Public Sub Arc(ByVal x As Single, ByVal y As Single, ByVal ray As Single, ByVal ang1 As Single, ByVal ang2 As Single)
1207            HPDF_Page_Arc(hpage, x, y, ray, ang1, ang2)
1208        End Sub
1209
1210        Public Sub TextOut(ByVal xpos As Single, ByVal ypos As Single, ByVal text As String)
1211            HPDF_Page_TextOut(hpage, xpos, ypos, text)
1212        End Sub
1213
1214        Public Sub TextRect(ByVal left As Single, ByVal top As Single, ByVal right As Single, ByVal bottom As Single, ByVal text As String, ByVal align As HPdfTextAlignment, ByRef len As UInt32)
1215            HPDF_Page_TextRect(hpage, left, top, right, bottom, text, align, len)
1216        End Sub
1217
1218        Public Sub SetSlideShow(ByVal type As HPdfTransitionStyle, ByVal disp_time As Single, ByVal trans_time As Single)
1219            HPDF_Page_SetSlideShow(hpage, type, disp_time, trans_time)
1220        End Sub
1221
1222        Public Function GetHandle() As IntPtr
1223            Return hpage
1224        End Function
1225
1226    End Class
1227    Public Class HPdfFont
1228        Private Declare Function HPDF_Outline_SetOpened Lib "libhpdf.dll" Alias "HPDF_Outline_SetOpened" (ByVal houtline As IntPtr, ByVal opened As Int32) As UInt32
1229
1230        Private Declare Function HPDF_Font_GetFontName Lib "libhpdf.dll" Alias "HPDF_Font_GetFontName" (ByVal hfont As IntPtr) As String
1231        Private Declare Function HPDF_Font_GetEncodingName Lib "libhpdf.dll" Alias "HPDF_Font_GetEncodingName" (ByVal hfont As IntPtr) As String
1232        Private Declare Function HPDF_Font_GetUnicodeWidth Lib "libhpdf.dll" Alias "HPDF_Font_GetUnicodeWidth" (ByVal hfont As IntPtr, ByVal code As UInt16) As Int32
1233        Private Declare Function HPDF_Font_GetBBox Lib "libhpdf.dll" Alias "HPDF_Font_GetBBox" (ByVal hfont As IntPtr) As HPdfBox
1234        Private Declare Function HPDF_Font_GetAscent Lib "libhpdf.dll" Alias "HPDF_Font_GetAscent" (ByVal hfont As IntPtr) As Int32
1235        Private Declare Function HPDF_Font_GetDescent Lib "libhpdf.dll" Alias "HPDF_Font_GetDescent" (ByVal hfont As IntPtr) As Int32
1236        Private Declare Function HPDF_Font_GetXHeight Lib "libhpdf.dll" Alias "HPDF_Font_GetXHeight" (ByVal hfont As IntPtr) As UInt32
1237        Private Declare Function HPDF_Font_GetCapHeight Lib "libhpdf.dll" Alias "HPDF_Font_GetCapHeight" (ByVal hfont As IntPtr) As UInt32
1238        Private Declare Function HPDF_Font_TextWidth Lib "libhpdf.dll" Alias "HPDF_Font_TextWidth" (ByVal hfont As IntPtr, ByVal text As String, ByVal len As UInt16) As HPdfTextWidth
1239        Private Declare Function HPDF_Font_MeasureText Lib "libhpdf.dll" Alias "HPDF_Font_MeasureText" (ByVal hfont As IntPtr, ByVal text As String, ByVal len As UInt16, _
1240                                                                                                        ByVal width As Single, ByVal font_size As Single, ByVal char_space As Single, ByVal word_space As Single, ByVal wordwrap As Int32, ByRef real_width As Single) As UInt32
1241
1242        Private hfont As IntPtr
1243
1244        Public Sub New(ByVal hfont As IntPtr)
1245            If (hfont = IntPtr.Zero) Then
1246                Throw New Exception("cannot create HPdfFont object.")
1247            End If
1248
1249            Me.hfont = hfont
1250        End Sub
1251
1252        Public Function GetHandle() As IntPtr
1253            Return hfont
1254        End Function
1255
1256        Public Function GetFontName() As String
1257            Return HPDF_Font_GetFontName(hfont)
1258        End Function
1259
1260        Public Function GetEncodingName() As String
1261            Return HPDF_Font_GetEncodingName(hfont)
1262        End Function
1263
1264        Public Function GetUnicodeWidth(ByVal code As UInt16) As Int32
1265            Return HPDF_Font_GetUnicodeWidth(hfont, code)
1266        End Function
1267
1268        Public Function GetBBox() As HPdfBox
1269            Return HPDF_Font_GetBBox(hfont)
1270        End Function
1271
1272        Public Function GetAscent() As Int32
1273            Return HPDF_Font_GetAscent(hfont)
1274        End Function
1275
1276        Public Function GetDescent() As Int32
1277            Return HPDF_Font_GetDescent(hfont)
1278        End Function
1279
1280        Public Function GetXHeight() As UInt32
1281            Return HPDF_Font_GetXHeight(hfont)
1282        End Function
1283
1284        Public Function GetCapHeight() As UInt32
1285            Return HPDF_Font_GetCapHeight(hfont)
1286        End Function
1287
1288        Public Function TextWidth(ByVal text As String, ByVal len As UInt32) As HPdfTextWidth
1289            Return HPDF_Font_TextWidth(hfont, text, len)
1290        End Function
1291
1292        Public Function MeasureText(ByVal text As String, ByVal len As UInt32, ByVal width As Single, _
1293                                    ByVal font_size As Single, ByVal char_space As Single, ByVal word_space As Single, _
1294                                    ByVal wordwrap As Int32, ByRef real_width As Single) As UInt32
1295
1296            Return HPDF_Font_MeasureText(hfont, text, len, width, font_size, char_space, word_space, wordwrap, real_width)
1297        End Function
1298    End Class
1299    Public Class HPdfOutline
1300
1301        Private Declare Function HPDF_Outline_SetOpened Lib "libhpdf.dll" Alias "HPDF_Outline_SetOpened" (ByVal houtline As IntPtr, ByVal opened As Int32) As UInt32
1302        Private Declare Function HPDF_Outline_SetDestination Lib "libhpdf.dll" Alias "HPDF_Outline_SetDestination" (ByVal houtline As IntPtr, ByVal hdest As IntPtr) As UInt32
1303
1304        Private houtline As IntPtr
1305
1306        Public Sub New(ByVal houtline As IntPtr)
1307            If (houtline = IntPtr.Zero) Then
1308                Throw New Exception("cannot create HPdfOutline object.")
1309            End If
1310
1311            Me.houtline = houtline
1312        End Sub
1313
1314        Public Function GetHandle() As IntPtr
1315            Return houtline
1316        End Function
1317
1318        Public Sub SetOpened(ByVal opened As Boolean)
1319            Dim iopened As Int32
1320
1321            If (opened) Then
1322                iopened = HPdfDoc.HPDF_TRUE
1323            Else
1324                iopened = HPdfDoc.HPDF_FALSE
1325            End If
1326
1327            HPDF_Outline_SetOpened(houtline, iopened)
1328        End Sub
1329
1330        Public Sub SetDestination(ByRef dest As HPdfDestination)
1331            HPDF_Outline_SetDestination(houtline, dest.GetHandle())
1332        End Sub
1333
1334    End Class
1335    Public Class HPdfEncoder
1336        Private Declare Function HPDF_Encoder_GetType Lib "libhpdf.dll" Alias "HPDF_Encoder_GetType" (ByVal hencoder As IntPtr) As HPdfEncoderType
1337        Private Declare Function HPDF_Encoder_GetByteType Lib "libhpdf.dll" Alias "HPDF_Encoder_GetByteType" (ByVal hencoder As IntPtr, ByVal text As String, ByVal index As UInt32) As HPdfByteType
1338        Private Declare Function HPDF_Encoder_GetUnicode Lib "libhpdf.dll" Alias "HPDF_Encoder_GetUnicode" (ByVal hencoder As IntPtr, ByVal code As UInt16) As UInt16
1339        Private Declare Function HPDF_Encoder_GetWritingMode Lib "libhpdf.dll" Alias "HPDF_Encoder_GetWritingMode" (ByVal hencoder As IntPtr) As HPdfWritingMode
1340
1341        Private hencoder As IntPtr
1342
1343        Public Sub New(ByVal hencoder As IntPtr)
1344            If (hencoder = IntPtr.Zero) Then
1345                Throw New Exception("cannot create HPdfEncoder object.")
1346            End If
1347
1348            Me.hencoder = hencoder
1349        End Sub
1350
1351        Public Function GetHandle() As IntPtr
1352            Return hencoder
1353        End Function
1354
1355        Public Function GetEncoderType() As HPdfEncoderType
1356            Return HPDF_Encoder_GetType(hencoder)
1357        End Function
1358
1359        Public Function GetByteType(ByVal text As String, ByVal index As UInt32) As HPdfByteType
1360            Return HPDF_Encoder_GetByteType(hencoder, text, index)
1361        End Function
1362
1363        Public Function GetUnicode(ByVal code As UInt16) As UInt16
1364            Return HPDF_Encoder_GetUnicode(hencoder, code)
1365        End Function
1366
1367        Public Function GetWritingMode() As HPdfWritingMode
1368            Return HPDF_Encoder_GetWritingMode(hencoder)
1369        End Function
1370    End Class
1371    Public Class HPdfDestination
1372        Private Declare Function HPDF_Destination_SetXYZ Lib "libhpdf.dll" Alias "HPDF_Destination_SetXYZ" (ByVal hdest As IntPtr, ByVal left As Single, ByVal top As Single, ByVal zoom As Single) As UInt32
1373        Private Declare Function HPDF_Destination_SetFit Lib "libhpdf.dll" Alias "HPDF_Destination_SetFit" (ByVal hdest As IntPtr) As UInt32
1374        Private Declare Function HPDF_Destination_SetFitH Lib "libhpdf.dll" Alias "HPDF_Destination_SetFitH" (ByVal hdest As IntPtr, ByVal top As Single) As UInt32
1375        Private Declare Function HPDF_Destination_SetFitV Lib "libhpdf.dll" Alias "HPDF_Destination_SetFitV" (ByVal hdest As IntPtr, ByVal left As Single) As UInt32
1376        Private Declare Function HPDF_Destination_SetFitR Lib "libhpdf.dll" Alias "HPDF_Destination_SetFitR" (ByVal hdest As IntPtr, ByVal left As Single, ByVal bottom As Single, ByVal right As Single, ByVal top As Single) As UInt32
1377        Private Declare Function HPDF_Destination_SetFitB Lib "libhpdf.dll" Alias "HPDF_Destination_SetFitB" (ByVal hdest As IntPtr) As UInt32
1378        Private Declare Function HPDF_Destination_SetFitBH Lib "libhpdf.dll" Alias "HPDF_Destination_SetFitBH" (ByVal hdest As IntPtr, ByVal top As Single) As UInt32
1379        Private Declare Function HPDF_Destination_SetFitBV Lib "libhpdf.dll" Alias "HPDF_Destination_SetFitBV" (ByVal hdest As IntPtr, ByVal left As Single) As UInt32
1380
1381        Private hdest As IntPtr
1382
1383        Public Sub New(ByVal hdest As IntPtr)
1384            If (hdest = IntPtr.Zero) Then
1385                Throw New Exception("cannot create HPdfDestination object.")
1386            End If
1387
1388            Me.hdest = hdest
1389        End Sub
1390
1391        Public Sub SetXYZ(ByVal left As Single, ByVal top As Single, ByVal zoom As Single)
1392            HPDF_Destination_SetXYZ(hdest, left, top, zoom)
1393        End Sub
1394
1395        Public Sub SetFit()
1396            HPDF_Destination_SetFit(hdest)
1397        End Sub
1398
1399        Public Sub SetFitH(ByVal top As Single)
1400            HPDF_Destination_SetFitH(hdest, top)
1401        End Sub
1402
1403        Public Sub SetFitV(ByVal left As Single)
1404            HPDF_Destination_SetFitV(hdest, left)
1405        End Sub
1406
1407        Public Sub SetFitR(ByVal left As Single, ByVal bottom As Single, ByVal right As Single, ByVal top As Single)
1408            HPDF_Destination_SetFitR(hdest, left, bottom, right, top)
1409        End Sub
1410
1411        Public Sub SetFitB()
1412            HPDF_Destination_SetFitB(hdest)
1413        End Sub
1414
1415        Public Sub SetFitBH(ByVal top As Single)
1416            HPDF_Destination_SetFitBH(hdest, top)
1417        End Sub
1418
1419        Public Sub SetFitBV(ByVal left As Single)
1420            HPDF_Destination_SetFitBV(hdest, left)
1421        End Sub
1422
1423        Public Function GetHandle() As IntPtr
1424            Return hdest
1425        End Function
1426    End Class
1427    Public Class HPdfAnnotation
1428
1429        Private Declare Function HPDF_LinkAnnot_SetHighlightMode Lib "libhpdf.dll" Alias "HPDF_LinkAnnot_SetHighlightMode" (ByVal hannot As IntPtr, ByVal mode As HPdfAnnotHighlightMode) As UInt32
1430        Private Declare Function HPDF_LinkAnnot_SetBorderStyle Lib "libhpdf.dll" Alias "HPDF_LinkAnnot_SetBorderStyle" (ByVal hannot As IntPtr, ByVal width As Single, ByVal dash_on As UInt16, ByVal dash_off As UInt16) As UInt32
1431        Private Declare Function HPDF_TextAnnot_SetIcon Lib "libhpdf.dll" Alias "HPDF_TextAnnot_SetIcon" (ByVal hannot As IntPtr, ByVal icon As HPdfAnnotIcon) As UInt32
1432        Private Declare Function HPDF_TextAnnot_SetOpened Lib "libhpdf.dll" Alias "HPDF_TextAnnot_SetOpened" (ByVal hannot As IntPtr, ByVal opened As Int32) As UInt32
1433
1434        Private hannot As IntPtr
1435
1436        Public Sub New(ByVal hannot As IntPtr)
1437            If (hannot = IntPtr.Zero) Then
1438                Throw New Exception("cannot create HPdfAnnotation object.")
1439            End If
1440
1441            Me.hannot = hannot
1442        End Sub
1443
1444        Public Function GetHandle() As IntPtr
1445            Return hannot
1446        End Function
1447
1448        Public Sub SetHighlightMode(ByVal mode As HPdfAnnotHighlightMode)
1449            HPDF_LinkAnnot_SetHighlightMode(hannot, mode)
1450        End Sub
1451
1452        Public Sub SetBorderStyle(ByVal width As Single, ByVal dash_on As UInt16, ByVal dash_off As UInt16)
1453            HPDF_LinkAnnot_SetBorderStyle(hannot, width, dash_on, dash_off)
1454        End Sub
1455
1456        Public Sub SetIcon(ByVal icon As HPdfAnnotIcon)
1457            HPDF_TextAnnot_SetIcon(hannot, icon)
1458        End Sub
1459
1460        Public Sub SetOpened(ByVal opened As Boolean)
1461            Dim flg As Int32
1462
1463            If (opened) Then
1464                flg = HPdfDoc.HPDF_TRUE
1465            Else
1466                flg = HPdfDoc.HPDF_FALSE
1467            End If
1468
1469            HPDF_TextAnnot_SetOpened(hannot, flg)
1470        End Sub
1471
1472    End Class
1473    Public Class HPdfXObject
1474        Protected hobj As IntPtr
1475
1476        Public Sub New(ByVal hobj As IntPtr)
1477            If (hobj = IntPtr.Zero) Then
1478                Throw New Exception("cannot create HPdfImage object.")
1479            End If
1480
1481            Me.hobj = hobj
1482        End Sub
1483
1484        Public Function GetHandle() As IntPtr
1485            Return hobj
1486        End Function
1487    End Class
1488    Public Class HPdfImage
1489        Inherits HPdfXObject
1490
1491        Private Declare Function HPDF_Image_GetSize Lib "libhpdf.dll" Alias "HPDF_Image_GetSize" (ByVal image As IntPtr) As HPdfPoint
1492        Private Declare Function HPDF_Image_GetWidth Lib "libhpdf.dll" Alias "HPDF_Image_GetWidth" (ByVal image As IntPtr) As UInt32
1493        Private Declare Function HPDF_Image_GetHeight Lib "libhpdf.dll" Alias "HPDF_Image_GetHeight" (ByVal image As IntPtr) As UInt32
1494        Private Declare Function HPDF_Image_GetBitsPerComponent Lib "libhpdf.dll" Alias "HPDF_Image_GetBitsPerComponent" (ByVal image As IntPtr) As UInt32
1495        Private Declare Function HPDF_Image_GetColorSpace Lib "libhpdf.dll" Alias "HPDF_Image_GetColorSpace" (ByVal image As IntPtr) As String
1496        Private Declare Function HPDF_Image_SetColorMask Lib "libhpdf.dll" Alias "HPDF_Image_SetColorMask" (ByVal image As IntPtr, ByVal rmin As UInt32, ByVal rmax As UInt32, ByVal gmin As UInt32, ByVal gmax As UInt32, ByVal bmin As UInt32, ByVal bmax As UInt32) As UInt32
1497        Private Declare Function HPDF_Image_SetMaskImage Lib "libhpdf.dll" Alias "HPDF_Image_SetMaskImage" (ByVal image As IntPtr, ByVal image_mask As IntPtr) As String
1498
1499        Public Sub New(ByVal hobj As IntPtr)
1500            MyBase.New(hobj)
1501        End Sub
1502
1503        Public Function GetWidth() As UInt32
1504            Return HPDF_Image_GetWidth(hobj)
1505        End Function
1506
1507        Public Function GetHeight() As UInt32
1508            Return HPDF_Image_GetHeight(hobj)
1509        End Function
1510
1511        Public Function GetBitsPerComponent() As UInt32
1512            Return HPDF_Image_GetBitsPerComponent(hobj)
1513        End Function
1514
1515        Public Function GetColorSpace() As String
1516            Return HPDF_Image_GetColorSpace(hobj)
1517        End Function
1518
1519        Public Sub SetColorMask(ByVal rmin As UInt32, ByVal rmax As UInt32, ByVal gmin As UInt32, ByVal gmax As UInt32, ByVal bmin As UInt32, ByVal bmax As UInt32)
1520            HPDF_Image_SetColorMask(hobj, rmin, rmax, gmin, gmax, bmin, bmax)
1521        End Sub
1522
1523        Public Sub SetMaskImage(ByRef mask_image As HPdfImage)
1524            HPDF_Image_SetMaskImage(hobj, mask_image.GetHandle())
1525        End Sub
1526
1527    End Class
1528    Public Class HPdfExtGState
1529        Private Declare Function HPDF_ExtGState_SetAlphaStroke Lib "libhpdf.dll" Alias "HPDF_ExtGState_SetAlphaStroke" (ByVal gstate As IntPtr, ByVal value As Single) As UInt32
1530        Private Declare Function HPDF_ExtGState_SetAlphaFill Lib "libhpdf.dll" Alias "HPDF_ExtGState_SetAlphaFill" (ByVal gstate As IntPtr, ByVal value As Single) As UInt32
1531        Private Declare Function HPDF_ExtGState_SetBlendMode Lib "libhpdf.dll" Alias "HPDF_ExtGState_SetBlendMode" (ByVal gstate As IntPtr, ByVal mode As HPdfBlendMode) As UInt32
1532
1533        Protected hgstate As IntPtr
1534
1535        Public Sub New(ByVal hgstate As IntPtr)
1536            If (hgstate = IntPtr.Zero) Then
1537                Throw New Exception("cannot create HPdfImage object.")
1538            End If
1539
1540            Me.hgstate = hgstate
1541        End Sub
1542
1543        Public Function GetHandle() As IntPtr
1544            Return hgstate
1545        End Function
1546
1547        Public Sub SetAlphaStroke(ByVal value As Single)
1548            HPDF_ExtGState_SetAlphaStroke(hgstate, value)
1549        End Sub
1550
1551        Public Sub SetAlphaFill(ByVal value As Single)
1552            HPDF_ExtGState_SetAlphaFill(hgstate, value)
1553        End Sub
1554
1555        Public Sub SetBlendMode(ByVal mode As HPdfBlendMode)
1556            HPDF_ExtGState_SetBlendMode(hgstate, mode)
1557        End Sub
1558
1559    End Class
1560
1561End Namespace
1562