Background Image for Floating Box or some work around

Hi,

We are using floating box to show some floating information but I am not able to put a background image for the FloatingBox image. Is there a work around for this? I am using Aspose.Pdf for .Net 7.3.0 version.

Thanks
Vishal

Hi Vishal,


Thanks for using our products.

If you need to add image as background/watermark over PDF file, then please follow the instructions specifiied over Adding Image Stamp in the PDF File

Besides this, if you need to add an image to FloatingBox object, you can create Image object and add it to paragraphs collection of FloatingBox. In case I have not properly understood your requirement of you have any further query, please feel free to contact.

Hi Shahbaz,

Thanks for your reply. As I mentioned I want to put a background image only to the FloatingBox not to the whole page. I know how to add a an image to the FloatingBox content, but I want to put a background image to the FloatingBox.

Thanks
Vishal

Hi Vishal,


Thanks for sharing the details and sorry for the late response.

We cannot add Background image to FloatingBox object. However if your requirement is to display background image on particular page region using FloatingBox and you also need to place other contents i.e. Text inside paragraphs collection of FloatingBox, then you need to create two FloatingBox objects. One will contain Text and the other object will hold the image file.

The FloatingBox class has a property named ZIndex which indicates the Z-order of the floating box. A floating box with larger ZIndex will be placed over the floating box with smaller ZIndex. ZIndex can be negative. Floating box with negative ZIndex will be placed behind the text in the page. Please take a look over the following code snippet and the resultant file which I have shared. In case I have still not properly understood your requirement, please feel free to contact.

[C#]

//Instantiate Pdf instance by calling
its empty constructor
<o:p></o:p>

Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();

// Create section object and add it to sections collection of PDF

Aspose.Pdf.Generator.Section sec1 = pdf1.Sections.Add();

// Create FloatingBox with 108 as width and 80 as height

Aspose.Pdf.Generator.FloatingBox box1 = new Aspose.Pdf.Generator.FloatingBox(108, 80);

// add FloatingBox to paragraphs collection of section object

sec1.Paragraphs.Add(box1);

box1.Border = new BorderInfo((int)Aspose.Pdf.Generator.BorderSide.All, new Aspose.Pdf.Generator.Color("Navy"));

// Specify the Horizontal Positioning type for FloatingBox as Margin

box1.BoxHorizontalPositioning = Aspose.Pdf.Generator.BoxHorizontalPositioningType.Margin;

// Set the left margin information as 200

box1.Left = 200;

// Specify the Vertical Positioning type for FloatingBox object

box1.BoxVerticalPositioning = Aspose.Pdf.Generator.BoxVerticalPositioningType.Page;

// Set the Top margin information as 300

box1.Top = 300;

// add sample text string to paragraphs collection of FloatingBox object

box1.Paragraphs.Add(new Aspose.Pdf.Generator.Text("Hello."));

// create Floatingbox object

Aspose.Pdf.Generator.FloatingBox imagebox = box1.Clone() as Aspose.Pdf.Generator.FloatingBox;

sec1.Paragraphs.Add(imagebox);

// create image object for background image

Aspose.Pdf.Generator.Image img = new Aspose.Pdf.Generator.Image();

img.ImageInfo.File = "c:/pdftest/Logo.jpg";

imagebox.Paragraphs.Add(img);

// set the Zorder as negative so that its displayed behind text on page

imagebox.ZIndex = -1;

// Save the resultant PDF document

pdf1.Save(“c:/pdftest/FloatingBox_ImageBackGround.pdf”);