Setting a background image

Using Aspose.PDF 10.5.1 I am trying to create a pdf file using the Aspose.Pdf.Generator.Pdf and I am having some trouble setting a background image.



I can use the Section.BackgroundImageFile to set images as I create my various sections, but I can’t set the image height when I do this so and I don’t want my image to fill the entire page.



I’ve tried loading my Generator into a Document object and then using either Stamps of BackgroundArtifacts but I can’t get either to work. The final pdf is still the same size as if I had just written out the Generator output. Can I get some pointers? Thanks!



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



AddLetterPage(pdf1, letter_info);



Document doc = new Document(pdf1);



foreach(Page page in doc.Pages)

{

/BackgroundArtifact bga = new BackgroundArtifact();

bga.BackgroundImage = System.IO.File.OpenRead(image_path);

bga.ArtifactVerticalAlignment = VerticalAlignment.Center;

bga.ArtifactHorizontalAlignment = HorizontalAlignment.Center;



page.Artifacts.Add(bga);
/



ImageStamp stamp = new ImageStamp(image_path);

stamp.Background = true;

stamp.VerticalAlignment = VerticalAlignment.Center;

stamp.HorizontalAlignment = HorizontalAlignment.Center;



page.AddStamp(stamp);

}



System.IO.MemoryStream ms_pdf = new System.IO.MemoryStream();

doc.Save(ms_pdf);

Never mind, updated to Aspose.PDF 10.6 and everything is working now.

Hi Michael,


Thanks for your feedback. It is good to know that you have managed to resolve the issue by using latest version for Aspose.Pdf for .NET.

Please keep using our API and feel free to contact us for any question or concern, we will be more than happy to extend our support.

Best Regards,