We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Headers With Images


I am currently attempting to make a document which contains a header, footer and a table in-between spans multiple pages.

The table, header and footer are working fine but when I want to add an Image to the header I am stuck. I have tried adding the image directly to the page as described in the following page.


But this only appears on the first page. I though about repeating the code for all the pages in the document but as I am only adding one page and the table automatically going into page 2 is adding the rest of the pages I don’t seem to have access to the remaining pages.

Hi Neil,

Thanks for contacting support.

Can you please share the code snippet and sample PDF files being generated in your environment so that we can test the scenario at our end. We are sorry for this inconvenience.

Well this is the issue I don’t know where to start so I don’t really have any code.

The code I could find adds the image to the currentPage

private double AddImage(Page currentPage, Stream imageStream, double x, double y, double height, bool factorWidth = false)
currentPage.Contents.Add(new Operator.GSave());

XImage ximage = currentPage.Resources.Images[currentPage.Resources.Images.Count];
double scale = height / ximage.Height;
double width = ximage.Width * scale;

if (factorWidth)
x = x - width;
Rectangle rectangle = new Rectangle(x, y, x + width, y + height);
Aspose.Pdf.DOM.Matrix matrix = new Aspose.Pdf.DOM.Matrix(new double[] { rectangle.URX - rectangle.LLX, 0, 0, rectangle.URY - rectangle.LLY, rectangle.LLX, rectangle.LLY });
currentPage.Contents.Add(new Operator.ConcatenateMatrix(matrix));
currentPage.Contents.Add(new Operator.Do(ximage.Name));
currentPage.Contents.Add(new Operator.GRestore());

return width;

Which is fine but I can only access the first page when I add a table.

Page page = doc.Pages.Add();
Table table;
SetupTable(out table);
Row newRow;
foreach(DataRow dr in dt.Rows)
newRow = table.Rows.Add();

So if I apply the above method in some sort of loop like below then I only get images on the first page

foreach(Page page in doc.Pages)
AddImage(page, LeftImage, 100, 100, 100);

Hi Neil,

Thanks for sharing the code snippet.

have tested the scenario and I am able to notice the same problem. For the sake
of correction, I have logged this problem as PDFNEWNET-36623 in
our issue tracking system. We will further look into the details of this
problem and will keep you updated on the status of correction. Please be
patient and spare us little time. We are sorry for this inconvenience.<o:p></o:p>

Hi Neil,

In addition to Nayyer’s comments. Please note that PDF is created dynamically and in order to get real PDF document PDF engine need to render its programming/dynamic model, so the actual structure is created. So please break your scenario into two parts. Create your PDF document and save into stream and then reopen it and add images on respective pages. Hopefully it will help you to accomplish your task.<o:p></o:p>

ByteArrayOutputStream outputStream = new ByteArrayOutputStream();


doc = new Document( new ByteArrayInputStream(outputStream.toByteArray()));

Please feel free to contact us for any furhter assistance.

Best Regards,

The issues you have found earlier (filed as PDFNEWNET-36623) have been fixed in Aspose.Pdf for .NET 9.1.0.

For further details, you may check this blog post.

This message was posted using Notification2Forum from Downloads module by Aspose Notifier.
Hi Neil,

In order to generate correct output, please try using following code snippet.


string outFile = TestSettings.GetOutputFile("36623.pdf");

string inFile = TestSettings.GetInputFile("../Generator/36163.bmp");

//open document

Document pdfDocument = new Document();

Page page = pdfDocument.Pages.Add();

Aspose.Pdf.Table table = new Aspose.Pdf.Table();

// SetupTable(out table);

Aspose.Pdf.Row newRow;

for (int counter = 0; counter <= 100; counter++)

{ newRow = table.Rows.Add(); newRow.Cells.Add("Sample Cell" + counter); }



pdfDocument = new Document(outFile);

FileStream fs = new FileStream(inFile, FileMode.Open);

foreach (Page innerpage in pdfDocument.Pages)

{ AddImage(innerpage, fs, 100, 100, 100); }