Ask a Question

PDF content decode

danmit
Occasional Contributor

PDF content decode

Hello community! 

 

Is there a way to decode the pdf content file that comes as a response from the API? 

Did a groovy script on asserting the file presence and size but need to add  an assertion for the content of the file also.

4 REPLIES 4
richie
Community Hero

Hey @danmit,

I'm responding to this cos no one else has yet.

I've had a look around for literature on using groovy or java to decode a pdf and i haven't found anything....everything seems to point to progressing a base64 encode to pdf.

I'm sure you CAN do it, but i can't with my knowledge of groovy/java. Perhaps one of the java experts on this thing can be of more help?

However, with my "Test Architect" hat on, i'd argue against trying to decode the pdf anyway. As you know the pdf is an image, but if you've asserted on filesize down to the specific byte size, i'd suggest it's overkill to even bother trying the decode, as even a single different character in the file would cause a byte size differential, surely?

That's all i got i'm afraid!

Cheers,

Rich
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
KarelHusa
Super Contributor

@danmit,

why do you need to decode the PDF? What is the content type (encoding) of the response?

 

Or, do you get a plain PDF and need to extract and check the PDF content (e.g., texts) in your tests?

 

Best regards,

Karel

 

Karel@apimate.eu
https://apimate.eu
danmit
Occasional Contributor

The API response contains a PDF file. The file contains a table with data gathered from several tables from the database. The need for a decode is sustained by the fact that the request send some parameters (eg: "roleCode": "<int>" and a date period.) and the response file contains the information needed. In order to validate the complete test, the file must be checked for the correct data corresponding to the certain parameter combination.

KarelHusa
Super Contributor

If you need to extract text from a PDF, you can use the PDFBox library.

Here's an example of how to use PDFBox.

 

Alternatively, you can use the iTextPdf library.

 

 

Karel@apimate.eu
https://apimate.eu
cancel
Showing results for 
Search instead for 
Did you mean: