Set background image for Section composed of multiple pages

The documentation here (http://www.aspose.com/docs/display/pdfnet/Set+Page+Background+Image) says the following:

"

Aspose.Pdf for .NET feature's list also include to set the background image for a [Section]. In Aspose.Pdf for .NET a [Section] can be composed of multiple pages. So, if we set the background image for a [Section] then that background image will be displayed on all pages (that belong to the same [Section]).

"

How does one do this? Specifically, I would like to take an existing PDF, put all of the pages in a Section, and then set the background image for that section.

Hi Keith,

Thanks for your inquiry. Please check the following code snippet to set page background. Hopefully, it will help you to accomplish.

Document doc = new Document(myDir + "input.pdf");

// Background
BackgroundArtifact background = new BackgroundArtifact();
background.BackgroundImage = System.IO.File.OpenRead(myDir + "image.png");

foreach(Page page in doc.Pages)
    page.Artifacts.Add(background);

doc.Save(myDir + "Document_background1.pdf");

Please feel free to contact us for any further assistance.

Best Regards,

tilal.ahmad: Hi Keith,

Thanks for your inquiry. Please check the following code snippet to set the page background. Hopefully, it will help you > accomplish your task.

Document doc = new Document(myDir + "input.pdf");

// Background
BackgroundArtifact background = new BackgroundArtifact();
background.BackgroundImage = System.IO.File.OpenRead(myDir + "image.png");

foreach(Page page in doc.Pages) {
    page.Artifacts.Add(background)

}

doc.Save(myDir + “Document_background1.pdf”);

Please feel free to contact us for any further assistance.

Best Regards,

I tried this technique earlier. It did put the background image on each page, but at a high cost. For our 8-page test document with a 300 PPI TIFF image, it took 15 seconds on average to output the document versus 9.5 seconds for an existing “draw the image on each page method” we have using PDFSharp. Furthermore, the resulting PDF was 4.52 MB using this technique versus 246 KB for our existing method.

So, is there not a way to do what that support page advised, applying a background image to a section consisting of multiple pages? If not that, is there any more efficient way to do this?

Hi Keith,


Adding more to Tilal’s comments, the documentation link which you have shared in your above post is related to related to Aspose.Pdf.Generator namespace is a legacy approach and it only offers the feature to set background Image for PDF document being generated from scratch. Whereas the new Document Object Model (DOM) of Aspose.Pdf namespace provides the feature to create as well as manipulate existing PDF documents. So as shared by Tilal, we recommend using new DOM for PDF creation, as well as manipulation.

keithkurak:
I tried this technique earlier. It did put the background image on each page but at a high cost. For our 8 page test document overlayed with a 300 PPI TIFF image, it took 15 seconds on average to output the document, vs 9.5 seconds for an existing “draw the image on each page method” we have using PDFSharp. Furthermore, the resulting PDF was 4.52 MB using this technique, vs. 246 KB for our existing method.

So, is there not a way to do what that support page advised, applying a background image to a Section consisting of multiple pages? If not that, is there any more efficient way to do this?
Hi Keith,

Can you please share the resource files, so that we can test the scenario in our environment. Meanwhile in order to optimize the size of resultant PDF file, you may consider following the instructions specified over Optimize PDF File Size