Images not displaying in pdf

image just shows in pdf as

aspose.pdf.Im
age@3b475a

I set the type and path as instructed in the documentation. Then I stream it back to the client but the image doesn’t display. instead I get

aspose.pdf.Im
age@3b475a

I am not providing any code because it seems my long posts with code get deleted.

Hi David,


Thanks for your inquiry. I’m afraid I couldn’t understand your issue. Could you please share some more details about your scenario?

Furthermore, we don’t have any restrictions on long posts. Please feel free to share your sample code/ document here.

Best Regards,

I set up my paths to the images like this.


HttpSession session = request.getSession();
String unitOfMeasure = (String) session.getAttribute(“unitOfMeasure”);
Integer projectId = Integer.valueOf(request.getParameter(“projectId”));
ServletContext sc = session.getServletContext();
String basePath = sc.getRealPath("/");
System.out.println(basePath);
Hashtable<String,String> imgH = new Hashtable<String, String>();
imgH.put(“GTS”, basePath + “\resources\images\GTS_humidifier.jpg”);
imgH.put(“VaporStream”, basePath +"\resources\images\VLC cover no Tknobs.jpg");
imgH.put(“XT”, basePath + “\resources\images\XT-VL4.jpg”);
imgH.put(“STS”, basePath + “\resources\images\STS_humidifier.jpg”);
imgH.put(“VaproMist”, basePath + “\resources\images\VM with VL4.jpg”);
imgH.put(“XTS”, basePath + “\resource/images\XTS.jpg”);
imgH.put(“CRUV”, basePath + “\resources\images\CRUV.jpg”);
imgH.put(“Ultra-sorb XV”, basePath + “\resources\images\US-XV.png”);
imgH.put(“Single tube”, basePath + “\resources\images\Single-Dispersion-Tube.png”);
imgH.put(“Ultra-sorb LV”, basePath + “\resources\images\Ultrasorb.png”);
imgH.put(“Mini-Bank”, basePath + “\resources\images\Mini-bank-humidifier.png”);
imgH.put(“Area-type”, basePath + “\resources\images\Area-type.png”);
imgH.put(“Ultra-sorb LH”, basePath + “\resources\images\US-LH.png”);
imgH.put(“Multi tube”, basePath + “\resources\images\Maxi-bank-humidifier.png”);
imgH.put(“Rapid-sorb”, basePath + “\resources\images\Rapidsorb.png”);
imgH.put(“SDU”, basePath + “\resources\images\SDUe.png”);
imgH.put(“Single Dispersion Tube”, basePath + “\resources\images\Single-Dispersion-Tube.png”);

and I use the hashtable as source for the following. adding images to table cells


Table table2 = new Table(sec1);

//Add the table in paragraphs collection of the desired section
sec1.getParagraphs().add(table2);

//Set with column widths of the table
table2.setColumnWidths(“72 72 72 72 72”);
table2.getDefaultCellTextInfo().setAlignment(AlignmentType.Center);

//Set default cell border using BorderInfo object
table2.setDefaultCellBorder(new BorderInfo(BorderSide.All.getValue(), 0.1F));

//Set table border using another customized BorderInfo object
table2.setBorder(new BorderInfo(BorderSide.All.getValue(), 0.5F));

//Create MarginInfo object and set its left, bottom, right and top margins
MarginInfo margin2 = new MarginInfo();
margin2.Left = 0.5f;
margin2.Right = 0.5f;
margin2.Top = 0.5f;
margin2.Bottom = 0.5f;
//Set the default cell padding to the MarginInfo object
table2.setDefaultCellPadding(margin2);
int imageAddedCount = 0;
String uniqueProducts = “”;
row = table2.getRows().add();
for(int j = 0; j< schedList.size(); j++)
{
sched = (Schedule) schedList.get(j);
if(sched.getGenerationProduct() != null && uniqueProducts.indexOf(sched.getGenerationProduct()) < 0)
{
aspose.pdf.Image img = new aspose.pdf.Image();
String imagePath = imgH.get(sched.getGenerationProduct());
if(imagePath.substring(imagePath.indexOf(".") + 1 , imagePath.length()).compareToIgnoreCase(“jpg”) ==0 )
{
// Specify the Image file type as JPEG
img.getImageInfo().setImageFileType(ImageFileType.Jpeg);
}
else if(imagePath.substring(imagePath.indexOf(".") + 1, imagePath.length()).compareToIgnoreCase(“PNG”) == 0)
{
img.getImageInfo().setImageFileType(ImageFileType.Png);
}

//Set the path of image file
img.getImageInfo().setFile(imagePath);
row.getCells().add(sched.getGenerationProduct() + “\n” + img);
uniqueProducts = uniqueProducts + sched.getGenerationProduct();
imageAddedCount++;
}
if(sched.getDispersionProduct() != null && uniqueProducts.indexOf(sched.getDispersionProduct()) < 0)
{
aspose.pdf.Image img1 = new aspose.pdf.Image();
String imagePath = imgH.get(sched.getDispersionProduct());
if(imagePath.substring(imagePath.indexOf(".") + 1 , imagePath.length()).compareToIgnoreCase(“jpg”) ==0 )
{
// Specify the Image file type as JPEG
img1.getImageInfo().setImageFileType(ImageFileType.Jpeg);
}
else if(imagePath.substring(imagePath.indexOf(".") + 1, imagePath.length()).compareToIgnoreCase(“PNG”) == 0)
{
img1.getImageInfo().setImageFileType(ImageFileType.Png);
}

//Set the path of image file
img1.getImageInfo().setFile(imagePath);

row.getCells().add(sched.getDispersionProduct() + “\n” + img1);
uniqueProducts = uniqueProducts + sched.getDispersionProduct();
imageAddedCount++;
}
if(imageAddedCount % 5 == 0)
{
row = table2.getRows().add();
}
}

and I stream back to the client as


ServletOutputStream stream = null;
byte buf1[] = null;
try
{
stream = response.getOutputStream();
response.setContentType(“application/pdf”);
response.addHeader(“Content-Disposition”, “attachment;Filename=schedule.pdf”);
buf1 = pdf1.getBuffer();
response.setContentLength(buf1.length);
int readBytes = 0;
for(int i = 0; i < buf1.length; i++)
{
readBytes = buf1[i];
stream.write(readBytes);
}

}
catch (IOException ioe)
{
throw new ServletException(ioe.getMessage());
} finally
{
if(stream != null)
{
stream.flush();
stream.close();
}
if(buf1 != null)
{
buf1 = null;
}
}

and what appears in my exported pdf table is


aspose.pdf.Im
age@1f2380


in place of the actual image

So I left all that code overnight hoping for a response. But come in this morning to find no response. It is bad enough that I have to wait overnight to get response to my questions, but now no response after overnight even. What I am I doing wrong?

Hi David,


Thanks for sharing the code snippet.

We are working over this query and will get back to you soon. Sorry for the delayed response.

OK I am anxiously awaiting your answers.

Hi David,


Thanks for your patience. I’ve noticed the reported issue and logged it in our issue tracking system as PDFJAVA-33198, for further investigation. We will keep you updated about issue status via this forum thread.

Sorry for the inconveneice faced.

Best Regards,

Does this mean no one has ever tried to do what I am doing? Creating a pdf from scratch and putting images in it?

Hi David,


Sorry for the inconvenience faced. Issues varies case to case due to source files, programming logic and environment. However, we are looking into your issue and will update you as soon it is resolved.

Thanks for your patience and cooperation.

Best Regards,