I have pdf file without xref table, this pdf was generated by 3d side service
Is any library\solution to fix this pdf file without open it in adobe acrobat? the error is Unable to find xref table
I have pdf file without xref table, this pdf was generated by 3d side service
Is any library\solution to fix this pdf file without open it in adobe acrobat? the error is Unable to find xref table
Creating an xref table for a pdf that never had any shouldn't be too hard (unlikely to involve linearization or incremental saves), so you have to wonder at the quality of the PDF that was generated by that PDF Producer.
Get a copy of the PDF (v1.7) Reference; the sections you'll need to reference are 3.2.9, and 3.4 (3.4.3 and 3.4.4 in particular), and open up your file in a hex editor.
Scroll to the very bottom of the file. The file should end with "%%EOF"; immediately preceding that should be 'startxref'[\r\n] followed by a number which is the byte offset for the start of the 'xref' section. Based on your error message, this number is likely missing or off. The xref section is usually after the last endobj but above the trailer section which itself is above the startxref section. You will want to keep a copy of the trailer to tack back on after you have written out the 'xref' section.
To create the xref section, you need to scan the body of the PDF for lines consisting of: IDNumber GenNumber 'obj'\r\n. In the simplest case, GenNumber will always be 0, and IDNumber will always be increasing in sequential order as you move from top to bottom. (If GenNumber is ever not zero, then you are dealing with a file that has been incrementally saved; that's a complication you dont want to deal with). Keep track of the offsets of each of those lines along with the IDNumber and GenNumber. write out a first line in the xref consisting of the first IDNumber and the number of indirect objects found (assuming that they are all in sequential order). Then, for each indirect object write out the offset (padded to 10 digits), space, GenNumber (00000), space,'n', eol (\r\n). Afterwards, tack on the trailer that was saved earlier, and the startxref section, and the '%%EOF' line. Save your file, and see if that fixes the problem for the file.
Having inspected the file provided by the OP it turns out that the base problem is not a missing cross reference table. Instead the problem ultimately is that the file in fact is a combination of two complete PDF files, the first one 93863 bytes in size and the second one 112857 bytes.
Both show the same form, the only difference being that the second one has six QR codes added at the bottom.
Probably someone attempted to merge the two PDFs (which simply doesn't work this way), or maybe it happened completely accidentally.
Thus, what the OP actually needs is a tool to split the file after 93863 bytes, right before the %PDF-1.4
file header there.
If you wonder why some program claimed Unable to find xref table
- at the end of a PDF there are lines like this:
startxref
111945
%%EOF
The number indicates at which offset counted from the start of the file the cross references are located.
Thus, if you have a file in which there are two PDFs in a row, this offset is falsified (as the offset is counted from the very start of the file) and points into the file where there are no cross references now.
Some programs in such a situation attempt to repair the file, reconstructing a cross reference table, while others fail with an error. Adobe Reader is of the former type and the program the OP tried to run of the latter.
maybe:
You could fix it yourself if you are (very!) familiar with the PDF format :) PDF is internally text.. well, except the streams and embedded objects
The provider of the PDF is an HP product (device)