Starting from example 1.5, the reference information is stored in the reference stream instead of the reference table. The reference stream improves the following advantages:
More concise and compact representation of reference information.
You can access the compressed objects stored in the object stream (see section 3.4.6, "Object stream"), and allow new objects to be added later.
.
But it also increases the difficulty of parsing data. I will analyze the PDF reference stream below:
Read a sample.pdf (get the start xref address to get firt-page cross-reference)
35 0 OBJ </decodeparms </columns 4/predictor 12>/filter/FlateDecode/ID [<strong> <f929944ec68a3543a18a40f2e7630a9d>]/index [24 23]/INFO 23 0 r/length 61/Prev 12284/root 25 0 r/size 47/type/xref/W [1 2 1]> streamh has BD ''' B '? M role ?, Failed, % failed? $ Release 0012? Endstreamendobj
First, analyze the data:
35 0: indicates that the object number is 35, and 0 indicates the generation number. If you have any questions, you can check the PDF reference.
Filter: indicates the filter category. Here is FlateDecode. We can decompress it using zlib's inflate.
Decodeparms: This mainly indicates the decoding parameter. colunms indicates the number of samples per line. predictor uses PNG filter. In fact, it also involves two parameters: bitspercomponent default value: 8 colors default value: 1
W: indicates that the data field is 1 byte, 2 bytes, and 1 byte respectively.
Now analyze the above data: If you are familiar with PNG Parsing, you can easily understand the following algorithms:
Before: decompress data using zlib
private void DisposeData(byte[] before) { int length = before.Length; int row = length / 5; byte[] after = new byte[length - row]; for (int i = 0; i < row; i++) { for (int j = 0; j < 4; j++) { after[j+4*i]=before[j+1+5*i]; } } for (int i = 1; i < row; i++) { for (int j = 0; j < 4; j++) { after[i * 4 + j] = (byte)(after[i * 4 + j]+after[(i - 1) * 4 + j]); //png filer 2 } } for (int i = 0; i < row; i++) { int w0 = after[0+i*4]; int w1 = after[1 + i * 4]; w1 = w1*256 + after[2 + i * 4]; int w2 = after[3 + i * 4]; } }