@@ -82,6 +82,9 @@ public class PdfReader implements Closeable, Serializable {
82
82
//indicate nearest first Indirect reference object which includes current reading the object, using for PdfString decrypt
83
83
private PdfIndirectReference currentIndirectReference ;
84
84
85
+ // For internal usage only
86
+ private String sourcePath ;
87
+
85
88
protected PdfTokenizer tokens ;
86
89
protected PdfEncryption decrypt ;
87
90
@@ -102,7 +105,6 @@ public class PdfReader implements Closeable, Serializable {
102
105
protected boolean fixedXref = false ;
103
106
protected boolean xrefStm = false ;
104
107
105
-
106
108
/**
107
109
* Constructs a new PdfReader.
108
110
*
@@ -153,7 +155,7 @@ public PdfReader(String filename, ReaderProperties properties) throws IOExceptio
153
155
.createBestSource (filename ),
154
156
properties
155
157
);
156
-
158
+ this . sourcePath = filename ;
157
159
}
158
160
159
161
/**
@@ -1099,6 +1101,30 @@ private void checkPdfStreamLength(PdfStream pdfStream) throws IOException {
1099
1101
}
1100
1102
}
1101
1103
1104
+ /**
1105
+ * This method is invoked while deserialization
1106
+ */
1107
+ private void readObject (java .io .ObjectInputStream in ) throws java .io .IOException , ClassNotFoundException {
1108
+ in .defaultReadObject ();
1109
+ if (sourcePath != null && tokens == null ) {
1110
+ tokens = getOffsetTokeniser (new RandomAccessSourceFactory ().setForceRead (false ).createBestSource (sourcePath ));
1111
+ }
1112
+ }
1113
+
1114
+ /**
1115
+ * This method is invoked while serialization
1116
+ */
1117
+ private void writeObject (java .io .ObjectOutputStream out ) throws java .io .IOException {
1118
+ if (sourcePath != null ) {
1119
+ PdfTokenizer tempTokens = tokens ;
1120
+ tokens = null ;
1121
+ out .defaultWriteObject ();
1122
+ tokens = tempTokens ;
1123
+ } else {
1124
+ out .defaultWriteObject ();
1125
+ }
1126
+ }
1127
+
1102
1128
protected static class ReusableRandomAccessSource implements IRandomAccessSource {
1103
1129
private ByteBuffer buffer ;
1104
1130
0 commit comments