So, I am intend to use pdf2json to test my pdf generator service within cucumberjs. When I read the expected pdf from file I can parse the PDF. No problem. When I obtain the generated pdf from the service, it is not possible to parse the PDF.
After some investigation I found the problem. The Buffer returned for the file has the same amount of bytes allocated as the number of bytes in the PDF. The Buffer created by the request lib to download the PDF from the service is larger then the number of bytes put into it. This seems to be a problem for pdf2json or the underlaying pdf parser:
{ parserError: 'An error occurred while parsing the PDF: bad XRef entry' }).
So, I am intend to use pdf2json to test my pdf generator service within cucumberjs. When I read the expected pdf from file I can parse the PDF. No problem. When I obtain the generated pdf from the service, it is not possible to parse the PDF. After some investigation I found the problem. The Buffer returned for the file has the same amount of bytes allocated as the number of bytes in the PDF. The Buffer created by the request lib to download the PDF from the service is larger then the number of bytes put into it. This seems to be a problem for pdf2json or the underlaying pdf parser:
For file pdf:
For downloaded pdf:
I work around this problem by creating a new buffer of the correct length and copying the data into it. Then it works.
It seems to me that the buffer is parsed too far...