1 /*
2 * << Haru Free PDF Library 2.0.6 >> -- hpdf.cs
3 *
4 * C# wrapper for libhpdf.dll
5 *
6 * Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
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
17 using System;
18 using System.Runtime.InteropServices;
19
20
21 namespace HPdf {
22
23 public enum HPdfPageLayout : uint {
24 HPDF_PAGE_LAYOUT_SINGLE = 0,
25 HPDF_PAGE_LAYOUT_ONE_COLUMN,
26 HPDF_PAGE_LAYOUT_TWO_CLUMN_LEFT,
27 HPDF_PAGE_LAYOUT_TWO_CLUMN_RIGHT,
28 HPDF_PAGE_LAYOUT_EOF
29 };
30
31 public enum HPdfPageMode : uint {
32 HPDF_PAGE_MODE_USE_NONE = 0,
33 HPDF_PAGE_MODE_USE_OUTLINE,
34 HPDF_PAGE_MODE_USE_THUMBS,
35 HPDF_PAGE_MODE_FULL_SCREEN,
36 HPDF_PAGE_MODE_EOF
37 };
38
39 public enum HPdfPageSizes : uint {
40 HPDF_PAGE_SIZE_LETTER = 0,
41 HPDF_PAGE_SIZE_LEGAL,
42 HPDF_PAGE_SIZE_A3,
43 HPDF_PAGE_SIZE_A4,
44 HPDF_PAGE_SIZE_A5,
45 HPDF_PAGE_SIZE_B4,
46 HPDF_PAGE_SIZE_B5,
47 HPDF_PAGE_SIZE_EXECUTIVE,
48 HPDF_PAGE_SIZE_US4x6,
49 HPDF_PAGE_SIZE_US4x8,
50 HPDF_PAGE_SIZE_US5x7,
51 HPDF_PAGE_SIZE_COMM10,
52 HPDF_PAGE_SIZE_EOF
53 };
54
55
56 public enum HPdfPageDirection : uint {
57 HPDF_PAGE_PORTRAIT = 0,
58 HPDF_PAGE_LANDSCAPE
59 };
60
61
62 public enum HPdfPageNumStyle : uint {
63 HPDF_PAGE_NUM_STYLE_DECIMAL = 0,
64 HPDF_PAGE_NUM_STYLE_UPPER_ROMAN,
65 HPDF_PAGE_NUM_STYLE_LOWER_ROMAN,
66 HPDF_PAGE_NUM_STYLE_UPPER_LETTERS,
67 HPDF_PAGE_NUM_STYLE_LOWER_LETTERS,
68 HPDF_PAGE_NUM_STYLE_EOF
69 };
70
71 public enum HPdfWritingMode : uint {
72 HPDF_WMODE_HORIZONTAL = 0,
73 HPDF_WMODE_VERTICAL,
74 HPDF_WMODE_EOF
75 };
76
77
78 public enum HPdfEncoderType : uint {
79 HPDF_ENCODER_TYPE_SINGLE_BYTE = 0,
80 HPDF_ENCODER_TYPE_DOUBLE_BYTE,
81 HPDF_ENCODER_TYPE_UNINITIALIZED,
82 HPDF_ENCODER_UNKNOWN
83 };
84
85
86 public enum HPdfByteType : uint {
87 HPDF_BYTE_TYPE_SINGLE = 0,
88 HPDF_BYTE_TYPE_LEAD,
89 HPDF_BYTE_TYPE_TRIAL,
90 HPDF_BYTE_TYPE_UNKNOWN
91 };
92
93
94 public enum HPdfAnnotHighlightMode : uint {
95 HPDF_ANNOT_NO_HIGHTLIGHT = 0,
96 HPDF_ANNOT_INVERT_BOX,
97 HPDF_ANNOT_INVERT_BORDER,
98 HPDF_ANNOT_DOWN_APPEARANCE,
99 HPDF_ANNOT_HIGHTLIGHT_MODE_EOF
100 };
101
102
103 public enum HPdfAnnotIcon : uint {
104 HPDF_ANNOT_ICON_COMMENT = 0,
105 HPDF_ANNOT_ICON_KEY,
106 HPDF_ANNOT_ICON_NOTE,
107 HPDF_ANNOT_ICON_HELP,
108 HPDF_ANNOT_ICON_NEW_PARAGRAPH,
109 HPDF_ANNOT_ICON_PARAGRAPH,
110 HPDF_ANNOT_ICON_INSERT,
111 HPDF_ANNOT_ICON_EOF
112 };
113
114 public enum HPdfColorSpace : uint {
115 HPDF_CS_DEVICE_GRAY = 0,
116 HPDF_CS_DEVICE_RGB,
117 HPDF_CS_DEVICE_CMYK,
118 HPDF_CS_CAL_GRAY,
119 HPDF_CS_CAL_RGB,
120 HPDF_CS_LAB,
121 HPDF_CS_ICC_BASED,
122 HPDF_CS_SEPARATION,
123 HPDF_CS_DEVICE_N,
124 HPDF_CS_INDEXED,
125 HPDF_CS_PATTERN,
126 HPDF_CS_EOF
127 };
128
129
130 public enum HPdfInfoType : uint {
131 /* date-time type parameters */
132 HPDF_INFO_CREATION_DATE = 0,
133 HPDF_INFO_MOD_DATE = 1,
134
135 /* string type parameters */
136 HPDF_INFO_AUTHOR = 2,
137 HPDF_INFO_CREATOR = 3,
138 HPDF_INFO_PRODUCER = 4,
139 HPDF_INFO_TITLE = 5,
140 HPDF_INFO_SUBJECT = 6,
141 HPDF_INFO_KEYWORDS = 7,
142 HPDF_INFO_EOF = 8
143 };
144
145 public enum HPdfEncryptMode: uint {
146 HPDF_ENCRYPT_R2 = 2,
147 HPDF_ENCRYPT_R3 = 3
148 };
149
150 public enum HPdfTextRenderingMode: uint {
151 HPDF_FILL = 0,
152 HPDF_STROKE = 1,
153 HPDF_FILL_THEN_STROKE = 2,
154 HPDF_INVISIBLE = 3,
155 HPDF_FILL_CLIPPING = 4,
156 HPDF_STROKE_CLIPPING = 5,
157 HPDF_FILL_STROKE_CLIPPING = 6,
158 HPDF_CLIPPING = 7,
159 HPDF_RENDERING_MODE_EOF = 8
160 };
161
162 public enum HPdfLineCap {
163 HPDF_BUTT_END = 0,
164 HPDF_ROUND_END = 1,
165 HPDF_PROJECTING_SCUARE_END = 2,
166 HPDF_LINECAP_EOF = 3
167 };
168
169 public enum HPdfLineJoin {
170 HPDF_MITER_JOIN = 0,
171 HPDF_ROUND_JOIN = 1,
172 HPDF_BEVEL_JOIN = 2,
173 HPDF_LINEJOIN_EOF = 3
174 };
175
176 public enum HPdfTextAlignment {
177 HPDF_TALIGN_LEFT = 0,
178 HPDF_TALIGN_RIGHT = 1,
179 HPDF_TALIGN_CENTER = 2,
180 HPDF_TALIGN_JUSTIFY = 3
181 };
182
183 public enum HPdfTransitionStyle {
184 HPDF_TS_WIPE_RIGHT = 0,
185 HPDF_TS_WIPE_UP,
186 HPDF_TS_WIPE_LEFT,
187 HPDF_TS_WIPE_DOWN,
188 HPDF_TS_BARN_DOORS_HORIZONTAL_OUT,
189 HPDF_TS_BARN_DOORS_HORIZONTAL_IN,
190 HPDF_TS_BARN_DOORS_VERTICAL_OUT,
191 HPDF_TS_BARN_DOORS_VERTICAL_IN,
192 HPDF_TS_BOX_OUT,
193 HPDF_TS_BOX_IN,
194 HPDF_TS_BLINDS_HORIZONTAL,
195 HPDF_TS_BLINDS_VERTICAL,
196 HPDF_TS_DISSOLVE,
197 HPDF_TS_GLITTER_RIGHT,
198 HPDF_TS_GLITTER_DOWN,
199 HPDF_TS_GLITTER_TOP_LEFT_TO_BOTTOM_RIGHT,
200 HPDF_TS_REPLACE,
201 HPDF_TS_EOF
202 };
203
204
205 public enum HPdfBlendMode {
206 HPDF_BM_NORMAL = 0,
207 HPDF_BM_MULTIPLY,
208 HPDF_BM_SCREEN,
209 HPDF_BM_OVERLAY,
210 HPDF_BM_DARKEN,
211 HPDF_BM_LIGHTEN,
212 HPDF_BM_COLOR_DODGE,
213 HPDF_BM_COLOR_BUM,
214 HPDF_BM_HARD_LIGHT,
215 HPDF_BM_SOFT_LIGHT,
216 HPDF_BM_DIFFERENCE,
217 HPDF_BM_EXCLUSHON,
218 HPDF_BM_EOF
219 };
220
221 [StructLayout(LayoutKind.Sequential)]
222 public struct HPdfRect {
223 public float left;
224 public float bottom;
225 public float right;
226 public float top;
227 }
228
229 [StructLayout(LayoutKind.Sequential)]
230 public struct HPdfBox {
231 public float left;
232 public float bottom;
233 public float right;
234 public float top;
235 }
236
237 [StructLayout(LayoutKind.Sequential)]
238 public struct HPdfPoint {
239 public float x;
240 public float y;
241 }
242
243 [StructLayout(LayoutKind.Sequential)]
244 public struct HPdfDate {
245 public int year;
246 public int month;
247 public int day;
248 public int hour;
249 public int minutes;
250 public int seconds;
251 public char ind;
252 public int off_hour;
253 public int off_minutes;
254 };
255
256 [StructLayout(LayoutKind.Sequential)]
257 public struct HPdfTextWidth {
258 public uint numchars;
259
260 /* don't use this value (it may be change in the feature).
261 use numspace as alternated. */
262 public uint numwords;
263
264 public uint width;
265 public uint numspace;
266 }
267
268 [StructLayout(LayoutKind.Sequential)]
269 public struct HPdfTransMatrix {
270 public float a;
271 public float b;
272 public float c;
273 public float d;
274 public float x;
275 public float y;
276 };
277
278 [StructLayout(LayoutKind.Sequential)]
279 public struct HPdfDashMode_Internal {
280 public ushort ptn0;
281 public ushort ptn1;
282 public ushort ptn2;
283 public ushort ptn3;
284 public ushort ptn4;
285 public ushort ptn5;
286 public ushort ptn6;
287 public ushort ptn7;
288 public uint num_ptn;
289 public uint phase;
290 };
291
292 public struct HPdfDashMode {
293 public ushort[] ptn;
294 public uint phase;
295 };
296
297 [StructLayout(LayoutKind.Sequential)]
298 public struct HPdfRGBColor {
299 public float r;
300 public float g;
301 public float b;
302 };
303
304 [StructLayout(LayoutKind.Sequential)]
305 public struct HPdfCMYKColor {
306 public float c;
307 public float y;
308 public float m;
309 public float k;
310 };
311
312
313 /* error handler (call back function) */
HPDF_ErrorHandler(uint error_no, uint detail_no, IntPtr user_data)314 public delegate void HPDF_ErrorHandler(uint error_no, uint detail_no,
315 IntPtr user_data);
316
317 public class HPdfDoc: IDisposable {
318 public const int HPDF_TRUE = 1;
319 public const int HPDF_FALSE = 0;
320 public const uint HPDF_COMP_NONE = 0;
321 public const uint HPDF_COMP_TEXT = 1;
322 public const uint HPDF_COMP_IMAGE = 2;
323 public const uint HPDF_COMP_METADATA = 4;
324 public const uint HPDF_COMP_ALL = 15;
325
326 public const uint HPDF_HIDE_TOOLBAR = 1;
327 public const uint HPDF_HIDE_MENUBAR = 2;
328 public const uint HPDF_HIDE_WINDOW_UI = 4;
329 public const uint HPDF_FIT_WINDOW = 8;
330 public const uint HPDF_CENTER_WINDOW = 16;
331
332 public const uint HPDF_ENABLE_READ = 0;
333 public const uint HPDF_ENABLE_PRINT = 4;
334 public const uint HPDF_ENABLE_EDIT_ALL = 8;
335 public const uint HPDF_ENABLE_COPY = 16;
336 public const uint HPDF_ENABLE_EDIT = 32;
337
338
339 [DllImport("libhpdf.dll")]
HPDF_GetVersion()340 private extern static string HPDF_GetVersion();
341
342 [DllImport("libhpdf.dll")]
HPDF_New(HPDF_ErrorHandler user_error_fn, IntPtr user_data)343 private extern static IntPtr HPDF_New(HPDF_ErrorHandler user_error_fn,
344 IntPtr user_data);
345
346 [DllImport("libhpdf.dll")]
HPDF_Free(IntPtr pdf)347 private extern static void HPDF_Free(IntPtr pdf);
348
349 [DllImport("libhpdf.dll")]
HPDF_NewDoc(IntPtr pdf)350 private extern static uint HPDF_NewDoc(IntPtr pdf);
351
352 [DllImport("libhpdf.dll")]
HPDF_FreeDoc(IntPtr pdf)353 private extern static uint HPDF_FreeDoc(IntPtr pdf);
354
355 [DllImport("libhpdf.dll")]
HPDF_FreeDocAll(IntPtr pdf)356 private extern static uint HPDF_FreeDocAll(IntPtr pdf);
357
358 [DllImport("libhpdf.dll")]
HPDF_HasDoc(IntPtr pdf)359 private extern static uint HPDF_HasDoc(IntPtr pdf);
360
361 [DllImport("libhpdf.dll")]
HPDF_SaveToFile(IntPtr pdf, string file_name)362 private extern static uint HPDF_SaveToFile(IntPtr pdf, string file_name);
363
364 [DllImport("libhpdf.dll")]
HPDF_GetError(IntPtr pdf)365 private extern static uint HPDF_GetError(IntPtr pdf);
366
367 [DllImport("libhpdf.dll")]
HPDF_GetErrorDetail(IntPtr pdf)368 private extern static uint HPDF_GetErrorDetail(IntPtr pdf);
369
370 [DllImport("libhpdf.dll")]
HPDF_ResetError(IntPtr pdf)371 private extern static void HPDF_ResetError(IntPtr pdf);
372
373 [DllImport("libhpdf.dll")]
HPDF_SetPagesConfiguration(IntPtr pdf, uint page_per_pages)374 private extern static uint HPDF_SetPagesConfiguration(IntPtr pdf,
375 uint page_per_pages);
376
377 [DllImport("libhpdf.dll")]
HPDF_GetPageByIndex(IntPtr pdf, uint index)378 private extern static IntPtr HPDF_GetPageByIndex(IntPtr pdf,
379 uint index);
380
381 [DllImport("libhpdf.dll")]
HPDF_GetPageLayout(IntPtr pdf)382 private extern static HPdfPageLayout HPDF_GetPageLayout(IntPtr pdf);
383
384 [DllImport("libhpdf.dll")]
HPDF_SetPageLayout(IntPtr pdf, HPdfPageLayout layout)385 private extern static uint HPDF_SetPageLayout(IntPtr pdf,
386 HPdfPageLayout layout);
387
388 [DllImport("libhpdf.dll")]
HPDF_GetPageMode(IntPtr pdf)389 private extern static HPdfPageMode HPDF_GetPageMode(IntPtr pdf);
390
391 [DllImport("libhpdf.dll")]
HPDF_SetPageMode(IntPtr pdf, HPdfPageMode mode)392 private extern static uint HPDF_SetPageMode(IntPtr pdf, HPdfPageMode mode);
393
394 [DllImport("libhpdf.dll")]
HPDF_SetOpenAction(IntPtr pdf, IntPtr open_action)395 private extern static uint HPDF_SetOpenAction(IntPtr pdf,
396 IntPtr open_action);
397
398 [DllImport("libhpdf.dll")]
HPDF_GetViewerPreference(IntPtr pdf)399 private extern static uint HPDF_GetViewerPreference(IntPtr pdf);
400
401 [DllImport("libhpdf.dll")]
HPDF_SetViewerPreference(IntPtr pdf, uint value)402 private extern static uint HPDF_SetViewerPreference(IntPtr pdf, uint value);
403
404 [DllImport("libhpdf.dll")]
HPDF_GetCurrentPage(IntPtr pdf)405 private extern static IntPtr HPDF_GetCurrentPage(IntPtr pdf);
406
407 [DllImport("libhpdf.dll")]
HPDF_AddPage(IntPtr pdf)408 private extern static IntPtr HPDF_AddPage(IntPtr pdf);
409
410 [DllImport("libhpdf.dll")]
HPDF_InsertPage(IntPtr pdf, IntPtr page)411 private extern static IntPtr HPDF_InsertPage(IntPtr pdf,
412 IntPtr page);
413
414 [DllImport("libhpdf.dll")]
HPDF_GetFont(IntPtr pdf, string font_name, string encoding_name)415 private extern static IntPtr HPDF_GetFont(IntPtr pdf, string font_name,
416 string encoding_name);
417
418 [DllImport("libhpdf.dll")]
HPDF_LoadType1FontFromFile(IntPtr pdf, string afmfilename, string pfmfilename)419 private extern static string HPDF_LoadType1FontFromFile(IntPtr pdf,
420 string afmfilename, string pfmfilename);
421
422 [DllImport("libhpdf.dll")]
HPDF_LoadTTFontFromFile(IntPtr pdf, string file_name, int embedding)423 private extern static string HPDF_LoadTTFontFromFile(IntPtr pdf,
424 string file_name, int embedding);
425
426 [DllImport("libhpdf.dll")]
HPDF_LoadTTFontFromFile2(IntPtr pdf, string file_name, uint index, int embedding)427 private extern static string HPDF_LoadTTFontFromFile2(IntPtr pdf,
428 string file_name, uint index, int embedding);
429
430 [DllImport("libhpdf.dll")]
HPDF_AddPageLabel(IntPtr pdf, uint page_num, HPdfPageNumStyle style, uint first_page, string prefix)431 private extern static uint HPDF_AddPageLabel(IntPtr pdf, uint page_num,
432 HPdfPageNumStyle style, uint first_page, string prefix);
433
434 [DllImport("libhpdf.dll")]
HPDF_UseJPFonts(IntPtr pdf)435 private extern static uint HPDF_UseJPFonts(IntPtr pdf);
436
437 [DllImport("libhpdf.dll")]
HPDF_UseKRFonts(IntPtr pdf)438 private extern static uint HPDF_UseKRFonts(IntPtr pdf);
439
440 [DllImport("libhpdf.dll")]
HPDF_UseCNSFonts(IntPtr pdf)441 private extern static uint HPDF_UseCNSFonts(IntPtr pdf);
442
443 [DllImport("libhpdf.dll")]
HPDF_UseCNTFonts(IntPtr pdf)444 private extern static uint HPDF_UseCNTFonts(IntPtr pdf);
445
446 [DllImport("libhpdf.dll")]
HPDF_CreateOutline(IntPtr pdf, IntPtr parent, string title, IntPtr encoder)447 private extern static IntPtr HPDF_CreateOutline(IntPtr pdf, IntPtr parent,
448 string title, IntPtr encoder);
449
450 [DllImport("libhpdf.dll")]
HPDF_GetEncoder(IntPtr pdf, string encoding_name)451 private extern static IntPtr HPDF_GetEncoder(IntPtr pdf,
452 string encoding_name);
453
454 [DllImport("libhpdf.dll")]
HPDF_GetCurrentEncoder(IntPtr pdf)455 private extern static IntPtr HPDF_GetCurrentEncoder(IntPtr pdf);
456
457 [DllImport("libhpdf.dll")]
HPDF_SetCurrentEncoder(IntPtr pdf, string encoding_name)458 private extern static uint HPDF_SetCurrentEncoder(IntPtr pdf,
459 string encoding_name);
460
461 [DllImport("libhpdf.dll")]
HPDF_UseJPEncodings(IntPtr pdf)462 private extern static uint HPDF_UseJPEncodings(IntPtr pdf);
463
464 [DllImport("libhpdf.dll")]
HPDF_UseKREncodings(IntPtr pdf)465 private extern static uint HPDF_UseKREncodings(IntPtr pdf);
466
467 [DllImport("libhpdf.dll")]
HPDF_UseCNSEncodings(IntPtr pdf)468 private extern static uint HPDF_UseCNSEncodings(IntPtr pdf);
469
470 [DllImport("libhpdf.dll")]
HPDF_UseCNTEncodings(IntPtr pdf)471 private extern static uint HPDF_UseCNTEncodings(IntPtr pdf);
472
473 [DllImport("libhpdf.dll")]
HPDF_LoadPngImageFromFile(IntPtr pdf, string filename)474 private extern static IntPtr HPDF_LoadPngImageFromFile(IntPtr pdf,
475 string filename);
476
477 [DllImport("libhpdf.dll")]
HPDF_LoadPngImageFromFile2(IntPtr pdf, string filename)478 private extern static IntPtr HPDF_LoadPngImageFromFile2(IntPtr pdf,
479 string filename);
480
481 [DllImport("libhpdf.dll")]
HPDF_LoadJpegImageFromFile(IntPtr pdf, string filename)482 private extern static IntPtr HPDF_LoadJpegImageFromFile(IntPtr pdf,
483 string filename);
484
485 [DllImport("libhpdf.dll")]
HPDF_LoadRawImageFromFile(IntPtr pdf, string filename, uint width, uint height, HPdfColorSpace color_space)486 private extern static IntPtr HPDF_LoadRawImageFromFile(IntPtr pdf,
487 string filename, uint width, uint height,
488 HPdfColorSpace color_space);
489
490 [DllImport("libhpdf.dll")]
HPDF_LoadRawImageFromMem(IntPtr pdf, byte[] data, int width, int height, HPdfColorSpace color_space, uint bits_per_component)491 private extern static IntPtr HPDF_LoadRawImageFromMem(IntPtr pdf,
492 byte[] data, int width, int height,
493 HPdfColorSpace color_space,
494 uint bits_per_component);
495
496 [DllImport("libhpdf.dll")]
HPDF_SetInfoAttr(IntPtr pdf, HPdfInfoType type, string value)497 private extern static uint HPDF_SetInfoAttr(IntPtr pdf,
498 HPdfInfoType type, string value);
499
500 [DllImport("libhpdf.dll")]
HPDF_SetInfoDateAttr(IntPtr pdf, HPdfInfoType type, HPdfDate value)501 private extern static uint HPDF_SetInfoDateAttr(IntPtr pdf,
502 HPdfInfoType type, HPdfDate value);
503
504 [DllImport("libhpdf.dll")]
HPDF_GetInfoAttr(IntPtr pdf, HPdfInfoType type)505 private extern static string HPDF_GetInfoAttr(IntPtr pdf,
506 HPdfInfoType type);
507
508 [DllImport("libhpdf.dll")]
HPDF_SetPassword(IntPtr pdf, string owner_passwd, string user_passwd)509 private extern static uint HPDF_SetPassword(IntPtr pdf,
510 string owner_passwd, string user_passwd);
511
512 [DllImport("libhpdf.dll")]
HPDF_SetPermission(IntPtr pdf, uint permission)513 private extern static uint HPDF_SetPermission(IntPtr pdf,
514 uint permission);
515
516 [DllImport("libhpdf.dll")]
HPDF_SetEncryptionMode(IntPtr pdf, HPdfEncryptMode mode, uint key_len)517 private extern static uint HPDF_SetEncryptionMode(IntPtr pdf,
518 HPdfEncryptMode mode, uint key_len);
519
520 [DllImport("libhpdf.dll")]
HPDF_SetCompressionMode(IntPtr pdf, uint mode)521 private extern static uint HPDF_SetCompressionMode(IntPtr pdf,
522 uint mode);
523
524 [DllImport("libhpdf.dll")]
HPDF_CreateExtGState(IntPtr pdf)525 private extern static IntPtr HPDF_CreateExtGState(IntPtr pdf);
526
527 // handle to an instance of a HPdfDoc object.
528 private IntPtr hpdf;
529
HPdfDoc()530 public HPdfDoc() {
531 HPDF_ErrorHandler error_handler =
532 new HPDF_ErrorHandler(HPdfDoc.ErrorProc);
533 hpdf = HPDF_New(error_handler, IntPtr.Zero);
534 if (hpdf == IntPtr.Zero) {
535 throw new Exception("cannot create HPdfDoc object.");
536 }
537 }
538
IDisposable.Dispose()539 void IDisposable.Dispose() {
540 if (hpdf != IntPtr.Zero) {
541 HPDF_Free(hpdf);
542 }
543
544 hpdf = IntPtr.Zero;
545 }
546
~HPdfDoc()547 ~HPdfDoc() {
548 if (hpdf != IntPtr.Zero) {
549 HPDF_Free(hpdf);
550 }
551 }
552
HPdfGetVersion()553 public static string HPdfGetVersion() {
554 return HPDF_GetVersion();
555 }
556
ErrorProc(uint error_no, uint detail_no, IntPtr user_data)557 public static void ErrorProc(uint error_no, uint detail_no,
558 IntPtr user_data) {
559 string s = "error-code=0x" + error_no.ToString("X") + " detail-code=" + detail_no;
560 throw new Exception(s);
561 }
562
NewDoc()563 public void NewDoc() {
564 HPDF_NewDoc(hpdf);
565 }
566
FreeDoc()567 public void FreeDoc() {
568 HPDF_FreeDoc(hpdf);
569 }
570
FreeDocAll()571 public void FreeDocAll() {
572 HPDF_FreeDocAll(hpdf);
573 }
574
HasDoc()575 public bool HasDoc() {
576 return (HPDF_HasDoc(hpdf) != 0);
577 }
578
SaveToFile(string file_name)579 public void SaveToFile(string file_name) {
580 HPDF_SaveToFile(hpdf, file_name);
581 }
582
GetError()583 public uint GetError() {
584 return HPDF_GetError(hpdf);
585 }
586
GetErrorDetail()587 public uint GetErrorDetail() {
588 return HPDF_GetErrorDetail(hpdf);
589 }
590
ResetError()591 public void ResetError() {
592 HPDF_ResetError(hpdf);
593 }
594
SetPagesConfiguration(uint page_per_pages)595 public void SetPagesConfiguration(uint page_per_pages) {
596 HPDF_SetPagesConfiguration(hpdf, page_per_pages);
597 }
598
GetPageByIndex(uint index)599 public HPdfPage GetPageByIndex(uint index) {
600 IntPtr hpage;
601
602 hpage = HPDF_GetPageByIndex(hpdf, index);
603 return new HPdfPage(hpage);
604 }
605
GetPageLayout()606 public HPdfPageLayout GetPageLayout() {
607 return HPDF_GetPageLayout(hpdf);
608 }
609
SetPageLayout(HPdfPageLayout layout)610 public void SetPageLayout(HPdfPageLayout layout) {
611 HPDF_SetPageLayout(hpdf, layout);
612 }
613
GetPageMode()614 public HPdfPageMode GetPageMode() {
615 return HPDF_GetPageMode(hpdf);
616 }
617
SetPageMode(HPdfPageMode mode)618 public void SetPageMode(HPdfPageMode mode) {
619 HPDF_SetPageMode(hpdf, mode);
620 }
621
SetOpenAction(HPdfDestination open_action)622 public void SetOpenAction(HPdfDestination open_action) {
623 if (open_action == null) {
624 // ERROR!!
625 } else {
626 HPDF_SetOpenAction(hpdf, open_action.GetHandle());
627 }
628 }
629
GetViewerPreference()630 public uint GetViewerPreference() {
631 return HPDF_GetViewerPreference(hpdf);
632 }
633
SetViewerPreference(uint value)634 public void SetViewerPreference(uint value) {
635 HPDF_SetViewerPreference(hpdf, value);
636 }
637
GetCurrentPage()638 public HPdfPage GetCurrentPage() {
639 IntPtr hpage;
640
641 hpage = HPDF_GetCurrentPage(hpdf);
642 return new HPdfPage(hpage);
643 }
644
AddPage()645 public HPdfPage AddPage() {
646 IntPtr hpage;
647
648 hpage = HPDF_AddPage(hpdf);
649 return new HPdfPage(hpage);
650 }
651
InsertPage(HPdfPage page)652 public HPdfPage InsertPage(HPdfPage page) {
653 IntPtr hpage;
654
655 hpage = HPDF_InsertPage(hpdf, page.GetHandle());
656 return new HPdfPage(hpage);
657 }
658
GetFont(string font_name, string encoding_name)659 public HPdfFont GetFont(string font_name, string encoding_name) {
660 IntPtr hfont;
661
662 hfont = HPDF_GetFont(hpdf, font_name, encoding_name);
663 return new HPdfFont(hfont);
664 }
665
LoadType1FontFromFile(string afmfilename, string pfmfilename)666 public string LoadType1FontFromFile(string afmfilename,
667 string pfmfilename) {
668 string font_name;
669
670 font_name = HPDF_LoadType1FontFromFile(hpdf, afmfilename, pfmfilename);
671 return font_name;
672 }
673
LoadTTFontFromFile(string file_name, bool embedding)674 public string LoadTTFontFromFile(string file_name, bool embedding) {
675 string font_name;
676 int emb;
677
678 if (embedding)
679 emb = HPDF_TRUE;
680 else
681 emb = HPDF_FALSE;
682
683 font_name = HPDF_LoadTTFontFromFile(hpdf, file_name, emb);
684 return font_name;
685 }
686
LoadTTFontFromFile2(string file_name, uint index, bool embedding)687 public string LoadTTFontFromFile2(string file_name, uint index,
688 bool embedding) {
689 string font_name;
690 int emb;
691
692 if (embedding)
693 emb = HPDF_TRUE;
694 else
695 emb = HPDF_FALSE;
696
697 font_name = HPDF_LoadTTFontFromFile2(hpdf, file_name, index, emb);
698 return font_name;
699 }
700
AddPageLabel(uint page_num, HPdfPageNumStyle style, uint first_page, string prefix)701 public void AddPageLabel(uint page_num, HPdfPageNumStyle style,
702 uint first_page, string prefix) {
703 HPDF_AddPageLabel(hpdf, page_num, style, first_page, prefix);
704 }
705
UseJPFonts()706 public uint UseJPFonts() {
707 return HPDF_UseJPFonts(hpdf);
708 }
709
UseKRFonts()710 public uint UseKRFonts() {
711 return HPDF_UseKRFonts(hpdf);
712 }
713
UseCNSFonts()714 public uint UseCNSFonts() {
715 return HPDF_UseCNSFonts(hpdf);
716 }
717
UseCNTFonts()718 public uint UseCNTFonts() {
719 return HPDF_UseCNTFonts(hpdf);
720 }
721
CreateOutline(HPdfOutline parent, string title, HPdfEncoder encoder)722 public HPdfOutline CreateOutline(HPdfOutline parent, string title,
723 HPdfEncoder encoder) {
724 IntPtr hparent;
725 IntPtr hencoder;
726 IntPtr houtline;
727
728 if (encoder != null)
729 hencoder = encoder.GetHandle();
730 else
731 hencoder = IntPtr.Zero;
732
733 if (parent != null)
734 hparent = parent.GetHandle();
735 else
736 hparent = IntPtr.Zero;
737
738 houtline = HPDF_CreateOutline(hpdf, hparent, title, hencoder);
739 return new HPdfOutline(houtline);
740 }
741
GetEncoder(string encoding_name)742 public HPdfEncoder GetEncoder(string encoding_name) {
743 IntPtr hencoder;
744
745 hencoder = HPDF_GetEncoder(hpdf, encoding_name);
746
747 return new HPdfEncoder(hencoder);
748 }
749
GetCurrentEncoder()750 public HPdfEncoder GetCurrentEncoder() {
751 IntPtr hencoder;
752
753 hencoder = HPDF_GetCurrentEncoder(hpdf);
754
755 return new HPdfEncoder(hencoder);
756 }
757
SetCurrentEncoder(string encoding_name)758 public void SetCurrentEncoder(string encoding_name) {
759 HPDF_SetCurrentEncoder(hpdf, encoding_name);
760 }
761
UseJPEncodings()762 public uint UseJPEncodings() {
763 return HPDF_UseJPEncodings(hpdf);
764 }
765
UseKREncodings()766 public uint UseKREncodings() {
767 return HPDF_UseKREncodings(hpdf);
768 }
769
UseCNSEncodings()770 public uint UseCNSEncodings() {
771 return HPDF_UseCNSEncodings(hpdf);
772 }
773
UseCNTEncodings()774 public uint UseCNTEncodings() {
775 return HPDF_UseCNTEncodings(hpdf);
776 }
777
LoadPngImageFromFile(string filename)778 public HPdfImage LoadPngImageFromFile(string filename) {
779 IntPtr hobj;
780
781 hobj = HPDF_LoadPngImageFromFile(hpdf, filename);
782
783 return new HPdfImage(hobj);
784 }
785
LoadPngImageFromFile2(string filename)786 public HPdfImage LoadPngImageFromFile2(string filename) {
787 IntPtr hobj;
788
789 hobj = HPDF_LoadPngImageFromFile2(hpdf, filename);
790
791 return new HPdfImage(hobj);
792 }
793
LoadJpegImageFromFile(string filename)794 public HPdfImage LoadJpegImageFromFile(string filename) {
795 IntPtr hobj;
796
797 hobj = HPDF_LoadJpegImageFromFile(hpdf, filename);
798
799 return new HPdfImage(hobj);
800 }
801
LoadRawImageFromFile(string filename, uint width, uint height, HPdfColorSpace color_space)802 public HPdfImage LoadRawImageFromFile(string filename,
803 uint width, uint height,
804 HPdfColorSpace color_space) {
805 IntPtr hobj;
806
807 hobj = HPDF_LoadRawImageFromFile(hpdf, filename, width, height,
808 color_space);
809
810 return new HPdfImage(hobj);
811 }
812
LoadRawImageFromMem(byte[] data, int width, int height, HPdfColorSpace color_space, uint bits_per_component)813 public HPdfImage LoadRawImageFromMem(byte[] data, int width, int height,
814 HPdfColorSpace color_space, uint bits_per_component) {
815 if (width * height < data.Length) {
816 string s = "error-code=0x1030 detail-code=0";
817 throw new Exception(s);
818 }
819 IntPtr hobj;
820
821 hobj = HPDF_LoadRawImageFromMem(hpdf, data, width, height, color_space,
822 bits_per_component);
823
824 return new HPdfImage(hobj);
825 }
826
SetInfoAttr(HPdfInfoType type, string value)827 public void SetInfoAttr(HPdfInfoType type, string value) {
828 HPDF_SetInfoAttr(hpdf, type, value);
829 }
830
SetInfoDateAttr(HPdfInfoType type, HPdfDate value)831 public void SetInfoDateAttr(HPdfInfoType type, HPdfDate value) {
832 HPDF_SetInfoDateAttr(hpdf, type, value);
833 }
834
GetInfoAttr(HPdfInfoType type)835 public string GetInfoAttr(HPdfInfoType type) {
836 return HPDF_GetInfoAttr(hpdf, type);
837 }
838
SetPassword(string owner_passwd, string user_passwd)839 public void SetPassword(string owner_passwd, string user_passwd) {
840 HPDF_SetPassword(hpdf, owner_passwd, user_passwd);
841 }
842
SetPermission(uint permission)843 public void SetPermission(uint permission) {
844 HPDF_SetPermission(hpdf, permission);
845 }
846
SetEncryptionMode(HPdfEncryptMode mode, uint key_len)847 public void SetEncryptionMode(HPdfEncryptMode mode, uint key_len) {
848 HPDF_SetEncryptionMode(hpdf, mode, key_len);
849 }
850
SetCompressionMode(uint mode)851 public void SetCompressionMode(uint mode) {
852 HPDF_SetCompressionMode(hpdf, mode);
853 }
854
CreateExtGState()855 public HPdfExtGState CreateExtGState() {
856 IntPtr hgstate;
857
858 hgstate = HPDF_CreateExtGState(hpdf);
859
860 return new HPdfExtGState(hgstate);
861 }
862 }
863
864 public class HPdfPage{
865 public const int HPDF_TRUE = 1;
866 public const int HPDF_FALSE = 0;
867
868 [DllImport("libhpdf.dll")]
HPDF_Page_SetWidth(IntPtr page, float value)869 private extern static uint HPDF_Page_SetWidth(IntPtr page, float value);
870
871 [DllImport("libhpdf.dll")]
HPDF_Page_SetHeight(IntPtr page, float value)872 private extern static uint HPDF_Page_SetHeight(IntPtr page, float value);
873
874 [DllImport("libhpdf.dll")]
HPDF_Page_SetSize(IntPtr page, HPdfPageSizes size, HPdfPageDirection direction)875 private extern static uint HPDF_Page_SetSize(IntPtr page,
876 HPdfPageSizes size, HPdfPageDirection direction);
877
878 [DllImport("libhpdf.dll")]
HPDF_Page_SetRotate(IntPtr page, ushort angle)879 private extern static uint HPDF_Page_SetRotate(IntPtr page, ushort angle);
880
881 [DllImport("libhpdf.dll")]
HPDF_Page_CreateDestination(IntPtr page)882 private extern static IntPtr HPDF_Page_CreateDestination(IntPtr page);
883
884 [DllImport("libhpdf.dll")]
HPDF_Page_CreateTextAnnot(IntPtr page, HPdfRect rect, string text, IntPtr encoder)885 private extern static IntPtr HPDF_Page_CreateTextAnnot(IntPtr page,
886 HPdfRect rect, string text, IntPtr encoder);
887
888 [DllImport("libhpdf.dll")]
HPDF_Page_CreateLinkAnnot(IntPtr page, HPdfRect rect, IntPtr dst)889 private extern static IntPtr HPDF_Page_CreateLinkAnnot(IntPtr page,
890 HPdfRect rect, IntPtr dst);
891
892 [DllImport("libhpdf.dll")]
HPDF_Page_CreateURILinkAnnot(IntPtr page, HPdfRect rect, string url)893 private extern static IntPtr HPDF_Page_CreateURILinkAnnot(IntPtr page,
894 HPdfRect rect, string url);
895
896 [DllImport("libhpdf.dll")]
HPDF_Page_TextWidth(IntPtr page, string text)897 private extern static float HPDF_Page_TextWidth(IntPtr page,
898 string text);
899
900 [DllImport("libhpdf.dll")]
HPDF_Page_MeasureText(IntPtr page, string text, float width, int wordwrap, ref float real_width)901 private extern static uint HPDF_Page_MeasureText(IntPtr page,
902 string text, float width, int wordwrap, ref float real_width);
903
904 [DllImport("libhpdf.dll")]
HPDF_Page_GetWidth(IntPtr page)905 private extern static float HPDF_Page_GetWidth(IntPtr page);
906
907 [DllImport("libhpdf.dll")]
HPDF_Page_GetHeight(IntPtr page)908 private extern static float HPDF_Page_GetHeight(IntPtr page);
909
910 [DllImport("libhpdf.dll")]
HPDF_Page_GetGMode(IntPtr page)911 private extern static ushort HPDF_Page_GetGMode(IntPtr page);
912
913 [DllImport("libhpdf.dll")]
HPDF_Page_GetCurrentPos(IntPtr page)914 private extern static HPdfPoint HPDF_Page_GetCurrentPos(IntPtr page);
915
916 [DllImport("libhpdf.dll")]
HPDF_Page_GetCurrentTextPos(IntPtr page)917 private extern static HPdfPoint HPDF_Page_GetCurrentTextPos(IntPtr page);
918
919 [DllImport("libhpdf.dll")]
HPDF_Page_GetCurrentFont(IntPtr page)920 private extern static IntPtr HPDF_Page_GetCurrentFont(IntPtr page);
921
922 [DllImport("libhpdf.dll")]
HPDF_Page_GetCurrentFontSize(IntPtr page)923 private extern static float HPDF_Page_GetCurrentFontSize(IntPtr page);
924
925 [DllImport("libhpdf.dll")]
HPDF_Page_GetTransMatrix(IntPtr page)926 private extern static HPdfTransMatrix HPDF_Page_GetTransMatrix(IntPtr page);
927
928 [DllImport("libhpdf.dll")]
HPDF_Page_GetLineWidth(IntPtr page)929 private extern static float HPDF_Page_GetLineWidth(IntPtr page);
930
931 [DllImport("libhpdf.dll")]
HPDF_Page_GetLineCap(IntPtr page)932 private extern static HPdfLineCap HPDF_Page_GetLineCap(IntPtr page);
933
934 [DllImport("libhpdf.dll")]
HPDF_Page_GetLineJoin(IntPtr page)935 private extern static HPdfLineJoin HPDF_Page_GetLineJoin(IntPtr page);
936
937 [DllImport("libhpdf.dll")]
HPDF_Page_GetMiterLimit(IntPtr page)938 private extern static float HPDF_Page_GetMiterLimit(IntPtr page);
939
940 [DllImport("libhpdf.dll")]
HPDF_Page_GetDash(IntPtr page)941 private extern static HPdfDashMode_Internal HPDF_Page_GetDash(IntPtr page);
942
943 [DllImport("libhpdf.dll")]
HPDF_Page_GetFlat(IntPtr page)944 private extern static float HPDF_Page_GetFlat(IntPtr page);
945
946 [DllImport("libhpdf.dll")]
HPDF_Page_GetCharSpace(IntPtr page)947 private extern static float HPDF_Page_GetCharSpace(IntPtr page);
948
949 [DllImport("libhpdf.dll")]
HPDF_Page_GetWordSpace(IntPtr page)950 private extern static float HPDF_Page_GetWordSpace(IntPtr page);
951
952 [DllImport("libhpdf.dll")]
HPDF_Page_GetHorizontalScalling(IntPtr page)953 private extern static float HPDF_Page_GetHorizontalScalling(IntPtr page);
954
955 [DllImport("libhpdf.dll")]
HPDF_Page_GetTextLeading(IntPtr page)956 private extern static float HPDF_Page_GetTextLeading(IntPtr page);
957
958 [DllImport("libhpdf.dll")]
HPDF_Page_GetTextRenderingMode(IntPtr page)959 private extern static HPdfTextRenderingMode HPDF_Page_GetTextRenderingMode(IntPtr page);
960
961 [DllImport("libhpdf.dll")]
HPDF_Page_GetTextRaise(IntPtr page)962 private extern static float HPDF_Page_GetTextRaise(IntPtr page);
963
964 [DllImport("libhpdf.dll")]
HPDF_Page_GetRGBFill(IntPtr page)965 private extern static HPdfRGBColor HPDF_Page_GetRGBFill(IntPtr page);
966
967 [DllImport("libhpdf.dll")]
HPDF_Page_GetRGBStroke(IntPtr page)968 private extern static HPdfRGBColor HPDF_Page_GetRGBStroke(IntPtr page);
969
970 [DllImport("libhpdf.dll")]
HPDF_Page_GetCMYKFill(IntPtr page)971 private extern static HPdfCMYKColor HPDF_Page_GetCMYKFill(IntPtr page);
972
973 [DllImport("libhpdf.dll")]
HPDF_Page_GetCMYKStroke(IntPtr page)974 private extern static HPdfCMYKColor HPDF_Page_GetCMYKStroke(IntPtr page);
975
976 [DllImport("libhpdf.dll")]
HPDF_Page_GetGrayFill(IntPtr page)977 private extern static float HPDF_Page_GetGrayFill(IntPtr page);
978
979 [DllImport("libhpdf.dll")]
HPDF_Page_GetGrayStroke(IntPtr page)980 private extern static float HPDF_Page_GetGrayStroke(IntPtr page);
981
982 [DllImport("libhpdf.dll")]
HPDF_Page_GetStrokingColorSpace(IntPtr page)983 private extern static HPdfColorSpace HPDF_Page_GetStrokingColorSpace(IntPtr page);
984
985 [DllImport("libhpdf.dll")]
HPDF_Page_GetFillingColorSpace(IntPtr page)986 private extern static HPdfColorSpace HPDF_Page_GetFillingColorSpace(IntPtr page);
987
988 [DllImport("libhpdf.dll")]
HPDF_Page_GetTextMatrix(IntPtr page)989 private extern static HPdfTransMatrix HPDF_Page_GetTextMatrix(IntPtr page);
990
991 [DllImport("libhpdf.dll")]
HPDF_Page_GetGStateDepth(IntPtr page)992 private extern static uint HPDF_Page_GetGStateDepth(IntPtr page);
993
994 /*--- General graphics state -----------------------------------------------*/
995
996 [DllImport("libhpdf.dll")]
HPDF_Page_SetLineWidth(IntPtr page, float line_width)997 private extern static uint HPDF_Page_SetLineWidth(IntPtr page,
998 float line_width);
999
1000 [DllImport("libhpdf.dll")]
HPDF_Page_SetLineCap(IntPtr page, HPdfLineCap line_cap)1001 private extern static uint HPDF_Page_SetLineCap(IntPtr page,
1002 HPdfLineCap line_cap);
1003
1004 [DllImport("libhpdf.dll")]
HPDF_Page_SetLineJoin(IntPtr page, HPdfLineJoin line_join)1005 private extern static uint HPDF_Page_SetLineJoin(IntPtr page,
1006 HPdfLineJoin line_join);
1007
1008 [DllImport("libhpdf.dll")]
HPDF_Page_SetMiterLimit(IntPtr page, float miter_limit)1009 private extern static uint HPDF_Page_SetMiterLimit(IntPtr page,
1010 float miter_limit);
1011
1012 [DllImport("libhpdf.dll")]
HPDF_Page_SetDash(IntPtr page, ushort[] array, uint num_param, uint phase)1013 private extern static uint HPDF_Page_SetDash(IntPtr page,
1014 ushort[] array, uint num_param, uint phase);
1015
1016 [DllImport("libhpdf.dll")]
HPDF_Page_SetFlat(IntPtr page, float flatness)1017 private extern static uint HPDF_Page_SetFlat(IntPtr page,
1018 float flatness);
1019
1020 [DllImport("libhpdf.dll")]
HPDF_Page_SetExtGState(IntPtr page, IntPtr ext_gstate)1021 private extern static uint HPDF_Page_SetExtGState(IntPtr page,
1022 IntPtr ext_gstate);
1023
1024 [DllImport("libhpdf.dll")]
HPDF_Page_GSave(IntPtr page)1025 private extern static uint HPDF_Page_GSave(IntPtr page);
1026
1027 [DllImport("libhpdf.dll")]
HPDF_Page_GRestore(IntPtr page)1028 private extern static uint HPDF_Page_GRestore(IntPtr page);
1029
1030 [DllImport("libhpdf.dll")]
HPDF_Page_Concat(IntPtr page, float a, float b, float c, float d, float x, float y)1031 private extern static uint HPDF_Page_Concat(IntPtr page,
1032 float a, float b, float c, float d, float x, float y);
1033
1034 [DllImport("libhpdf.dll")]
HPDF_Page_MoveTo(IntPtr page, float x, float y)1035 private extern static uint HPDF_Page_MoveTo(IntPtr page,
1036 float x, float y);
1037
1038 [DllImport("libhpdf.dll")]
HPDF_Page_LineTo(IntPtr page, float x, float y)1039 private extern static uint HPDF_Page_LineTo(IntPtr page,
1040 float x, float y);
1041
1042 [DllImport("libhpdf.dll")]
HPDF_Page_CurveTo(IntPtr page, float x1, float y1, float x2, float y2, float x3, float y3)1043 private extern static uint HPDF_Page_CurveTo(IntPtr page,
1044 float x1, float y1, float x2, float y2, float x3, float y3);
1045
1046 [DllImport("libhpdf.dll")]
HPDF_Page_CurveTo2(IntPtr page, float x2, float y2, float x3, float y3)1047 private extern static uint HPDF_Page_CurveTo2(IntPtr page,
1048 float x2, float y2, float x3, float y3);
1049
1050 [DllImport("libhpdf.dll")]
HPDF_Page_CurveTo3(IntPtr page, float x1, float y1, float x3, float y3)1051 private extern static uint HPDF_Page_CurveTo3(IntPtr page,
1052 float x1, float y1, float x3, float y3);
1053
1054 [DllImport("libhpdf.dll")]
HPDF_Page_ClosePath(IntPtr page)1055 private extern static uint HPDF_Page_ClosePath(IntPtr page);
1056
1057 [DllImport("libhpdf.dll")]
HPDF_Page_Rectangle(IntPtr page, float x, float y, float width, float height)1058 private extern static uint HPDF_Page_Rectangle(IntPtr page,
1059 float x, float y, float width, float height);
1060
1061 [DllImport("libhpdf.dll")]
HPDF_Page_Stroke(IntPtr page)1062 private extern static uint HPDF_Page_Stroke(IntPtr page);
1063
1064 [DllImport("libhpdf.dll")]
HPDF_Page_ClosePathStroke(IntPtr page)1065 private extern static uint HPDF_Page_ClosePathStroke(IntPtr page);
1066
1067 [DllImport("libhpdf.dll")]
HPDF_Page_Fill(IntPtr page)1068 private extern static uint HPDF_Page_Fill(IntPtr page);
1069
1070 [DllImport("libhpdf.dll")]
HPDF_Page_Eofill(IntPtr page)1071 private extern static uint HPDF_Page_Eofill(IntPtr page);
1072
1073 [DllImport("libhpdf.dll")]
HPDF_Page_FillStroke(IntPtr page)1074 private extern static uint HPDF_Page_FillStroke(IntPtr page);
1075
1076 [DllImport("libhpdf.dll")]
HPDF_Page_EofillStroke(IntPtr page)1077 private extern static uint HPDF_Page_EofillStroke(IntPtr page);
1078
1079 [DllImport("libhpdf.dll")]
HPDF_Page_ClosePathFillStroke(IntPtr page)1080 private extern static uint HPDF_Page_ClosePathFillStroke(IntPtr page);
1081
1082 [DllImport("libhpdf.dll")]
HPDF_Page_ClosePathEofillStroke(IntPtr page)1083 private extern static uint HPDF_Page_ClosePathEofillStroke(IntPtr page);
1084
1085 [DllImport("libhpdf.dll")]
HPDF_Page_EndPath(IntPtr page)1086 private extern static uint HPDF_Page_EndPath(IntPtr page);
1087
1088 /*--- Clipping paths operator --------------------------------------------*/
1089
1090 [DllImport("libhpdf.dll")]
HPDF_Page_Clip(IntPtr page)1091 private extern static uint HPDF_Page_Clip(IntPtr page);
1092
1093 [DllImport("libhpdf.dll")]
HPDF_Page_Eoclip(IntPtr page)1094 private extern static uint HPDF_Page_Eoclip(IntPtr page);
1095
1096 /*--- Text object operator -----------------------------------------------*/
1097
1098 [DllImport("libhpdf.dll")]
HPDF_Page_BeginText(IntPtr page)1099 private extern static uint HPDF_Page_BeginText(IntPtr page);
1100
1101 [DllImport("libhpdf.dll")]
HPDF_Page_EndText(IntPtr page)1102 private extern static uint HPDF_Page_EndText(IntPtr page);
1103
1104 /*--- Text state ---------------------------------------------------------*/
1105
1106 [DllImport("libhpdf.dll")]
HPDF_Page_SetCharSpace(IntPtr page, float value)1107 private extern static uint HPDF_Page_SetCharSpace(IntPtr page,
1108 float value);
1109
1110 [DllImport("libhpdf.dll")]
HPDF_Page_SetWordSpace(IntPtr page, float value)1111 private extern static uint HPDF_Page_SetWordSpace(IntPtr page,
1112 float value);
1113
1114 [DllImport("libhpdf.dll")]
HPDF_Page_SetHorizontalScalling(IntPtr page, float value)1115 private extern static uint HPDF_Page_SetHorizontalScalling(IntPtr page,
1116 float value);
1117
1118 [DllImport("libhpdf.dll")]
HPDF_Page_SetTextLeading(IntPtr page, float value)1119 private extern static uint HPDF_Page_SetTextLeading(IntPtr page,
1120 float value);
1121
1122 [DllImport("libhpdf.dll")]
HPDF_Page_SetFontAndSize(IntPtr page, IntPtr hfont, float size)1123 private extern static uint HPDF_Page_SetFontAndSize(IntPtr page,
1124 IntPtr hfont, float size);
1125
1126 [DllImport("libhpdf.dll")]
HPDF_Page_SetTextRenderingMode(IntPtr page, HPdfTextRenderingMode mode)1127 private extern static uint HPDF_Page_SetTextRenderingMode(IntPtr page,
1128 HPdfTextRenderingMode mode);
1129
1130 [DllImport("libhpdf.dll")]
HPDF_Page_SetTextRaise(IntPtr page, float value)1131 private extern static uint HPDF_Page_SetTextRaise(IntPtr page,
1132 float value);
1133
1134 /*--- Text positioning ---------------------------------------------------*/
1135
1136 [DllImport("libhpdf.dll")]
HPDF_Page_MoveTextPos(IntPtr page, float x, float y)1137 private extern static uint HPDF_Page_MoveTextPos(IntPtr page,
1138 float x, float y);
1139
1140 [DllImport("libhpdf.dll")]
HPDF_Page_MoveTextPos2(IntPtr page, float x, float y)1141 private extern static uint HPDF_Page_MoveTextPos2(IntPtr page,
1142 float x, float y);
1143
1144 [DllImport("libhpdf.dll")]
HPDF_Page_SetTextMatrix(IntPtr page, float a, float b, float c, float d, float x, float y)1145 private extern static uint HPDF_Page_SetTextMatrix(IntPtr page,
1146 float a, float b, float c, float d, float x, float y);
1147
1148 [DllImport("libhpdf.dll")]
HPDF_Page_MoveToNextLine(IntPtr page)1149 private extern static uint HPDF_Page_MoveToNextLine(IntPtr page);
1150
1151 /*--- Text showing -------------------------------------------------------*/
1152
1153 [DllImport("libhpdf.dll")]
HPDF_Page_ShowText(IntPtr page, string text)1154 private extern static uint HPDF_Page_ShowText(IntPtr page,
1155 string text);
1156
1157 [DllImport("libhpdf.dll")]
HPDF_Page_ShowTextNextLine(IntPtr page, string text)1158 private extern static uint HPDF_Page_ShowTextNextLine(IntPtr page,
1159 string text);
1160
1161 [DllImport("libhpdf.dll")]
HPDF_Page_ShowTextNextLineEx(IntPtr page, float word_space, float char_space, string text)1162 private extern static uint HPDF_Page_ShowTextNextLineEx(IntPtr page,
1163 float word_space, float char_space, string text);
1164
1165 /*--- Color showing ------------------------------------------------------*/
1166
1167 [DllImport("libhpdf.dll")]
HPDF_Page_SetGrayFill(IntPtr page, float gray)1168 private extern static uint HPDF_Page_SetGrayFill(IntPtr page,
1169 float gray);
1170
1171 [DllImport("libhpdf.dll")]
HPDF_Page_SetGrayStroke(IntPtr page, float gray)1172 private extern static uint HPDF_Page_SetGrayStroke(IntPtr page,
1173 float gray);
1174
1175 [DllImport("libhpdf.dll")]
HPDF_Page_SetRGBFill(IntPtr page, float r, float g, float b)1176 private extern static uint HPDF_Page_SetRGBFill(IntPtr page,
1177 float r, float g, float b);
1178
1179 [DllImport("libhpdf.dll")]
HPDF_Page_SetRGBStroke(IntPtr page, float r, float g, float b)1180 private extern static uint HPDF_Page_SetRGBStroke(IntPtr page,
1181 float r, float g, float b);
1182
1183 [DllImport("libhpdf.dll")]
HPDF_Page_SetCMYKFill(IntPtr page, float c, float m, float y, float k)1184 private extern static uint HPDF_Page_SetCMYKFill(IntPtr page,
1185 float c, float m, float y, float k);
1186
1187 [DllImport("libhpdf.dll")]
HPDF_Page_SetCMYKStroke(IntPtr page, float c, float m, float y, float k)1188 private extern static uint HPDF_Page_SetCMYKStroke(IntPtr page,
1189 float c, float m, float y, float k);
1190
1191 [DllImport("libhpdf.dll")]
HPDF_Page_ExecuteXObject(IntPtr page, IntPtr obj)1192 private extern static uint HPDF_Page_ExecuteXObject(IntPtr page,
1193 IntPtr obj);
1194
1195 /*---------------------------------------------------------------------*/
1196
1197 [DllImport("libhpdf.dll")]
HPDF_Page_DrawImage(IntPtr page, IntPtr image, float x, float y, float width, float height)1198 private extern static uint HPDF_Page_DrawImage(IntPtr page,
1199 IntPtr image, float x, float y, float width, float height);
1200
1201 [DllImport("libhpdf.dll")]
HPDF_Page_Circle(IntPtr page, float x, float y, float ray)1202 private extern static uint HPDF_Page_Circle(IntPtr page,
1203 float x, float y, float ray);
1204
1205 [DllImport("libhpdf.dll")]
HPDF_Page_Arc(IntPtr page, float x, float y, float ray, float ang1, float ang2)1206 private extern static uint HPDF_Page_Arc(IntPtr page,
1207 float x, float y, float ray, float ang1, float ang2);
1208
1209 [DllImport("libhpdf.dll")]
HPDF_Page_Ellipse(IntPtr page, float x, float y, float xray, float yray)1210 private extern static uint HPDF_Page_Ellipse(IntPtr page,
1211 float x, float y, float xray, float yray);
1212
1213 [DllImport("libhpdf.dll")]
HPDF_Page_TextOut(IntPtr page, float xpos, float ypos, string text)1214 private extern static uint HPDF_Page_TextOut(IntPtr page,
1215 float xpos, float ypos, string text);
1216
1217 [DllImport("libhpdf.dll")]
HPDF_Page_TextRect(IntPtr page, float left, float top, float right, float bottom, string text, HPdfTextAlignment align, ref uint len)1218 private extern static uint HPDF_Page_TextRect(IntPtr page,
1219 float left, float top, float right, float bottom,
1220 string text, HPdfTextAlignment align, ref uint len);
1221
1222 [DllImport("libhpdf.dll")]
HPDF_Page_SetSlideShow(IntPtr page, HPdfTransitionStyle type, float disp_time, float trans_time)1223 private extern static uint HPDF_Page_SetSlideShow(IntPtr page,
1224 HPdfTransitionStyle type, float disp_time, float trans_time);
1225
1226
1227 // handle to an instance of a HPDF_Doc object.
1228 private IntPtr hpage;
1229
HPdfPage(IntPtr hpage)1230 public HPdfPage(IntPtr hpage) {
1231 if (hpage == IntPtr.Zero) {
1232 throw new Exception("cannot create HPdfPage object.");
1233 }
1234
1235 this.hpage = hpage;
1236 }
1237
SetWidth(float value)1238 public void SetWidth(float value) {
1239 HPDF_Page_SetWidth(hpage, value);
1240 }
1241
SetHeight(float value)1242 public void SetHeight(float value) {
1243 HPDF_Page_SetHeight(hpage, value);
1244 }
1245
SetSize(HPdfPageSizes size, HPdfPageDirection direction)1246 public void SetSize(HPdfPageSizes size,
1247 HPdfPageDirection direction) {
1248 HPDF_Page_SetSize(hpage, size, direction);
1249 }
1250
SetRotate(ushort angle)1251 public void SetRotate(ushort angle) {
1252 HPDF_Page_SetRotate(hpage, angle);
1253 }
1254
CreateDestination()1255 public HPdfDestination CreateDestination() {
1256 IntPtr hdest;
1257
1258 hdest = HPDF_Page_CreateDestination(hpage);
1259 return new HPdfDestination(hdest);
1260 }
1261
CreateTextAnnot(HPdfRect rect, string text, HPdfEncoder encoder)1262 public HPdfAnnotation CreateTextAnnot(HPdfRect rect, string text,
1263 HPdfEncoder encoder) {
1264 IntPtr hannot;
1265
1266 hannot = HPDF_Page_CreateTextAnnot(hpage, rect, text, encoder.GetHandle());
1267 return new HPdfAnnotation(hannot);
1268 }
1269
CreateLinkAnnot(HPdfRect rect, HPdfDestination dst)1270 public HPdfAnnotation CreateLinkAnnot(HPdfRect rect, HPdfDestination dst) {
1271 IntPtr hannot;
1272
1273 hannot = HPDF_Page_CreateLinkAnnot(hpage, rect, dst.GetHandle());
1274 return new HPdfAnnotation(hannot);
1275 }
1276
CreateURILinkAnnot(HPdfRect rect, string uri)1277 public HPdfAnnotation CreateURILinkAnnot(HPdfRect rect, string uri) {
1278 IntPtr hannot;
1279
1280 hannot = HPDF_Page_CreateURILinkAnnot(hpage, rect, uri);
1281 return new HPdfAnnotation(hannot);
1282 }
1283
1284
TextWidth(string text)1285 public float TextWidth(string text) {
1286 return HPDF_Page_TextWidth(hpage, text);
1287 }
1288
MeasureText(string text, float width, bool wordwrap, ref float real_width)1289 public uint MeasureText(string text, float width, bool wordwrap,
1290 ref float real_width) {
1291 int ww;
1292
1293 if (wordwrap)
1294 ww = HPDF_TRUE;
1295 else
1296 ww = HPDF_FALSE;
1297
1298 return HPDF_Page_MeasureText(hpage, text, width, ww, ref real_width);
1299 }
1300
MeasureText(string text, float width, bool wordwrap)1301 public uint MeasureText(string text, float width, bool wordwrap) {
1302 float dummy = 0;
1303 int ww;
1304
1305 if (wordwrap)
1306 ww = HPDF_TRUE;
1307 else
1308 ww = HPDF_FALSE;
1309
1310 return HPDF_Page_MeasureText(hpage, text, width, ww, ref dummy);
1311 }
1312
GetWidth()1313 public float GetWidth() {
1314 return HPDF_Page_GetWidth(hpage);
1315 }
1316
GetHeight()1317 public float GetHeight() {
1318 return HPDF_Page_GetHeight(hpage);
1319 }
1320
GetGMode()1321 public ushort GetGMode() {
1322 return HPDF_Page_GetGMode(hpage);
1323 }
1324
GetCurrentPos()1325 public HPdfPoint GetCurrentPos() {
1326 return HPDF_Page_GetCurrentPos(hpage);
1327 }
1328
GetCurrentTextPos()1329 public HPdfPoint GetCurrentTextPos() {
1330 return HPDF_Page_GetCurrentTextPos(hpage);
1331 }
1332
GetCurrentFont()1333 public HPdfFont GetCurrentFont() {
1334 return new HPdfFont(HPDF_Page_GetCurrentFont(hpage));
1335 }
1336
GetCurrentFontSize()1337 public float GetCurrentFontSize() {
1338 return HPDF_Page_GetCurrentFontSize(hpage);
1339 }
1340
GetTransMatrix()1341 public HPdfTransMatrix GetTransMatrix() {
1342 return HPDF_Page_GetTransMatrix(hpage);
1343 }
1344
GetLineWidth()1345 public float GetLineWidth() {
1346 return HPDF_Page_GetLineWidth(hpage);
1347 }
1348
GetLineCap()1349 public HPdfLineCap GetLineCap() {
1350 return HPDF_Page_GetLineCap(hpage);
1351 }
1352
GetLineJoin()1353 public HPdfLineJoin GetLineJoin() {
1354 return HPDF_Page_GetLineJoin(hpage);
1355 }
1356
GetMiterLimit()1357 public float GetMiterLimit() {
1358 return HPDF_Page_GetMiterLimit(hpage);
1359 }
1360
GetDash()1361 public HPdfDashMode GetDash() {
1362 HPdfDashMode_Internal mode1 = HPDF_Page_GetDash(hpage);
1363 HPdfDashMode mode2;
1364
1365 mode2.phase = mode1.phase;
1366 mode2.ptn = new ushort[mode1.num_ptn];
1367
1368 if (mode1.num_ptn >= 1)
1369 mode2.ptn[0] = mode1.ptn0;
1370
1371 if (mode1.num_ptn >= 2)
1372 mode2.ptn[1] = mode1.ptn1;
1373
1374 if (mode1.num_ptn >= 3)
1375 mode2.ptn[2] = mode1.ptn2;
1376
1377 if (mode1.num_ptn >= 4)
1378 mode2.ptn[3] = mode1.ptn3;
1379
1380 if (mode1.num_ptn >= 5)
1381 mode2.ptn[4] = mode1.ptn4;
1382
1383 if (mode1.num_ptn >= 6)
1384 mode2.ptn[5] = mode1.ptn5;
1385
1386 if (mode1.num_ptn >= 7)
1387 mode2.ptn[6] = mode1.ptn6;
1388
1389 if (mode1.num_ptn >= 8)
1390 mode2.ptn[7] = mode1.ptn7;
1391
1392 return mode2;
1393 }
1394
GetFlat()1395 public float GetFlat() {
1396 return HPDF_Page_GetFlat(hpage);
1397 }
1398
GetCharSpace()1399 public float GetCharSpace() {
1400 return HPDF_Page_GetCharSpace(hpage);
1401 }
1402
GetWordSpace()1403 public float GetWordSpace() {
1404 return HPDF_Page_GetWordSpace(hpage);
1405 }
1406
GetHorizontalScalling()1407 public float GetHorizontalScalling() {
1408 return HPDF_Page_GetHorizontalScalling(hpage);
1409 }
1410
GetTextLeading()1411 public float GetTextLeading() {
1412 return HPDF_Page_GetTextLeading(hpage);
1413 }
1414
GetTextRenderingMode()1415 public HPdfTextRenderingMode GetTextRenderingMode() {
1416 return HPDF_Page_GetTextRenderingMode(hpage);
1417 }
1418
GetTextRaise()1419 public float GetTextRaise() {
1420 return HPDF_Page_GetTextRaise(hpage);
1421 }
1422
GetRGBFill()1423 public HPdfRGBColor GetRGBFill() {
1424 return HPDF_Page_GetRGBFill(hpage);
1425 }
1426
GetRGBStroke()1427 public HPdfRGBColor GetRGBStroke() {
1428 return HPDF_Page_GetRGBStroke(hpage);
1429 }
1430
GetCMYKFill()1431 public HPdfCMYKColor GetCMYKFill() {
1432 return HPDF_Page_GetCMYKFill(hpage);
1433 }
1434
GetCMYKStroke()1435 public HPdfCMYKColor GetCMYKStroke() {
1436 return HPDF_Page_GetCMYKStroke(hpage);
1437 }
1438
GetGrayFill()1439 public float GetGrayFill() {
1440 return HPDF_Page_GetGrayFill(hpage);
1441 }
1442
GetGrayStroke()1443 public float GetGrayStroke() {
1444 return HPDF_Page_GetGrayStroke(hpage);
1445 }
1446
GetStrokingColorSpace()1447 public HPdfColorSpace GetStrokingColorSpace() {
1448 return HPDF_Page_GetStrokingColorSpace(hpage);
1449 }
1450
GetFillingColorSpace()1451 public HPdfColorSpace GetFillingColorSpace() {
1452 return HPDF_Page_GetFillingColorSpace(hpage);
1453 }
1454
GetTextMatrix()1455 public HPdfTransMatrix GetTextMatrix() {
1456 return HPDF_Page_GetTextMatrix(hpage);
1457 }
1458
GetGStateDepth()1459 public uint GetGStateDepth() {
1460 return HPDF_Page_GetGStateDepth(hpage);
1461 }
1462
SetLineWidth(float line_width)1463 public void SetLineWidth(float line_width) {
1464 HPDF_Page_SetLineWidth(hpage, line_width);
1465 }
1466
SetLineCap(HPdfLineCap line_cap)1467 public void SetLineCap(HPdfLineCap line_cap) {
1468 HPDF_Page_SetLineCap(hpage, line_cap);
1469 }
1470
SetLineJoin(HPdfLineJoin line_join)1471 public void SetLineJoin(HPdfLineJoin line_join) {
1472 HPDF_Page_SetLineJoin(hpage, line_join);
1473 }
1474
SetMiterLimit(float miter_limit)1475 public void SetMiterLimit(float miter_limit) {
1476 HPDF_Page_SetMiterLimit(hpage, miter_limit);
1477 }
1478
SetDash(ushort[] dash_ptn, uint phase)1479 public void SetDash(ushort[] dash_ptn, uint phase) {
1480 if (dash_ptn == null) {
1481 HPDF_Page_SetDash(hpage, dash_ptn, 0, 0);
1482 return;
1483 }
1484
1485 int len = dash_ptn.Length;
1486
1487 HPDF_Page_SetDash(hpage, dash_ptn, (uint)len, phase);
1488 }
1489
SetFlat(float flatness)1490 public void SetFlat(float flatness) {
1491 HPDF_Page_SetFlat(hpage, flatness);
1492 }
1493
SetExtGState(HPdfExtGState gstate)1494 public void SetExtGState(HPdfExtGState gstate) {
1495 HPDF_Page_SetExtGState(hpage, gstate.GetHandle());
1496 }
1497
GSave()1498 public void GSave() {
1499 HPDF_Page_GSave(hpage);
1500 }
1501
GRestore()1502 public void GRestore() {
1503 HPDF_Page_GRestore(hpage);
1504 }
1505
Concat(float a, float b, float c, float d, float x, float y)1506 public void Concat(float a, float b, float c, float d, float x, float y) {
1507 HPDF_Page_Concat(hpage, a, b, c, d, x, y);
1508 }
1509
MoveTo(float x, float y)1510 public void MoveTo(float x, float y) {
1511 HPDF_Page_MoveTo(hpage, x, y);
1512 }
1513
LineTo(float x, float y)1514 public void LineTo(float x, float y) {
1515 HPDF_Page_LineTo(hpage, x, y);
1516 }
1517
CurveTo(float x1, float y1, float x2, float y2, float x3, float y3)1518 public void CurveTo(float x1, float y1, float x2, float y2,
1519 float x3, float y3) {
1520 HPDF_Page_CurveTo(hpage, x1, y1, x2, y2, x3, y3);
1521 }
1522
CurveTo2(float x2, float y2, float x3, float y3)1523 public void CurveTo2(float x2, float y2, float x3, float y3) {
1524 HPDF_Page_CurveTo2(hpage, x2, y2, x3, y3);
1525 }
1526
CurveTo3(float x1, float y1, float x3, float y3)1527 public void CurveTo3(float x1, float y1, float x3, float y3) {
1528 HPDF_Page_CurveTo2(hpage, x1, y1, x3, y3);
1529 }
1530
ClosePath()1531 public void ClosePath() {
1532 HPDF_Page_ClosePath(hpage);
1533 }
1534
Rectangle(float x, float y, float width, float height)1535 public void Rectangle(float x, float y, float width, float height) {
1536 HPDF_Page_Rectangle(hpage, x, y, width, height);
1537 }
1538
Stroke()1539 public void Stroke() {
1540 HPDF_Page_Stroke(hpage);
1541 }
1542
ClosePathStroke()1543 public void ClosePathStroke() {
1544 HPDF_Page_ClosePathStroke(hpage);
1545 }
1546
Fill()1547 public void Fill() {
1548 HPDF_Page_Fill(hpage);
1549 }
1550
Eofill()1551 public void Eofill() {
1552 HPDF_Page_Eofill(hpage);
1553 }
1554
FillStroke()1555 public void FillStroke() {
1556 HPDF_Page_FillStroke(hpage);
1557 }
1558
EofillStroke()1559 public void EofillStroke() {
1560 HPDF_Page_EofillStroke(hpage);
1561 }
1562
ClosePathFillStroke()1563 public void ClosePathFillStroke() {
1564 HPDF_Page_ClosePathFillStroke(hpage);
1565 }
1566
ClosePathEofillStroke()1567 public void ClosePathEofillStroke() {
1568 HPDF_Page_ClosePathEofillStroke(hpage);
1569 }
1570
EndPath()1571 public void EndPath() {
1572 HPDF_Page_EndPath(hpage);
1573 }
1574
Clip()1575 public void Clip() {
1576 HPDF_Page_Clip(hpage);
1577 }
1578
Eoclip()1579 public void Eoclip() {
1580 HPDF_Page_Eoclip(hpage);
1581 }
1582
BeginText()1583 public void BeginText() {
1584 HPDF_Page_BeginText(hpage);
1585 }
1586
EndText()1587 public void EndText() {
1588 HPDF_Page_EndText(hpage);
1589 }
1590
SetCharSpace(float value)1591 public void SetCharSpace(float value) {
1592 HPDF_Page_SetCharSpace(hpage, value);
1593 }
1594
SetWordSpace(float value)1595 public void SetWordSpace(float value) {
1596 HPDF_Page_SetWordSpace(hpage, value);
1597 }
1598
SetHorizontalScalling(float value)1599 public void SetHorizontalScalling(float value) {
1600 HPDF_Page_SetHorizontalScalling(hpage, value);
1601 }
1602
SetTextLeading(float value)1603 public void SetTextLeading(float value) {
1604 HPDF_Page_SetTextLeading(hpage, value);
1605 }
1606
SetFontAndSize(HPdfFont font, float size)1607 public void SetFontAndSize(HPdfFont font, float size) {
1608 HPDF_Page_SetFontAndSize(hpage, font.GetHandle(), size);
1609 }
1610
SetTextRenderingMode(HPdfTextRenderingMode mode)1611 public void SetTextRenderingMode(HPdfTextRenderingMode mode) {
1612 HPDF_Page_SetTextRenderingMode(hpage, mode);
1613 }
1614
SetTextRaise(float value)1615 public void SetTextRaise(float value) {
1616 HPDF_Page_SetTextRaise(hpage, value);
1617 }
1618
MoveTextPos(float x, float y)1619 public void MoveTextPos(float x, float y) {
1620 HPDF_Page_MoveTextPos(hpage, x, y);
1621 }
1622
MoveTextPos2(float x, float y)1623 public void MoveTextPos2(float x, float y) {
1624 HPDF_Page_MoveTextPos2(hpage, x, y);
1625 }
1626
SetTextMatrix(float a, float b, float c, float d, float x, float y)1627 public void SetTextMatrix(float a, float b, float c, float d, float x, float y) {
1628 HPDF_Page_SetTextMatrix(hpage, a, b, c, d, x, y);
1629 }
1630
MoveToNextLine()1631 public void MoveToNextLine() {
1632 HPDF_Page_MoveToNextLine(hpage);
1633 }
1634
ShowText(string text)1635 public void ShowText(string text) {
1636 HPDF_Page_ShowText(hpage, text);
1637 }
1638
ShowTextNextLine(string text)1639 public void ShowTextNextLine(string text) {
1640 HPDF_Page_ShowTextNextLine(hpage, text);
1641 }
1642
ShowTextNextLineEx(float word_space, float char_space, string text)1643 public void ShowTextNextLineEx(float word_space, float char_space,
1644 string text) {
1645 HPDF_Page_ShowTextNextLineEx(hpage, word_space, char_space, text);
1646 }
1647
SetGrayFill(float gray)1648 public void SetGrayFill(float gray) {
1649 HPDF_Page_SetGrayFill(hpage, gray);
1650 }
1651
SetGrayStroke(float gray)1652 public void SetGrayStroke(float gray) {
1653 HPDF_Page_SetGrayStroke(hpage, gray);
1654 }
1655
SetRGBFill(float r, float g, float b)1656 public void SetRGBFill(float r, float g, float b) {
1657 HPDF_Page_SetRGBFill(hpage, r, g, b);
1658 }
1659
SetRGBStroke(float r, float g, float b)1660 public void SetRGBStroke(float r, float g, float b) {
1661 HPDF_Page_SetRGBStroke(hpage, r, g, b);
1662 }
1663
SetCMYKFill(float c, float m, float y, float k)1664 public void SetCMYKFill(float c, float m, float y, float k) {
1665 HPDF_Page_SetCMYKFill(hpage, c, m, y, k);
1666 }
1667
SetCMYKStroke(float c, float m, float y, float k)1668 public void SetCMYKStroke(float c, float m, float y, float k) {
1669 HPDF_Page_SetCMYKStroke(hpage, c, m, y, k);
1670 }
1671
ExecuteXObject(HPdfImage xobj)1672 public void ExecuteXObject(HPdfImage xobj) {
1673 HPDF_Page_ExecuteXObject(hpage, xobj.GetHandle());
1674 }
1675
DrawImage(HPdfImage image, float x, float y, float width, float height)1676 public void DrawImage(HPdfImage image, float x, float y,
1677 float width, float height) {
1678 HPDF_Page_DrawImage(hpage, image.GetHandle(), x, y, width, height);
1679 }
1680
Circle(float x, float y, float ray)1681 public void Circle(float x, float y, float ray) {
1682 HPDF_Page_Circle(hpage, x, y, ray);
1683 }
1684
Arc(float x, float y, float ray, float ang1, float ang2)1685 public void Arc(float x, float y, float ray, float ang1, float ang2) {
1686 HPDF_Page_Arc(hpage, x, y, ray, ang1, ang2);
1687 }
1688
TextOut(float xpos, float ypos, string text)1689 public void TextOut(float xpos, float ypos, string text) {
1690 HPDF_Page_TextOut(hpage, xpos, ypos, text);
1691 }
1692
TextRect(float left, float top, float right, float bottom, string text, HPdfTextAlignment align, ref uint len)1693 public void TextRect(float left, float top, float right,
1694 float bottom, string text, HPdfTextAlignment align,
1695 ref uint len) {
1696 HPDF_Page_TextRect(hpage, left, top, right, bottom, text, align, ref len);
1697 }
1698
SetSlideShow(HPdfTransitionStyle type, float disp_time, float trans_time)1699 public void SetSlideShow(HPdfTransitionStyle type, float disp_time,
1700 float trans_time) {
1701 HPDF_Page_SetSlideShow(hpage, type, disp_time, trans_time);
1702 }
1703
GetHandle()1704 public IntPtr GetHandle() {
1705 return hpage;
1706 }
1707 }
1708
1709 public class HPdfFont {
1710 [DllImport("libhpdf.dll")]
HPDF_Font_GetFontName(IntPtr hfont)1711 private extern static string HPDF_Font_GetFontName(IntPtr hfont);
1712
1713 [DllImport("libhpdf.dll")]
HPDF_Font_GetEncodingName(IntPtr hfont)1714 private extern static string HPDF_Font_GetEncodingName(IntPtr hfont);
1715
1716 [DllImport("libhpdf.dll")]
HPDF_Font_GetUnicodeWidth(IntPtr hfont, ushort code)1717 private extern static int HPDF_Font_GetUnicodeWidth(IntPtr hfont,
1718 ushort code);
1719
1720 [DllImport("libhpdf.dll")]
HPDF_Font_GetBBox(IntPtr hfont)1721 private extern static HPdfBox HPDF_Font_GetBBox(IntPtr hfont);
1722
1723 [DllImport("libhpdf.dll")]
HPDF_Font_GetAscent(IntPtr hfont)1724 private extern static int HPDF_Font_GetAscent(IntPtr hfont);
1725
1726 [DllImport("libhpdf.dll")]
HPDF_Font_GetDescent(IntPtr hfont)1727 private extern static int HPDF_Font_GetDescent(IntPtr hfont);
1728
1729 [DllImport("libhpdf.dll")]
HPDF_Font_GetXHeight(IntPtr hfont)1730 private extern static uint HPDF_Font_GetXHeight(IntPtr hfont);
1731
1732 [DllImport("libhpdf.dll")]
HPDF_Font_GetCapHeight(IntPtr hfont)1733 private extern static uint HPDF_Font_GetCapHeight(IntPtr hfont);
1734
1735 [DllImport("libhpdf.dll")]
HPDF_Font_TextWidth(IntPtr hfont, string text, uint len)1736 private extern static HPdfTextWidth HPDF_Font_TextWidth(IntPtr hfont,
1737 string text, uint len);
1738
1739 [DllImport("libhpdf.dll")]
HPDF_Font_MeasureText(IntPtr hfont, string text, uint len, float width, float font_size, float char_space, float word_space, int wordwrap, ref float real_width)1740 private extern static uint HPDF_Font_MeasureText(IntPtr hfont,
1741 string text, uint len, float width, float font_size,
1742 float char_space, float word_space, int wordwrap,
1743 ref float real_width);
1744
1745
1746 IntPtr hfont;
1747
HPdfFont(IntPtr hfont)1748 public HPdfFont(IntPtr hfont) {
1749 if (hfont == IntPtr.Zero) {
1750 throw new Exception("cannot create HPdfFont object.");
1751 }
1752
1753 this.hfont = hfont;
1754 }
1755
GetHandle()1756 public IntPtr GetHandle() {
1757 return hfont;
1758 }
1759
GetFontName()1760 public string GetFontName() {
1761 return HPDF_Font_GetFontName(hfont);
1762 }
1763
GetEncodingName()1764 public string GetEncodingName() {
1765 return HPDF_Font_GetEncodingName(hfont);
1766 }
1767
GetUnicodeWidth(ushort code)1768 public int GetUnicodeWidth(ushort code) {
1769 return HPDF_Font_GetUnicodeWidth(hfont, code);
1770 }
1771
GetBBox()1772 public HPdfBox GetBBox() {
1773 return HPDF_Font_GetBBox(hfont);
1774 }
1775
GetAscent()1776 public int GetAscent() {
1777 return HPDF_Font_GetAscent(hfont);
1778 }
1779
GetDescent()1780 public int GetDescent() {
1781 return HPDF_Font_GetDescent(hfont);
1782 }
1783
GetXHeight()1784 public uint GetXHeight() {
1785 return HPDF_Font_GetXHeight(hfont);
1786 }
1787
GetCapHeight()1788 public uint GetCapHeight() {
1789 return HPDF_Font_GetCapHeight(hfont);
1790 }
1791
TextWidth(string text, uint len)1792 public HPdfTextWidth TextWidth(string text, uint len) {
1793 return HPDF_Font_TextWidth(hfont, text, len);
1794 }
1795
MeasureText(string text, uint len, float width, float font_size, float char_space, float word_space, int wordwrap, ref float real_width)1796 public uint MeasureText(string text, uint len, float width,
1797 float font_size, float char_space, float word_space,
1798 int wordwrap, ref float real_width) {
1799 return HPDF_Font_MeasureText(hfont, text, len, width, font_size,
1800 char_space, word_space, wordwrap,
1801 ref real_width);
1802 }
1803 }
1804
1805 public class HPdfOutline {
1806 [DllImport("libhpdf.dll")]
HPDF_Outline_SetOpened(IntPtr houtline, int opened)1807 private extern static uint HPDF_Outline_SetOpened(IntPtr houtline,
1808 int opened);
1809
1810 [DllImport("libhpdf.dll")]
HPDF_Outline_SetDestination(IntPtr houtline, IntPtr hdest)1811 private extern static uint HPDF_Outline_SetDestination(IntPtr houtline,
1812 IntPtr hdest);
1813
1814 IntPtr houtline;
1815
HPdfOutline(IntPtr houtline)1816 public HPdfOutline(IntPtr houtline) {
1817 if (houtline == IntPtr.Zero) {
1818 throw new Exception("cannot create HPdfOutline object.");
1819 }
1820
1821 this.houtline = houtline;
1822 }
1823
GetHandle()1824 public IntPtr GetHandle() {
1825 return houtline;
1826 }
1827
SetOpened(bool opened)1828 public void SetOpened(bool opened) {
1829 int iopened;
1830
1831 if (opened)
1832 iopened = HPdfDoc.HPDF_TRUE;
1833 else
1834 iopened = HPdfDoc.HPDF_FALSE;
1835
1836 HPDF_Outline_SetOpened(houtline, iopened);
1837 }
1838
SetDestination(HPdfDestination dest)1839 public void SetDestination(HPdfDestination dest) {
1840 HPDF_Outline_SetDestination(houtline, dest.GetHandle());
1841 }
1842 }
1843
1844 public class HPdfEncoder {
1845 IntPtr hencoder;
1846
HPdfEncoder(IntPtr hencoder)1847 public HPdfEncoder(IntPtr hencoder) {
1848 if (hencoder == IntPtr.Zero) {
1849 throw new Exception("cannot create HPdfEncoder object.");
1850 }
1851
1852 this.hencoder = hencoder;
1853 }
1854
1855 [DllImport("libhpdf.dll")]
HPDF_Encoder_GetType(IntPtr hencoder)1856 private extern static HPdfEncoderType HPDF_Encoder_GetType(IntPtr
1857 hencoder);
1858
1859 [DllImport("libhpdf.dll")]
HPDF_Encoder_GetByteType(IntPtr hencoder, string text, uint index)1860 private extern static HPdfByteType HPDF_Encoder_GetByteType(IntPtr
1861 hencoder, string text, uint index);
1862
1863 [DllImport("libhpdf.dll")]
HPDF_Encoder_GetUnicode(IntPtr hencoder, ushort code)1864 private extern static ushort HPDF_Encoder_GetUnicode(IntPtr
1865 hencoder, ushort code);
1866
1867 [DllImport("libhpdf.dll")]
HPDF_Encoder_GetWritingMode(IntPtr hencoder)1868 private extern static HPdfWritingMode HPDF_Encoder_GetWritingMode(IntPtr
1869 hencoder);
1870
1871
GetHandle()1872 public IntPtr GetHandle() {
1873 return hencoder;
1874 }
1875
GetEncoderType()1876 public HPdfEncoderType GetEncoderType() {
1877 return HPDF_Encoder_GetType(hencoder);
1878 }
1879
GetByteType(string text, uint index)1880 public HPdfByteType GetByteType(string text, uint index) {
1881 return HPDF_Encoder_GetByteType(hencoder, text, index);
1882 }
1883
GetUnicode(ushort code)1884 public ushort GetUnicode(ushort code) {
1885 return HPDF_Encoder_GetUnicode(hencoder, code);
1886 }
1887
GetWritingMode()1888 public HPdfWritingMode GetWritingMode() {
1889 return HPDF_Encoder_GetWritingMode(hencoder);
1890 }
1891
1892 }
1893
1894 public class HPdfDestination {
1895 [DllImport("libhpdf.dll")]
HPDF_Destination_SetXYZ(IntPtr hdest, float left, float top, float zoom)1896 private extern static uint HPDF_Destination_SetXYZ(IntPtr hdest,
1897 float left, float top, float zoom);
1898
1899 [DllImport("libhpdf.dll")]
HPDF_Destination_SetFit(IntPtr hdest)1900 private extern static uint HPDF_Destination_SetFit(IntPtr hdest);
1901
1902 [DllImport("libhpdf.dll")]
HPDF_Destination_SetFitH(IntPtr hdest, float top)1903 private extern static uint HPDF_Destination_SetFitH(IntPtr hdest,
1904 float top);
1905
1906 [DllImport("libhpdf.dll")]
HPDF_Destination_SetFitV(IntPtr hdest, float left)1907 private extern static uint HPDF_Destination_SetFitV(IntPtr hdest,
1908 float left);
1909
1910 [DllImport("libhpdf.dll")]
HPDF_Destination_SetFitR(IntPtr hdest, float left, float bottom, float right, float top)1911 private extern static uint HPDF_Destination_SetFitR(IntPtr hdest,
1912 float left, float bottom, float right, float top);
1913
1914 [DllImport("libhpdf.dll")]
HPDF_Destination_SetFitB(IntPtr hdest)1915 private extern static uint HPDF_Destination_SetFitB(IntPtr hdest);
1916
1917 [DllImport("libhpdf.dll")]
HPDF_Destination_SetFitBH(IntPtr hdest, float top)1918 private extern static uint HPDF_Destination_SetFitBH(IntPtr hdest,
1919 float top);
1920
1921 [DllImport("libhpdf.dll")]
HPDF_Destination_SetFitBV(IntPtr hdest, float left)1922 private extern static uint HPDF_Destination_SetFitBV(IntPtr hdest,
1923 float left);
1924
1925 IntPtr hdest;
1926
HPdfDestination(IntPtr hdest)1927 public HPdfDestination(IntPtr hdest) {
1928 if (hdest == IntPtr.Zero) {
1929 throw new Exception("cannot create HPdfDestination object.");
1930 }
1931
1932 this.hdest = hdest;
1933 }
1934
SetXYZ(float left, float top, float zoom)1935 public void SetXYZ(float left, float top, float zoom) {
1936 HPDF_Destination_SetXYZ(hdest, left, top, zoom);
1937 }
1938
SetFit()1939 public void SetFit() {
1940 HPDF_Destination_SetFit(hdest);
1941 }
1942
SetFitH(float top)1943 public void SetFitH(float top) {
1944 HPDF_Destination_SetFitH(hdest, top);
1945 }
1946
SetFitV(float left)1947 public void SetFitV(float left) {
1948 HPDF_Destination_SetFitV(hdest, left);
1949 }
1950
SetFitR(float left, float bottom, float right, float top)1951 public void SetFitR(float left, float bottom, float right, float top) {
1952 HPDF_Destination_SetFitR(hdest, left, bottom, right, top);
1953 }
1954
SetFitB()1955 public void SetFitB() {
1956 HPDF_Destination_SetFitB(hdest);
1957 }
1958
SetFitBH(float top)1959 public void SetFitBH(float top) {
1960 HPDF_Destination_SetFitBH(hdest, top);
1961 }
1962
SetFitBV(float left)1963 public void SetFitBV(float left) {
1964 HPDF_Destination_SetFitBV(hdest, left);
1965 }
1966
GetHandle()1967 public IntPtr GetHandle() {
1968 return hdest;
1969 }
1970 }
1971
1972 public class HPdfAnnotation {
1973 IntPtr hannot;
1974
1975 [DllImport("libhpdf.dll")]
HPDF_LinkAnnot_SetHighlightMode(IntPtr hannot, HPdfAnnotHighlightMode mode)1976 private extern static uint HPDF_LinkAnnot_SetHighlightMode(IntPtr hannot,
1977 HPdfAnnotHighlightMode mode);
1978
1979 [DllImport("libhpdf.dll")]
HPDF_LinkAnnot_SetBorderStyle(IntPtr hannot, float width, ushort dash_on, ushort dash_off)1980 private extern static uint HPDF_LinkAnnot_SetBorderStyle(IntPtr hannot,
1981 float width, ushort dash_on, ushort dash_off);
1982
1983 [DllImport("libhpdf.dll")]
HPDF_TextAnnot_SetIcon(IntPtr hannot, HPdfAnnotIcon icon)1984 private extern static uint HPDF_TextAnnot_SetIcon(IntPtr hannot,
1985 HPdfAnnotIcon icon);
1986
1987 [DllImport("libhpdf.dll")]
HPDF_TextAnnot_SetOpened(IntPtr hannot, int opened)1988 private extern static uint HPDF_TextAnnot_SetOpened(IntPtr hannot,
1989 int opened);
1990
1991
HPdfAnnotation(IntPtr hannot)1992 public HPdfAnnotation(IntPtr hannot) {
1993 if (hannot == IntPtr.Zero) {
1994 throw new Exception("cannot create HPdfAnnotation object.");
1995 }
1996
1997 this.hannot = hannot;
1998 }
1999
GetHandle()2000 public IntPtr GetHandle() {
2001 return hannot;
2002 }
2003
SetHighlightMode(HPdfAnnotHighlightMode mode)2004 public void SetHighlightMode(HPdfAnnotHighlightMode mode) {
2005 HPDF_LinkAnnot_SetHighlightMode(hannot, mode);
2006 }
2007
SetBorderStyle(float width, ushort dash_on, ushort dash_off)2008 public void SetBorderStyle(float width, ushort dash_on, ushort dash_off) {
2009 HPDF_LinkAnnot_SetBorderStyle(hannot, width, dash_on, dash_off);
2010 }
2011
SetIcon(HPdfAnnotIcon icon)2012 public void SetIcon(HPdfAnnotIcon icon) {
2013 HPDF_TextAnnot_SetIcon(hannot, icon);
2014 }
2015
SetOpened(bool opened)2016 public void SetOpened(bool opened) {
2017 int flg;
2018
2019 if (opened)
2020 flg = HPdfDoc.HPDF_TRUE;
2021 else
2022 flg = HPdfDoc.HPDF_FALSE;
2023
2024 HPDF_TextAnnot_SetOpened(hannot, flg);
2025 }
2026
2027 }
2028
2029 public class HPdfXObject {
2030 protected IntPtr hobj;
2031
HPdfXObject(IntPtr hobj)2032 public HPdfXObject(IntPtr hobj) {
2033 if (hobj == IntPtr.Zero) {
2034 throw new Exception("cannot create HPdfImage object.");
2035 }
2036
2037 this.hobj = hobj;
2038 }
2039
GetHandle()2040 public IntPtr GetHandle() {
2041 return hobj;
2042 }
2043 }
2044
2045 public class HPdfImage: HPdfXObject {
2046
2047 [DllImport("libhpdf.dll")]
HPDF_Image_GetSize(IntPtr image)2048 private extern static HPdfPoint HPDF_Image_GetSize(IntPtr image);
2049
2050 [DllImport("libhpdf.dll")]
HPDF_Image_GetWidth(IntPtr image)2051 private extern static uint HPDF_Image_GetWidth(IntPtr image);
2052
2053 [DllImport("libhpdf.dll")]
HPDF_Image_GetHeight(IntPtr image)2054 private extern static uint HPDF_Image_GetHeight(IntPtr image);
2055
2056 [DllImport("libhpdf.dll")]
HPDF_Image_GetBitsPerComponent(IntPtr image)2057 private extern static uint HPDF_Image_GetBitsPerComponent(IntPtr image);
2058
2059 [DllImport("libhpdf.dll")]
HPDF_Image_GetColorSpace(IntPtr image)2060 private extern static string HPDF_Image_GetColorSpace(IntPtr image);
2061
2062 [DllImport("libhpdf.dll")]
HPDF_Image_SetColorMask(IntPtr image, uint rmin, uint rmax, uint gmin, uint gmax, uint bmin, uint bmax)2063 private extern static uint HPDF_Image_SetColorMask(IntPtr image,
2064 uint rmin, uint rmax, uint gmin, uint gmax, uint bmin, uint bmax);
2065
2066 [DllImport("libhpdf.dll")]
HPDF_Image_SetMaskImage(IntPtr image, IntPtr mask_image)2067 private extern static string HPDF_Image_SetMaskImage(IntPtr image,
2068 IntPtr mask_image);
2069
HPdfImage(IntPtr hobj)2070 public HPdfImage(IntPtr hobj): base (hobj) {
2071 }
2072
GetSize()2073 public HPdfPoint GetSize() {
2074 return HPDF_Image_GetSize(hobj);
2075 }
2076
GetWidth()2077 public uint GetWidth() {
2078 return HPDF_Image_GetWidth(hobj);
2079 }
2080
GetHeight()2081 public uint GetHeight() {
2082 return HPDF_Image_GetHeight(hobj);
2083 }
2084
GetBitsPerComponent()2085 public uint GetBitsPerComponent() {
2086 return HPDF_Image_GetBitsPerComponent(hobj);
2087 }
2088
GetColorSpace()2089 public string GetColorSpace() {
2090 return HPDF_Image_GetColorSpace(hobj);
2091 }
2092
SetColorMask(uint rmin, uint rmax, uint gmin, uint gmax, uint bmin, uint bmax)2093 public void SetColorMask(uint rmin, uint rmax, uint gmin, uint gmax,
2094 uint bmin, uint bmax) {
2095 HPDF_Image_SetColorMask(hobj, rmin, rmax, gmin, gmax,
2096 bmin, bmax);
2097 }
2098
SetMaskImage(HPdfImage mask_image)2099 public void SetMaskImage(HPdfImage mask_image) {
2100 HPDF_Image_SetMaskImage(hobj, mask_image.GetHandle());
2101 }
2102 }
2103
2104 public class HPdfExtGState {
2105 protected IntPtr hgstate;
2106
2107 [DllImport("libhpdf.dll")]
HPDF_ExtGState_SetAlphaStroke(IntPtr gstate, float value)2108 private extern static uint HPDF_ExtGState_SetAlphaStroke(IntPtr gstate,
2109 float value);
2110
2111 [DllImport("libhpdf.dll")]
HPDF_ExtGState_SetAlphaFill(IntPtr gstate, float value)2112 private extern static uint HPDF_ExtGState_SetAlphaFill(IntPtr gstate,
2113 float value);
2114
2115 [DllImport("libhpdf.dll")]
HPDF_ExtGState_SetBlendMode(IntPtr gstate, HPdfBlendMode mode)2116 private extern static uint HPDF_ExtGState_SetBlendMode(IntPtr gstate,
2117 HPdfBlendMode mode);
2118
HPdfExtGState(IntPtr hgstate)2119 public HPdfExtGState(IntPtr hgstate) {
2120 if (hgstate == IntPtr.Zero) {
2121 throw new Exception("cannot create HPdfImage object.");
2122 }
2123
2124 this.hgstate = hgstate;
2125 }
2126
GetHandle()2127 public IntPtr GetHandle() {
2128 return hgstate;
2129 }
2130
SetAlphaStroke(float value)2131 public void SetAlphaStroke(float value) {
2132 HPDF_ExtGState_SetAlphaStroke(hgstate, value);
2133 }
2134
SetAlphaFill(float value)2135 public void SetAlphaFill(float value) {
2136 HPDF_ExtGState_SetAlphaFill(hgstate, value);
2137 }
2138
SetBlendMode(HPdfBlendMode mode)2139 public void SetBlendMode(HPdfBlendMode mode) {
2140 HPDF_ExtGState_SetBlendMode(hgstate, mode);
2141 }
2142
2143
2144
2145
2146 }
2147
2148 }
2149
2150
2151