Hi,
We are developping a web application which generates some pdf.
We wrote some “unit test” and it works well.
When we call the service in charge of generating the pdf inside a web application (on a jetty server) we have some difficulties: the image creation does not work.
Could you please provide a sample of how to create an image in the pdf when the png file are packaged in a jar ?
We tried to use something like that, is it the good way ?
Image image = new Image();
URL resource = PDFImage.class.getClassLoader().getResource(IMAGES_DIRECTORY + imageName);
File file = new File(resource.toURI());
FileInputStream
fileInputStream = new FileInputStream(file);
image.setImageScale(0.35F);
image.getImageInfo().setImageStream(fileInputStream);
image.getImageInfo().setImageFileType(ImageFileType.Png);
Thanks,
Hello Jean,
Thanks for using our products.
We are working over this query and will get back to you soon. We apologize for your inconvenience.
Hi,
I have the same problem with the font. I have to set a filename: textInfo.setTruetypeFontFileName(font.getFileName());
But how can i do that when my font is inside a jar ?
Do i have to tell my web app to load resources from a directory on the server? Can t I load resources from my war ??
The company work for has purchased a licence for aspose total. Is there any other technical support than this forum ? Is there another support level (if my company pays more $$ ?)
Thanks,
jbcazaux:
When we call the service in charge of generating the pdf inside a web application (on a jetty server) we have some difficulties: the image creation does not work.
Hello Jean,
Can you please share some details regarding the issue that you are facing ?
jbcazaux:
Could you please provide a sample of how to create an image in the pdf when the png file are packaged in a jar ?
We tried to use something like that, is it the good way ?
Image image = new Image();
URL resource = PDFImage.class.getClassLoader().getResource(IMAGES_DIRECTORY + imageName);
File file = new File(resource.toURI());
FileInputStream
fileInputStream = new FileInputStream(file);
image.setImageScale(0.35F);
image.getImageInfo().setImageStream(fileInputStream);
image.getImageInfo().setImageFileType(ImageFileType.Png);
You may also load Image file from jar file as URL imageURL = JARFILENAME.class.getResource("IMAGE.PNG");
simply replace the colored parts to your own stuff.
Please note that there is another option to load the image file contents into BufferedImage object and then pass this object as an argument to Image.ImageInfo.setSysImageStream(image); method but I am afraid the current release version is causing some issues when using setSysImageStream method. For the sake of correction, I have logged this problem as PDFJAVA-33122 in our issue tracking system. We will further look into the details of this problem and will keep you updated on the status of correction. We apologize for your inconvenience.
[Java]
java.awt.image.BufferedImage image = javax.imageio.ImageIO.read(getClass().getResource("imageName.jpg"));
Pdf pdf1 = new Pdf();
Section sec1 = pdf1.getSections().add();
aspose.pdf.Image image1 = new aspose.pdf.Image(sec1);
sec1.getParagraphs().add(image1);
image1.getImageInfo().setSysImageStream(image);
image1.getImageInfo().setImageFileType(aspose.pdf.ImageFileType.Png);
pdf1.save("d:\\pdftest\\axa_logo (1)-converted.pdf");
The issues you have found earlier (filed as PDFJAVA-33122) have been fixed in Aspose.Pdf for Java 3.2.0.
This message was posted using Notification2Forum from Downloads module by aspose.notifier.