forked from marcpabst/PdfiumLight
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNativeMethods.Pdfium.cs
More file actions
1100 lines (883 loc) · 36.5 KB
/
NativeMethods.Pdfium.cs
File metadata and controls
1100 lines (883 loc) · 36.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
#pragma warning disable 1591
namespace PdfiumLight
{
public partial class NativeMethods
{
// Interned strings are cached over AppDomains. This means that when we
// lock on this string, we actually lock over AppDomain's. The Pdfium
// library is not thread safe, and this way of locking
// guarantees that we don't access the Pdfium library from different
// threads, even when there are multiple AppDomain's in play.
private static readonly string LockString = string.Intern("e362349b-001d-4cb2-bf55-a71606a3e36f");
public static void FPDF_AddRef()
{
lock (LockString)
{
Imports.FPDF_AddRef();
}
}
public static void FPDF_Release()
{
lock (LockString)
{
Imports.FPDF_Release();
}
}
public static IntPtr FPDF_LoadMemDocument(SafeHandle data_buf, int size, string password)
{
lock (LockString)
{
return Imports.FPDF_LoadMemDocument(data_buf, size, password);
}
}
public static IntPtr FPDF_LoadMemDocument(byte[] data_buf, int size, string password)
{
lock (LockString)
{
return Imports.FPDF_LoadMemDocument(data_buf, size, password);
}
}
public static void FPDF_CloseDocument(IntPtr document)
{
lock (LockString)
{
Imports.FPDF_CloseDocument(document);
}
}
public static int FPDF_GetPageCount(IntPtr document)
{
lock (LockString)
{
return Imports.FPDF_GetPageCount(document);
}
}
public static uint FPDF_GetDocPermissions(IntPtr document)
{
lock (LockString)
{
return Imports.FPDF_GetDocPermissions(document);
}
}
public static IntPtr FPDFDOC_InitFormFillEnvironment(IntPtr document, FPDF_FORMFILLINFO formInfo)
{
lock (LockString)
{
return Imports.FPDFDOC_InitFormFillEnvironment(document, formInfo);
}
}
public static void FPDF_SetFormFieldHighlightColor(IntPtr hHandle, int fieldType, uint color)
{
lock (LockString)
{
Imports.FPDF_SetFormFieldHighlightColor(hHandle, fieldType, color);
}
}
public static void FPDF_SetFormFieldHighlightAlpha(IntPtr hHandle, byte alpha)
{
lock (LockString)
{
Imports.FPDF_SetFormFieldHighlightAlpha(hHandle, alpha);
}
}
public static void FORM_DoDocumentJSAction(IntPtr hHandle)
{
lock (LockString)
{
Imports.FORM_DoDocumentJSAction(hHandle);
}
}
public static void FORM_DoDocumentOpenAction(IntPtr hHandle)
{
lock (LockString)
{
Imports.FORM_DoDocumentOpenAction(hHandle);
}
}
public static void FPDFDOC_ExitFormFillEnvironment(IntPtr hHandle)
{
lock (LockString)
{
Imports.FPDFDOC_ExitFormFillEnvironment(hHandle);
}
}
public static void FORM_DoDocumentAAction(IntPtr hHandle, FPDFDOC_AACTION aaType)
{
lock (LockString)
{
Imports.FORM_DoDocumentAAction(hHandle, aaType);
}
}
public static IntPtr FPDF_LoadPage(IntPtr document, int page_index)
{
lock (LockString)
{
return Imports.FPDF_LoadPage(document, page_index);
}
}
public static void FPDFPage_SetCropBox(IntPtr page_object, float left, float bottom, float right, float top)
{
lock (LockString)
{
Imports.FPDFPage_SetCropBox(page_object, left, bottom, right, top);
}
}
// remove start
public static IntPtr FPDFPageObj_NewPathObj()
{
lock (LockString)
{
return Imports.FPDFPageObj_NewPathObj();
}
}
public static IntPtr FPDFPathObj_GetPath(IntPtr path_object)
{
lock (LockString)
{
return Imports.FPDFPathObj_GetPath(path_object);
}
}
public static void FPDFPathObj_InsertPoint(IntPtr path_object, double x, double y, int flag)
{
lock (LockString)
{
Imports.FPDFPathObj_InsertPoint(path_object, x, y, flag);
}
}
public static void FPDFPageObj_AddClip(IntPtr page_object, IntPtr path_object, int type)
{
lock (LockString)
{
Imports.FPDFPageObj_AddClip(page_object, path_object, type);
}
}
// remove end
public static IntPtr FPDFText_LoadPage(IntPtr page)
{
lock (LockString)
{
return Imports.FPDFText_LoadPage(page);
}
}
public static void FORM_OnAfterLoadPage(IntPtr page, IntPtr _form)
{
lock (LockString)
{
Imports.FORM_OnAfterLoadPage(page, _form);
}
}
public static void FORM_DoPageAAction(IntPtr page, IntPtr _form, FPDFPAGE_AACTION fPDFPAGE_AACTION)
{
lock (LockString)
{
Imports.FORM_DoPageAAction(page, _form, fPDFPAGE_AACTION);
}
}
public static double FPDF_GetPageWidth(IntPtr page)
{
lock (LockString)
{
return Imports.FPDF_GetPageWidth(page);
}
}
public static double FPDF_GetPageHeight(IntPtr page)
{
lock (LockString)
{
return Imports.FPDF_GetPageHeight(page);
}
}
public static void FORM_OnBeforeClosePage(IntPtr page, IntPtr _form)
{
lock (LockString)
{
Imports.FORM_OnBeforeClosePage(page, _form);
}
}
public static void FPDFText_ClosePage(IntPtr text_page)
{
lock (LockString)
{
Imports.FPDFText_ClosePage(text_page);
}
}
public static void FPDF_ClosePage(IntPtr page)
{
lock (LockString)
{
Imports.FPDF_ClosePage(page);
}
}
public static void FPDF_RenderPage(IntPtr dc, IntPtr page, int start_x, int start_y, int size_x, int size_y, int rotate, FPDF flags)
{
lock (LockString)
{
Imports.FPDF_RenderPage(dc, page, start_x, start_y, size_x, size_y, rotate, flags);
}
}
public static void FPDF_RenderPageBitmap(IntPtr bitmapHandle, IntPtr page, int start_x, int start_y, int size_x, int size_y, int rotate, FPDF flags)
{
lock (LockString)
{
Imports.FPDF_RenderPageBitmap(bitmapHandle, page, start_x, start_y, size_x, size_y, rotate, flags);
}
}
public static int FPDF_GetPageSizeByIndex(IntPtr document, int page_index, out double width, out double height)
{
lock (LockString)
{
return Imports.FPDF_GetPageSizeByIndex(document, page_index, out width, out height);
}
}
public static IntPtr FPDFBitmap_CreateEx(int width, int height, int format, IntPtr first_scan, int stride)
{
lock (LockString)
{
return Imports.FPDFBitmap_CreateEx(width, height, format, first_scan, stride);
}
}
public static void FPDFBitmap_FillRect(IntPtr bitmapHandle, int left, int top, int width, int height, uint color)
{
lock (LockString)
{
Imports.FPDFBitmap_FillRect(bitmapHandle, left, top, width, height, color);
}
}
public static IntPtr FPDFBitmap_Destroy(IntPtr bitmapHandle)
{
lock (LockString)
{
return Imports.FPDFBitmap_Destroy(bitmapHandle);
}
}
public static IntPtr FPDFText_FindStart(IntPtr page, byte[] findWhat, FPDF_SEARCH_FLAGS flags, int start_index)
{
lock (LockString)
{
return Imports.FPDFText_FindStart(page, findWhat, flags, start_index);
}
}
public static int FPDFText_GetSchResultIndex(IntPtr handle)
{
lock (LockString)
{
return Imports.FPDFText_GetSchResultIndex(handle);
}
}
public static int FPDFText_GetSchCount(IntPtr handle)
{
lock (LockString)
{
return Imports.FPDFText_GetSchCount(handle);
}
}
public static int FPDFText_GetText(IntPtr page, int start_index, int count, byte[] result)
{
lock (LockString)
{
return Imports.FPDFText_GetText(page, start_index, count, result);
}
}
public static void FPDFText_GetCharBox(IntPtr page, int index, out double left, out double right, out double bottom, out double top)
{
lock (LockString)
{
Imports.FPDFText_GetCharBox(page, index, out left, out right, out bottom, out top);
}
}
public static int FPDFText_CountChars(IntPtr page)
{
lock (LockString)
{
return Imports.FPDFText_CountChars(page);
}
}
public static bool FPDFText_FindNext(IntPtr handle)
{
lock (LockString)
{
return Imports.FPDFText_FindNext(handle);
}
}
public static void FPDFText_FindClose(IntPtr handle)
{
lock (LockString)
{
Imports.FPDFText_FindClose(handle);
}
}
public static bool FPDFLink_Enumerate(IntPtr page, ref int startPos, out IntPtr linkAnnot)
{
lock (LockString)
{
return Imports.FPDFLink_Enumerate(page, ref startPos, out linkAnnot);
}
}
public static IntPtr FPDFLink_GetDest(IntPtr document, IntPtr link)
{
lock (LockString)
{
return Imports.FPDFLink_GetDest(document, link);
}
}
public static uint FPDFDest_GetPageIndex(IntPtr document, IntPtr dest)
{
lock (LockString)
{
return Imports.FPDFDest_GetPageIndex(document, dest);
}
}
public static bool FPDFLink_GetAnnotRect(IntPtr linkAnnot, FS_RECTF rect)
{
lock (LockString)
{
return Imports.FPDFLink_GetAnnotRect(linkAnnot, rect);
}
}
public static void FPDF_DeviceToPage(IntPtr page, int start_x, int start_y, int size_x, int size_y, int rotate, int device_x, int device_y, out double page_x, out double page_y)
{
lock (LockString)
{
Imports.FPDF_DeviceToPage(page, start_x, start_y, size_x, size_y, rotate, device_x, device_y, out page_x, out page_y);
}
}
public static void FPDF_PageToDevice(IntPtr page, int start_x, int start_y, int size_x, int size_y, int rotate, double page_x, double page_y, out int device_x, out int device_y)
{
lock (LockString)
{
Imports.FPDF_PageToDevice(page, start_x, start_y, size_x, size_y, rotate, page_x, page_y, out device_x, out device_y);
}
}
public static IntPtr FPDFLink_GetAction(IntPtr link)
{
lock (LockString)
{
return Imports.FPDFLink_GetAction(link);
}
}
public static uint FPDFAction_GetURIPath(IntPtr document, IntPtr action, StringBuilder buffer, uint buflen)
{
lock (LockString)
{
return Imports.FPDFAction_GetURIPath(document, action, buffer, buflen);
}
}
public static IntPtr FPDF_BookmarkGetFirstChild(IntPtr document, IntPtr bookmark)
{
lock (LockString)
{
return Imports.FPDFBookmark_GetFirstChild(document, bookmark);
}
}
public static IntPtr FPDF_BookmarkGetNextSibling(IntPtr document, IntPtr bookmark)
{
lock (LockString)
return Imports.FPDFBookmark_GetNextSibling(document, bookmark);
}
public static uint FPDF_BookmarkGetTitle(IntPtr bookmark, byte[] buffer, uint buflen)
{
lock (LockString)
return Imports.FPDFBookmark_GetTitle(bookmark, buffer, buflen);
}
public static IntPtr FPDF_BookmarkGetAction(IntPtr bookmark)
{
lock (LockString)
return Imports.FPDFBookmark_GetAction(bookmark);
}
public static IntPtr FPDF_BookmarkGetDest(IntPtr document, IntPtr bookmark)
{
lock (LockString)
return Imports.FPDFBookmark_GetDest(document, bookmark);
}
public static uint FPDF_ActionGetType(IntPtr action)
{
lock (LockString)
return Imports.FPDFAction_GetType(action);
}
/// <summary>
/// Opens a document using a .NET Stream. Allows opening huge
/// PDFs without loading them into memory first.
/// </summary>
/// <param name="input">The input Stream. Don't dispose prior to closing the pdf.</param>
/// <param name="password">Password, if the PDF is protected. Can be null.</param>
/// <param name="id">Retrieves an IntPtr to the COM object for the Stream. The caller must release this with Marshal.Release prior to Disposing the Stream.</param>
/// <returns>An IntPtr to the FPDF_DOCUMENT object.</returns>
public static IntPtr FPDF_LoadCustomDocument(Stream input, string password, int id)
{
var getBlock = Marshal.GetFunctionPointerForDelegate(_getBlockDelegate);
var access = new FPDF_FILEACCESS
{
m_FileLen = (uint)input.Length,
m_GetBlock = getBlock,
m_Param = (IntPtr)id
};
lock (LockString)
{
return Imports.FPDF_LoadCustomDocument(access, password);
}
}
public static FPDF_ERR FPDF_GetLastError()
{
lock (LockString)
{
return (FPDF_ERR)Imports.FPDF_GetLastError();
}
}
public static uint FPDF_GetMetaText(IntPtr document, string tag, byte[] buffer, uint buflen)
{
lock (LockString)
{
return Imports.FPDF_GetMetaText(document, tag, buffer, buflen);
}
}
#region Save / Edit Methods
public static void FPDFPage_SetRotation(IntPtr page, PdfRotation rotation)
{
lock (LockString)
{
Imports.FPDFPage_SetRotation(page, (int)rotation);
}
}
public static bool FPDFPage_GenerateContent(IntPtr page)
{
lock (LockString)
{
return Imports.FPDFPage_GenerateContent(page);
}
}
public static void FPDFPage_Delete(IntPtr doc, int page)
{
lock (LockString)
{
Imports.FPDFPage_Delete(doc, page);
}
}
public static bool FPDF_SaveAsCopy(IntPtr doc, Stream output, FPDF_SAVE_FLAGS flags)
{
int id = StreamManager.Register(output);
try
{
var write = new FPDF_FILEWRITE
{
stream = (IntPtr)id,
version = 1,
WriteBlock = Marshal.GetFunctionPointerForDelegate(_saveBlockDelegate)
};
lock (LockString)
{
return Imports.FPDF_SaveAsCopy(doc, write, flags);
}
}
finally
{
StreamManager.Unregister(id);
}
}
public static bool FPDF_SaveWithVersion(IntPtr doc, Stream output, FPDF_SAVE_FLAGS flags, int fileVersion)
{
int id = StreamManager.Register(output);
try
{
var write = new FPDF_FILEWRITE
{
stream = (IntPtr)id,
version = 1,
WriteBlock = Marshal.GetFunctionPointerForDelegate(_saveBlockDelegate)
};
lock (LockString)
{
return Imports.FPDF_SaveWithVersion(doc, write, flags, fileVersion);
}
}
finally
{
StreamManager.Unregister(id);
}
}
public static int FPDFText_GetCharIndexAtPos(IntPtr page, double x, double y, double x_tolerance, double y_tolerance)
{
lock (LockString)
{
return Imports.FPDFText_GetCharIndexAtPos(page, x, y, x_tolerance, y_tolerance);
}
}
public static int FPDFText_CountRects(IntPtr text_page, int start_index, int count)
{
lock (LockString)
{
return Imports.FPDFText_CountRects(text_page, start_index, count);
}
}
public static void FPDFText_GetRect(IntPtr text_page, int rect_index, out double left, out double top, out double right, out double bottom)
{
lock (LockString)
{
Imports.FPDFText_GetRect(text_page, rect_index, out left, out top, out right, out bottom);
}
}
// Parameters:
// text_page - Handle to a text page information structure.
// left - Left boundary.
// top - Top boundary.
// right - Right boundary.
// bottom - Bottom boundary.
// buffer - A unicode buffer.
// buflen - Number of characters (not bytes) for the buffer, excluding an additional terminator.
// Return Value:
// If buffer is NULL or buflen is zero, return number of characters (not bytes) needed,
// otherwise, return number of characters copied into the buffer.
public static uint FPDFText_GetBoundedText(IntPtr text_page, double left, double top, double right, double bottom, byte[] buffer, uint buflen)
{
lock (LockString)
{
return Imports.FPDFText_GetBoundedText(text_page, left, top, right, bottom, buffer, buflen);
}
}
public static void FPDF_FFLDraw(IntPtr form, IntPtr bitmap, IntPtr page, int start_x, int start_y, int size_x, int size_y, int rotate, FPDF flags)
{
lock (LockString)
{
Imports.FPDF_FFLDraw(form, bitmap, page, start_x, start_y, size_x, size_y, rotate, flags);
}
}
#endregion
#region Custom Load/Save Logic
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate int FPDF_GetBlockDelegate(IntPtr param, uint position, IntPtr buffer, uint size);
private static readonly FPDF_GetBlockDelegate _getBlockDelegate = FPDF_GetBlock;
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate int FPDF_SaveBlockDelegate(IntPtr fileWrite, IntPtr data, uint size);
private static readonly FPDF_SaveBlockDelegate _saveBlockDelegate = FPDF_SaveBlock;
private static int FPDF_GetBlock(IntPtr param, uint position, IntPtr buffer, uint size)
{
var stream = StreamManager.Get((int)param);
if (stream is null)
return 0;
byte[] managedBuffer = new byte[size];
stream.Position = position;
int read = stream.Read(managedBuffer, 0, (int)size);
if (read != size)
return 0;
Marshal.Copy(managedBuffer, 0, buffer, (int)size);
return 1;
}
private static int FPDF_SaveBlock(IntPtr fileWrite, IntPtr data, uint size)
{
var write = new FPDF_FILEWRITE();
Marshal.PtrToStructure(fileWrite, write);
var stream = StreamManager.Get((int)write.stream);
if (stream is null)
return 0;
byte[] buffer = new byte[size];
Marshal.Copy(data, buffer, 0, (int)size);
try
{
stream.Write(buffer, 0, (int)size);
return (int)size;
}
catch
{
return 0;
}
}
#endregion
private static class Imports
{
[DllImport("pdfium.dll")]
public static extern void FPDF_AddRef();
[DllImport("pdfium.dll")]
public static extern void FPDF_Release();
[DllImport("pdfium.dll", CharSet = CharSet.Ansi)]
public static extern IntPtr FPDF_LoadCustomDocument([MarshalAs(UnmanagedType.LPStruct)]FPDF_FILEACCESS access, string password);
[DllImport("pdfium.dll", CharSet = CharSet.Ansi)]
public static extern IntPtr FPDF_LoadMemDocument(SafeHandle data_buf, int size, string password);
[DllImport("pdfium.dll", CharSet = CharSet.Ansi)]
public static extern IntPtr FPDF_LoadMemDocument(byte[] data_buf, int size, string password);
[DllImport("pdfium.dll")]
public static extern void FPDF_CloseDocument(IntPtr document);
[DllImport("pdfium.dll")]
public static extern int FPDF_GetPageCount(IntPtr document);
[DllImport("pdfium.dll")]
public static extern uint FPDF_GetDocPermissions(IntPtr document);
[DllImport("pdfium.dll")]
public static extern IntPtr FPDFDOC_InitFormFillEnvironment(IntPtr document, FPDF_FORMFILLINFO formInfo);
[DllImport("pdfium.dll")]
public static extern void FPDF_SetFormFieldHighlightColor(IntPtr hHandle, int fieldType, uint color);
[DllImport("pdfium.dll")]
public static extern void FPDF_SetFormFieldHighlightAlpha(IntPtr hHandle, byte alpha);
[DllImport("pdfium.dll")]
public static extern void FORM_DoDocumentJSAction(IntPtr hHandle);
[DllImport("pdfium.dll")]
public static extern void FORM_DoDocumentOpenAction(IntPtr hHandle);
[DllImport("pdfium.dll")]
public static extern void FPDFDOC_ExitFormFillEnvironment(IntPtr hHandle);
[DllImport("pdfium.dll")]
public static extern void FORM_DoDocumentAAction(IntPtr hHandle, FPDFDOC_AACTION aaType);
[DllImport("pdfium.dll")]
public static extern IntPtr FPDF_LoadPage(IntPtr document, int page_index);
[DllImport("pdfium.dll")]
public static extern IntPtr FPDFPage_SetCropBox(IntPtr page_object, float left, float bottom, float right, float top);
// remove start
[DllImport("pdfium.dll")]
public static extern IntPtr FPDFPathObj_GetPath(IntPtr path_object);
[DllImport("pdfium.dll")]
public static extern IntPtr FPDFPageObj_NewPathObj();
[DllImport("pdfium.dll")]
public static extern void FPDFPathObj_InsertPoint(IntPtr path_object, double x, double y, int flag);
[DllImport("pdfium.dll")]
public static extern IntPtr FPDFPageObj_AddClip(IntPtr page_object, IntPtr path_object, int type);
// remove end
[DllImport("pdfium.dll")]
public static extern IntPtr FPDFText_LoadPage(IntPtr page);
[DllImport("pdfium.dll")]
public static extern void FORM_OnAfterLoadPage(IntPtr page, IntPtr _form);
[DllImport("pdfium.dll")]
public static extern void FORM_DoPageAAction(IntPtr page, IntPtr _form, FPDFPAGE_AACTION fPDFPAGE_AACTION);
[DllImport("pdfium.dll")]
public static extern double FPDF_GetPageWidth(IntPtr page);
[DllImport("pdfium.dll")]
public static extern double FPDF_GetPageHeight(IntPtr page);
[DllImport("pdfium.dll")]
public static extern void FORM_OnBeforeClosePage(IntPtr page, IntPtr _form);
[DllImport("pdfium.dll")]
public static extern void FPDFText_ClosePage(IntPtr text_page);
[DllImport("pdfium.dll")]
public static extern int FPDFText_GetCharIndexAtPos(IntPtr text_page, double x, double y, double x_tolerance, double y_tolerance);
[DllImport("pdfium.dll")]
public static extern void FPDFText_GetRect(IntPtr text_page, int rect_index, out double left, out double top, out double right, out double bottom);
[DllImport("pdfium.dll")]
public static extern uint FPDFText_GetBoundedText(IntPtr text_page, double left, double top, double right, double bottom, byte[] buffer, uint buflen);
[DllImport("pdfium.dll")]
public static extern int FPDFText_CountRects(IntPtr text_page, int start_index, int count);
[DllImport("pdfium.dll")]
public static extern void FPDF_ClosePage(IntPtr page);
[DllImport("pdfium.dll")]
public static extern void FPDF_RenderPage(IntPtr dc, IntPtr page, int start_x, int start_y, int size_x, int size_y, int rotate, FPDF flags);
[DllImport("pdfium.dll")]
public static extern void FPDF_RenderPageBitmap(IntPtr bitmapHandle, IntPtr page, int start_x, int start_y, int size_x, int size_y, int rotate, FPDF flags);
[DllImport("pdfium.dll")]
public static extern int FPDF_GetPageSizeByIndex(IntPtr document, int page_index, out double width, out double height);
[DllImport("pdfium.dll")]
public static extern IntPtr FPDFBitmap_CreateEx(int width, int height, int format, IntPtr first_scan, int stride);
[DllImport("pdfium.dll")]
public static extern void FPDFBitmap_FillRect(IntPtr bitmapHandle, int left, int top, int width, int height, uint color);
[DllImport("pdfium.dll")]
public static extern IntPtr FPDFBitmap_Destroy(IntPtr bitmapHandle);
[DllImport("pdfium.dll")]
public static extern IntPtr FPDFText_FindStart(IntPtr page, byte[] findWhat, FPDF_SEARCH_FLAGS flags, int start_index);
[DllImport("pdfium.dll")]
public static extern int FPDFText_GetSchResultIndex(IntPtr handle);
[DllImport("pdfium.dll")]
public static extern int FPDFText_GetSchCount(IntPtr handle);
[DllImport("pdfium.dll")]
public static extern int FPDFText_GetText(IntPtr page, int start_index, int count, byte[] result);
[DllImport("pdfium.dll")]
public static extern void FPDFText_GetCharBox(IntPtr page, int index, out double left, out double right, out double bottom, out double top);
[DllImport("pdfium.dll")]
public static extern int FPDFText_CountChars(IntPtr page);
[DllImport("pdfium.dll")]
public static extern bool FPDFText_FindNext(IntPtr handle);
[DllImport("pdfium.dll")]
public static extern void FPDFText_FindClose(IntPtr handle);
[DllImport("pdfium.dll")]
public static extern bool FPDFLink_Enumerate(IntPtr page, ref int startPos, out IntPtr linkAnnot);
[DllImport("pdfium.dll")]
public static extern IntPtr FPDFLink_GetDest(IntPtr document, IntPtr link);
[DllImport("pdfium.dll")]
public static extern uint FPDFDest_GetPageIndex(IntPtr document, IntPtr dest);
[DllImport("pdfium.dll")]
public static extern bool FPDFLink_GetAnnotRect(IntPtr linkAnnot, FS_RECTF rect);
[DllImport("pdfium.dll")]
public static extern void FPDF_DeviceToPage(IntPtr page, int start_x, int start_y, int size_x, int size_y, int rotate, int device_x, int device_y, out double page_x, out double page_y);
[DllImport("pdfium.dll")]
public static extern void FPDF_PageToDevice(IntPtr page, int start_x, int start_y, int size_x, int size_y, int rotate, double page_x, double page_y, out int device_x, out int device_y);
[DllImport("pdfium.dll")]
public static extern IntPtr FPDFLink_GetAction(IntPtr link);
[DllImport("pdfium.dll")]
public static extern uint FPDFAction_GetURIPath(IntPtr document, IntPtr action, StringBuilder buffer, uint buflen);
[DllImport("pdfium.dll")]
public static extern IntPtr FPDFBookmark_GetFirstChild(IntPtr document, IntPtr bookmark);
[DllImport("pdfium.dll")]
public static extern IntPtr FPDFBookmark_GetNextSibling(IntPtr document, IntPtr bookmark);
[DllImport("pdfium.dll")]
public static extern uint FPDFBookmark_GetTitle(IntPtr bookmark, byte[] buffer, uint buflen);
[DllImport("pdfium.dll")]
public static extern IntPtr FPDFBookmark_GetAction(IntPtr bookmark);
[DllImport("pdfium.dll")]
public static extern IntPtr FPDFBookmark_GetDest(IntPtr document, IntPtr bookmark);
[DllImport("pdfium.dll")]
public static extern uint FPDFAction_GetType(IntPtr action);
[DllImport("pdfium.dll")]
public static extern uint FPDF_GetLastError();
[DllImport("pdfium.dll")]
public static extern uint FPDF_GetMetaText(IntPtr document, string tag, byte[] buffer, uint buflen);
#region Save/Edit APIs
[DllImport("pdfium.dll")]
public static extern bool FPDF_ImportPages(IntPtr destDoc, IntPtr srcDoc, [MarshalAs(UnmanagedType.LPStr)]string pageRange, int index);
[DllImport("pdfium.dll")]
public static extern bool FPDF_SaveAsCopy(IntPtr doc,
[MarshalAs(UnmanagedType.LPStruct)]FPDF_FILEWRITE writer,
[MarshalAs(UnmanagedType.I4)]FPDF_SAVE_FLAGS flag);
[DllImport("pdfium.dll")]
public static extern bool FPDF_SaveWithVersion(IntPtr doc,
[MarshalAs(UnmanagedType.LPStruct)]FPDF_FILEWRITE writer,
[MarshalAs(UnmanagedType.I4)]FPDF_SAVE_FLAGS flags,
int fileVersion);
[DllImport("pdfium.dll")]
public static extern IntPtr FPDFPage_New(IntPtr doc, int index, double width, double height);
[DllImport("pdfium.dll")]
public static extern void FPDFPage_Delete(IntPtr doc, int index);
[DllImport("pdfium.dll")]
public static extern int FPDFPage_GetRotation(IntPtr page);
[DllImport("pdfium.dll")]
public static extern void FPDFPage_SetRotation(IntPtr page, int rotate);
[DllImport("pdfium.dll")]
public static extern IntPtr FPDF_CreateNewDocument();
[DllImport("pdfium.dll")]
public static extern IntPtr FPDFPageObj_NewImgeObj(IntPtr document);
[DllImport("pdfium.dll")]
public static extern bool FPDFImageObj_SetBitmap(IntPtr pages, int count, IntPtr imageObject, IntPtr bitmap);
[DllImport("pdfium.dll")]
public static extern void FPDFPageObj_Transform(IntPtr page, double a, double b, double c, double d, double e, double f);
[DllImport("pdfium.dll")]
public static extern void FPDFPage_InsertObject(IntPtr page, IntPtr pageObject);
[DllImport("pdfium.dll")]
public static extern bool FPDFPage_GenerateContent(IntPtr page);
[DllImport("pdfium.dll")]
public static extern void FPDF_FFLDraw(IntPtr form, IntPtr bitmap, IntPtr page, int start_x, int start_y, int size_x, int size_y, int rotate, FPDF flags);
#endregion
}
[StructLayout(LayoutKind.Sequential)]
public class FPDF_FORMFILLINFO
{
public int version;
private IntPtr Release;
private IntPtr FFI_Invalidate;
private IntPtr FFI_OutputSelectedRect;
private IntPtr FFI_SetCursor;
private IntPtr FFI_SetTimer;
private IntPtr FFI_KillTimer;
private IntPtr FFI_GetLocalTime;
private IntPtr FFI_OnChange;
private IntPtr FFI_GetPage;
private IntPtr FFI_GetCurrentPage;
private IntPtr FFI_GetRotation;
private IntPtr FFI_ExecuteNamedAction;
private IntPtr FFI_SetTextFieldFocus;
private IntPtr FFI_DoURIAction;
private IntPtr FFI_DoGoToAction;
private IntPtr m_pJsPlatform;
// XFA support i.e. version 2
private IntPtr FFI_DisplayCaret;
private IntPtr FFI_GetCurrentPageIndex;
private IntPtr FFI_SetCurrentPage;
private IntPtr FFI_GotoURL;
private IntPtr FFI_GetPageViewRect;
private IntPtr FFI_PageEvent;
private IntPtr FFI_PopupMenu;
private IntPtr FFI_OpenFile;
private IntPtr FFI_EmailTo;
private IntPtr FFI_UploadTo;
private IntPtr FFI_GetPlatform;
private IntPtr FFI_GetLanguage;
private IntPtr FFI_DownloadFromURL;
private IntPtr FFI_PostRequestURL;
private IntPtr FFI_PutRequestURL;
}
public enum FPDF_UNSP
{
DOC_XFAFORM = 1,