PDF header signature error

Our company has purchased Aspose Total, and our business unit is evaluating aspose pdf kit.

I am trying to extract a number of single pages from a multipage pdf.

I am using the following method from class PdfEditor:

extract(java.io.InputStream inputStream, int[] pageNumber, java.io.OutputStream outputStream)

Extracts pages specified by number array, saves as a new Pdf file

I receive our images as a byte[] and need to convert this to a InputStream.

If I use the InputStream generated from the bytearray, I get the error listed below. If I create an InputStream from a file it works.

I can use the same code, bytearray to InputStream, to concat multiple single page pdf’s and it work fine.

Versions:

  • aspose-pdf-kit-4.5.0
  • java jdk 1.6
  • commons-io-2.4 (bytearray to InputStream)

Error:

java.io.IOException: PDF header signature error.
    at com.aspose.pdf.kit.lf.k(Unknown Source)
    at com.aspose.pdf.kit.oq.a(Unknown Source)
    at com.aspose.pdf.kit.oq.<init>(Unknown Source)
    at com.aspose.pdf.kit.oq.<init>(Unknown Source)
    at com.aspose.pdf.kit.PdfFileEditor.extract(Unknown Source)
    at za.co.fnb.ecm.image.pdf.util.PDFUtil.extract(PdfUtil.java:326)
    at za.co.fnb.ecm.image.test.TestPDFUtil.testExtract(TestPDFUtil.java:330)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

[[strong>Zirk said:]

Our company has purchased Aspose Total, and our business unit is evaluating aspose pdf kit.

I am trying to extract a number of single pages from a multipage pdf.

I am using the following method form class PDfEditor.

[extract](file:///D:/Classification/Workspace/Docs/Aspose/pdf/doc/com/aspose/pdf/kit/PdfFileEditor.html#extract(java.io.InputStream, int[], java.io.OutputStream))(InputStream inputStream, int[] pageNumber, OutputStream outputStream).

Extracts pages specified by number array, saves as a new Pdf file.

I receive our images as a byte[] and need to convert this to a InputStream.

If I use the InputStream generated from the bytearray, I get the error listed below. If I create an InputStream form a file it works.

Hi Zirk,
Thanks for using our products.

I am afraid I am unable to understand your above stated point highlighted in yellow. PdfFileEditor class does not accept any image format as input but it only works with a valid PDF file. Furthermore, none of the overload’s of extract(…) method accept bytearray as an argument.

Furthermore, I have tested the scenario using following code snippet and I am unable to notice any issue. Can you please share the code snippet which you are using so that we can test the scenario at our end. We are sorry for your inconvenience.

[Java]

//Initialize the string variables storing paths of PDF files
String inFile = "c:/pdftest/Global_Network_Block_Device.pdf";
String outFile = "c:/pdftest/Extracted_kitOut.pdf";

//Creating an array of integers having numbers of the pages to be extracted from PDF file
int[] pages = new int[] { 1, 2, 4, 10, 100 };
com.aspose.pdf.kit.PdfFileEditor pdfEditor = new com.aspose.pdf.kit.PdfFileEditor();

//Calling Extract method
pdfEditor.extract(new java.io.FileInputStream(inFile), pages, new FileOutputStream(outFile));