40
40
using PdfSharpCore . Internal ;
41
41
using PdfSharpCore . Pdf ;
42
42
using PdfSharpCore . Pdf . IO ;
43
+ using PdfSharpCore . Pdf . IO . enums ;
43
44
44
45
namespace PdfSharpCore . Drawing
45
46
{
@@ -59,7 +60,7 @@ public class XPdfForm : XForm
59
60
/// document. Furthermore, because XPdfForm can occupy very much memory, it is recommended to
60
61
/// dispose XPdfForm objects if not needed anymore.
61
62
/// </summary>
62
- internal XPdfForm ( string path )
63
+ internal XPdfForm ( string path , PdfReadAccuracy accuracy )
63
64
{
64
65
int pageNumber ;
65
66
path = ExtractPageNumber ( path , out pageNumber ) ;
@@ -74,6 +75,7 @@ internal XPdfForm(string path)
74
75
throw new ArgumentException ( "The specified file has no valid PDF file header." , "path" ) ;
75
76
76
77
_path = path ;
78
+ _pathReadAccuracy = accuracy ;
77
79
if ( pageNumber != 0 )
78
80
PageNumber = pageNumber ;
79
81
}
@@ -82,54 +84,79 @@ internal XPdfForm(string path)
82
84
/// Initializes a new instance of the <see cref="XPdfForm"/> class from a stream.
83
85
/// </summary>
84
86
/// <param name="stream">The stream.</param>
85
- internal XPdfForm ( Stream stream )
87
+ /// <param name="accuracy">Moderate allows for broken references.</param>
88
+ internal XPdfForm ( Stream stream , PdfReadAccuracy accuracy )
86
89
{
87
90
// Create a dummy unique path
88
91
_path = "*" + Guid . NewGuid ( ) . ToString ( "B" ) ;
89
92
90
93
if ( PdfReader . TestPdfFile ( stream ) == 0 )
91
94
throw new ArgumentException ( "The specified stream has no valid PDF file header." , "stream" ) ;
92
95
93
- _externalDocument = PdfReader . Open ( stream ) ;
96
+ _externalDocument = PdfReader . Open ( stream , accuracy ) ;
94
97
}
95
98
96
99
/// <summary>
97
100
/// Initializes a new instance of the <see cref="XPdfForm"/> class from a stream and password.
98
101
/// </summary>
99
102
/// <param name="stream">The stream.</param>
100
103
/// <param name="password">The password.</param>
101
- internal XPdfForm ( Stream stream , string password ) {
104
+ /// <param name="accuracy">Moderate allows for broken references.</param>
105
+ internal XPdfForm ( Stream stream , string password , PdfReadAccuracy accuracy ) {
102
106
// Create a dummy unique path
103
107
_path = "*" + Guid . NewGuid ( ) . ToString ( "B" ) ;
104
108
105
109
if ( PdfReader . TestPdfFile ( stream ) == 0 )
106
110
throw new ArgumentException ( "The specified stream has no valid PDF file header." , "stream" ) ;
107
111
108
- _externalDocument = PdfReader . Open ( stream , password , PdfDocumentOpenMode . ReadOnly ) ;
112
+ _externalDocument = PdfReader . Open ( stream , password , PdfDocumentOpenMode . ReadOnly , accuracy ) ;
109
113
}
110
114
111
115
/// <summary>
112
116
/// Creates an XPdfForm from a file.
113
117
/// </summary>
114
118
public static new XPdfForm FromFile ( string path )
119
+ {
120
+ return FromFile ( path , PdfReadAccuracy . Strict ) ;
121
+ }
122
+
123
+ /// <summary>
124
+ /// Creates an XPdfForm from a file.
125
+ /// </summary>
126
+ public static new XPdfForm FromFile ( string path , PdfReadAccuracy accuracy )
115
127
{
116
128
// TODO: Same file should return same object (that's why the function is static).
117
- return new XPdfForm ( path ) ;
129
+ return new XPdfForm ( path , accuracy ) ;
118
130
}
119
131
120
132
/// <summary>
121
133
/// Creates an XPdfForm from a stream.
122
134
/// </summary>
123
135
public static XPdfForm FromStream ( Stream stream )
124
136
{
125
- return new XPdfForm ( stream ) ;
137
+ return FromStream ( stream , PdfReadAccuracy . Strict ) ;
138
+ }
139
+
140
+ /// <summary>
141
+ /// Creates an XPdfForm from a stream.
142
+ /// </summary>
143
+ public static XPdfForm FromStream ( Stream stream , PdfReadAccuracy accuracy )
144
+ {
145
+ return new XPdfForm ( stream , accuracy ) ;
126
146
}
127
147
128
148
/// <summary>
129
149
/// Creates an XPdfForm from a stream and a password.
130
150
/// </summary>
131
151
public static XPdfForm FromStream ( Stream stream , string password ) {
132
- return new XPdfForm ( stream , password ) ;
152
+ return FromStream ( stream , password , PdfReadAccuracy . Strict ) ;
153
+ }
154
+
155
+ /// <summary>
156
+ /// Creates an XPdfForm from a stream and a password.
157
+ /// </summary>
158
+ public static XPdfForm FromStream ( Stream stream , string password , PdfReadAccuracy accuracy ) {
159
+ return new XPdfForm ( stream , password , accuracy ) ;
133
160
}
134
161
135
162
/*
@@ -370,12 +397,14 @@ internal PdfDocument ExternalDocument
370
397
throw new InvalidOperationException ( "This XPdfForm is a template and not an imported PDF page; therefore it has no external document." ) ;
371
398
372
399
if ( _externalDocument == null )
373
- _externalDocument = PdfDocument . Tls . GetDocument ( _path ) ;
400
+ _externalDocument = PdfDocument . Tls . GetDocument ( _path , _pathReadAccuracy ) ;
374
401
return _externalDocument ;
375
402
}
376
403
}
377
404
internal PdfDocument _externalDocument ;
378
405
406
+ private PdfReadAccuracy _pathReadAccuracy ;
407
+
379
408
/// <summary>
380
409
/// Extracts the page number if the path has the form 'MyFile.pdf#123' and returns
381
410
/// the actual path without the number sign and the following digits.
0 commit comments