Not Able to Read PDF Page Created by ASPOSE or Other Sources

Here is my code to create the PDF (based on aspose sample) and PDF (1page) created no issue.

//Instantiate License class and call its SetLicense method to use the license

aspose.pdf.License lic = new aspose.pdf.License();

lic.setLicense(new FileInputStream(new File("C:/work2013/app/aspose/test/data/Aspose.Total.Java.lic")));

//Create PDF document

Pdf pdf1 = new Pdf();

//Add a section into the PDF document

Section sec1 = pdf1.getSections().add();

//Add a text paragraph into the section

sec1.getParagraphs().add(new Text("Hello World"));

pdf1.setPagesNumber(1);

//Save the document

pdf1.save("HelloWorld.pdf");

///////////////////////////////

Then to read the PDF (based on sample from ASPOSE)

com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document("HelloWorld.pdf");

com.aspose.pdf.DocumentInfo docInfo = pdfDocument.getInfo();

//show document information

System.out.printf("Author:-" + docInfo.getAuthor());

System.out.printf("\n Creation Date:-" + docInfo.getCreationDate());

System.out.printf("\n Keywords:-" + docInfo.getKeywords());

System.out.printf("\n Modify Date:-" + docInfo.getModDate());

System.out.printf("\n Subject:-" + docInfo.getSubject());

System.out.printf("\n Title:-" + docInfo.getTitle());

//get the page where image needs to be added

if(pdfDocument.getPages()!=null)

{

com.aspose.pdf.Page page = pdfDocument.getPages().get_Item(1);

// No issue until here with Java null exception

Exception in thread "main" java.lang.NullPointerException

at com.aspose.pdf.engine.d.a.e.a.a.a(Unknown Source)

at com.aspose.pdf.engine.d.a.e.a.c.b(Unknown Source)

at com.aspose.pdf.engine.d.a.e.a.d.a(Unknown Source)

at com.aspose.pdf.engine.d.a.e.a.c.a(Unknown Source)

at com.aspose.pdf.engine.d.a.e.a.f.b(Unknown Source)

at com.aspose.pdf.engine.d.a.e.a.k.a(Unknown Source)

at com.aspose.ms.System.d.c.a(Unknown Source)

at com.aspose.pdf.engine.d.a.e.a.a(Unknown Source)

at com.aspose.pdf.engine.data.types.PdfStreamAccessor.getDecodedData(Unknown Source)

at com.aspose.pdf.engine.commondata.d.a.o(Unknown Source)

at com.aspose.pdf.engine.commondata.d.a.(Unknown Source)

at com.aspose.pdf.engine.c.a.a(Unknown Source)

at com.aspose.pdf.engine.commondata.w.b(Unknown Source)

at com.aspose.pdf.Page.(Unknown Source)

at com.aspose.pdf.PageCollection.a(Unknown Source)

at com.aspose.pdf.PageCollection.get_Item(Unknown Source)

at BarcodeReaderTest.main(BarcodeReaderTest.java:98)

}

Why ASPOSE can't read the same PDF created by itself? Am I missing any setting to the call?

Tahnk you if anyone can answer my question. Thanks.

Hi,


Thanks for using our products.

I have tested the scenario using Aspose.Pdf for Java 4.0.0 in a sample project created in Eclipse IDE running over Windows 7 (X64) where I have jdk1.7.0_10 installed over my system and I am unable to notice any issue when reading the PDF file created with same component. For your reference, I have also attached the resultant PDF file which I am trying to read. Can you please share the PDF file which is generated over your end and also please share some details regarding your working environment.

We are sorry for your inconvenience.

  1. I attached my HelloWorld.failed.pdf created from my program posted 2 days ago here.

    If you “run” my program, it will create / read the PDF no issue. What I found is that, when you “debug” the Java program, it will fail at,

    com.aspose.pdf.Page page = pdfDocument.getPages().get_Item(1);
    with

    Exception in thread “main” java.lang.NullPointerException
    at com.aspose.pdf.engine.d.a.e.a.a.a(Unknown Source)
    at com.aspose.pdf.engine.d.a.e.a.c.b(Unknown Source)
    at com.aspose.pdf.engine.d.a.e.a.d.a(Unknown Source)
    at com.aspose.pdf.engine.d.a.e.a.c.a(Unknown Source)
    at com.aspose.pdf.engine.d.a.e.a.f.b(Unknown Source)
    at com.aspose.pdf.engine.d.a.e.a.k.a(Unknown Source)
    at com.aspose.ms.System.d.c.a(Unknown Source)
    at com.aspose.pdf.engine.d.a.e.a.a(Unknown Source)
    at com.aspose.pdf.engine.data.types.PdfStreamAccessor.getDecodedData(Unknown Source)
    at com.aspose.pdf.engine.commondata.d.a.o(Unknown Source)
    at com.aspose.pdf.engine.commondata.d.a.(Unknown Source)
    at com.aspose.pdf.engine.c.a.a(Unknown Source)
    at com.aspose.pdf.engine.commondata.w.b(Unknown Source)
    at com.aspose.pdf.Page.(Unknown Source)
    at com.aspose.pdf.PageCollection.a(Unknown Source)
    at com.aspose.pdf.PageCollection.get_Item(Unknown Source)
    at BarcodeReaderTest.main(BarcodeReaderTest.java:101)

    even though it is a good PDF file opened by Adope PDF viewer.

    2) So I proceed with only “run” the java program not “debug” in eclipse. I am using Windows 7 Professional 64-bit, Eclispe 3.6.2 JRE 1.6 which bundled with IBM Integration Designer 7.5.1.1.

    In other words, you can’t debug “open” PDF file (at a page) created by ASPOSE. Ok during the “Run” mode.

    Thanks.

Hi there,


Thanks for providing your source document. I’m afraid I’m unable to notice issue even in debug mode. Can you please share your complete sample code here? So we test it at our side and provide you more information.

Sorry for the inconvenienced faced.

Best Regards,

My complete code is attached here. In the 2nd part, I open the Hello.pdf (attached also) and modify/save the file. In the 3rd part, I tried to open this saved PDF file and read page-by-page and get exceptions.

The code ok in WebSphere “Run” mode. But throw unknown exception in “Debug” mode. So I just have to run instead of debug it all the time. It is JDK1.6 and Eclipse 3.6.2. Thanks.

Hi there,


I’m afraid the code attachment is missing. Can you please re-attach the code here? Moreover your shared exception included Barcodereader(), Are you using Aspose.Barcode as well or it is some customer method.

Sorry for the inconvenience faced.

Best Regards,