Free Support Forum - aspose.com

Com.aspose.pdf.elements

Hello there,
I am trying out aspose products and
I installed all the neccessary Jar files but somehow
I want to use the class -
"com.aspose.pdf.elements.Pdf"
but I cant find it anywhere

Can soneone tell where to find it ?

greetings,
Bernard.

Hello Bernard,

Thanks for using our products.

Aspose.Pdf for Java is more consistent with Aspose.Pdf for .NET so in order to access the objects/elements inside its API, you don’t need to refer them using com.aspose.pdf statement. You can directly access object with class name. The approach has been changed since the release of Aspose.Pdf for Java 2.5.0. Please take a look over the following code snippet which I have created a simple HelloWorld PDF document.

[Java]

// create PDF document instance
Pdf pdf = new Pdf();
// create section and add it to PDF object
Section section = pdf.getSections().add();
// create sample text paragraph
Text SampleText = new Text("Hello World");
// add the Text paragraph to section
section.getParagraphs().add(SampleText);
// save the resultant PDF
pdf.save("d:/pdftest/HelloWorld_Test.pdf");

I would also recommend you to please have a look over following link for better understanding on Migrating your code to Aspose.Pdf for Java 2.5.0. In case you still face any problem or you have any further query, please feel free to contact. We apologize for your inconvenience.

Hi,

I’m having the same issue here. Downloaded aspose-pdf-2.9.0-java.zip.

Tried to compile an example:
aspose-pdf-2.9.0-java> javac -classpath=/lib/aspose-pdf-2.9.0-jdk16.jar samples/demos/image/ImageExample.java

Got a bunch of errors, saying the compiler can’t find the Pdf, Section, Text etc. classes. They are mentioned in the import statements. I went to check the jar and indeed the classes are missing.

Help?

Hi,

I’m trying out Aspose pdf for java. Downloaded aspose-pdf-2.9.0-java.zip.

Tried to compile an example:
aspose-pdf-2.9.0-java> javac -classpath=/lib/aspose-pdf-2.9.0-jdk16.jar samples/demos/image/ImageExample.java

Got a bunch of errors, saying the compiler can’t find the Pdf, Section, Text etc. classes. They are mentioned in the import statements. I went to check the jar and indeed the classes are missing.

Help?

Hello,


just change your command line to
javac -classpath /lib/aspose-pdf-2.9.0-jdk16.jar samples/demos/image/ImageExample.java

Java compiler does not support GNU getopt style.

Hi,

Thanks for using our products and sorry for replying you late.

The issue is occurring because the demos are referencing old version of Aspose.Pdf for Java. In order to use the latest release version, please update the product reference information as following

import com.aspose.pdf.elements.*;
import com.aspose.pdf.exception.AsposeBaseException;

from above code line, remove second line and update the first code line as import aspose.pdf.*;

More along, update pdf.save(new FileOutputStream(new File("exampleOutput/ImageExample.pdf"))); to pdf.save("D:\\pdftest\\SampleDataSmall.pdf");

We are working on activity to update Aspose.Pdf for Java demos in order to make them compatible with latest release version. In case you still face any problem or you have any further query, please feel free to contact. We apologize for your inconvenience.

I would also suggest you to please visit the following link for related information on

Hi, thanks for your reply. I was able to compile the class at last. By the way, I had to change the package reference to samples.demos.image, and remove the catch(AsposeBaseException e) block as well.

Anyway, now when I try to run the compiled class, I'm getting the following error:

C:\workspace\aspose-pdf-2.9.0-java>java samples.demos.image.ImageExample
Exception in thread "main" java.lang.NoClassDefFoundError: aspose/pdf/Paragraph
Caused by: java.lang.ClassNotFoundException: aspose.pdf.Paragraph
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: samples.demos.image.ImageExample. Program will e
xit.

What's wrong this time?

Wouldn't it be easier to fix your documentation and examples once instead of replying to numerous posts? By the way, both links that you mentioned lead to:

Unexpected Error

An unexpected error has occurred while we were trying to fetch your desired resource. We apologize for the inconvenience. An email has been sent to the webmaster with the error details.

Hello Bernard,

Please download the updated demos which are fully compatible with latest relaese version of Aspose.Pdf for Java 2.9.0 from Aspose.Pdf for Java Demos. Please try uisng them and in case you encounter any issue or you have any further query, please feel free to contact. We apologize for your inconvenience.

Sorry, same error.

I suggest you check the exmples before posting them. Because I had to fix the package name and the references again according to the directory structure.

Hello Bernard,

I have again double checked and have updated the Packages names (wherever required) and also the information inside Readme is updated. In you are executing the demos from Command Prompt, please notice that $JAVA_HOME is the directory where JDK is installed and please comment out the code line in which package is referenced. You should be able to generate the PDF from these demos.

I have used the same copy and have executed couple of demos and as per my observations, the PDF documents are properly being generated. More along concerning to broken link towards documentation, I am afraid currently it seems to be an issue with the Live server which is generating UnExpected Error. I would request you to please try accessing these links in few moments. We are really sorry for this inconvenience.

Thanks again for your time.

By the way, you can safely remove the reference to JAVA_HOME from your Readme. Copying files into \bin folder inside JAVA_HOME doesn't make any sense. It works from any dir:

C:\AAAAA>javac -classpath .;aspose-pdf-2.9.0-jdk16.jar ImageExample.java

C:\AAAAA>java -classpath .;aspose-pdf-2.9.0-jdk16.jar ImageExample

Hello Bernard,

Thanks for sharing the information. Yes you are correct. .Java code file can be compiled and executed from any directory over the system. However in readme.txt, we thought to share the information so that even a novice can easily execute the code (without getting confused in defining .jar path and other information). However, we will consider updating this file as per suggestion.