Hi, we are trying to insert an image into a FloatingBox, but the image renders wrong.
Code:
Image image = new Image();
if (ctx.getBanner().get().getFileName().endsWith(“svg”)) {
image.setFileType(ImageFileType.Svg);
}
image.setImageStream(is);
image.setFixWidth(200);
image.setFixHeight(60);
image.setMargin(new MarginInfo(30, 0, 30, 30));
FloatingBox coverHeaderBox = new FloatingBox(PageInfo.CONTENT_BOX_WIDTH, 120);
coverHeaderBox.getParagraphs().add(image);
Sample output:
image.png (2.9 KB)
Original Image:
Bananas (1).zip (4.4 KB)
@ahashem,
There is an issue there. I run the following code in C#:
private void Logic()
{
Document doc = new Document();
var image = new Aspose.Pdf.Image();
image.File = $"{PartialPath}_input.svg";
image.FixWidth = 300;
image.FixHeight = 200;
image.Margin = new MarginInfo(30, 30, 30, 30);
FloatingBox coverHeaderBox = new FloatingBox(360, 260);
coverHeaderBox.Paragraphs.Add(image);
var page = doc.Pages.Add();
page.Paragraphs.Add(coverHeaderBox);
// Save PDF Document
doc.Save($"{PartialPath}_output.pdf");
}
And it works. Here is the output:
FloatingBoxWithSvgImage_output.pdf (26.9 KB)
Here is the code in java:
public void Logic() throws Exception
{
var doc = new com.aspose.pdf.Document();
var image = new com.aspose.pdf.Image();
//image.setFileType(ImageFileType.Svg);
image.setFile(PartialPath + "_input.svg");
image.setFixWidth(300);
image.setFixWidth(200);
image.setMargin(new MarginInfo(30, 30, 30, 30));
FloatingBox coverHeaderBox = new FloatingBox(330, 230);
coverHeaderBox.getParagraphs().add(image);
var page = doc.getPages().add();
page.getParagraphs().add(coverHeaderBox);
// Save PDF Document
doc.save(PartialPath + "_output.pdf");
}
Here is the output:
FloatingBoxWithSvgImage_output.pdf (1.3 KB)
So the java version has an issue. I tried the same code with a different picture and it works. So there is something about the image.
I will be creating a bug for the dev team now.
@ahashem
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): PDFJAVA-42547
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.