PdfJavaStriper

Hello I am trying to use PdfJavaScriptStripper and get the following error.
Code:
PdfJavaScriptStripper jsStriper = new PdfJavaScriptStripper();
InputStream targetStream = new FileInputStream(f);
OutputStream os = new FileOutputStream(f.getAbsolutePath());
stripSucess = jsStriper.strip(targetStream, os);
File f is a pdf file and I want to remove the js and save it to the same location.
The output is:
" class com.aspose.pdf.exceptions.InvalidPdfFileFormatException: Incorect file format"

  1. How to solve this issue?
  2. Do you have simpler way to remove all Js
  3. How can I check if a document has JS

@ManInABox

Such exception is thrown in case of corrupted stream or different file format than the .pdf. Would you kindly share your sample PDF document with us so that we can test the scenario in our environment and address it accordingly.

Furthermore, API offers only above method to strip the JavaScript from PDF document. You can further check Document.getJavaScript().getKeys().size() to determine if JavaScript is present or not.

Thanks for the answer.
I found the issue, the problem I used the same path for in/out streams.
I think this class should be a function in the PDF.Document and not as a separated functionality.
I can see that the input size of the file increase compared to the original. Why is that ? I would assume if I remove data the size will be lower. I can send you an example in email.
Thanks!

@ManInABox

You may please share your sample PDF document along with used sample code snippet. We will test the scenario in our environment and address it accordingly. It is not necessary to send an email, but you can send it by attaching with your post in this forum thread.