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

Free Support Forum - aspose.com

Creating document with PDF header and Word body

Hi everyone,

I need to format a document that has a header generated by Aspose.Pdf but the body is generated by Aspose.Words and the footer generated by Aspose.Pdf. The reason for this is that we are getting a HTML in MS Outlook format which can not be parsed by Aspose.Pdf, but if we generate the header using Aspose.Words, it messes up the heading. Here is the code we are using for the pdf header, so any ideas on how to do this?


PDF generation code:

Pdf pdf = new Pdf();

pdf.IsTruetypeFontMapCached = false;

pdf.PageSetup.PageHeight = PageSize.A2Height;

pdf.PageSetup.PageWidth = PageSize.A2Width;

Aspose.Pdf.Generator.Section secHeader = pdf.Sections.Add();

Aspose.Pdf.Generator.HeaderFooter header = new Aspose.Pdf.Generator.HeaderFooter(secHeader);

secHeader.OddHeader = header;

Table tableLogo = new Table();

tableLogo.PositioningType = PositioningType.ColumnRelative;


tableLogo.DefaultCellBorder = new BorderInfo((int)BorderSide.None, 0.1F);

tableLogo.ColumnWidths = "500 500";

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

img.ImageInfo.File = @"F:\logo999_110.bmp";

img.ImageInfo.ImageFileType = ImageFileType.Bmp;

img.ImageInfo.FixWidth = 1000;

Row row1 = tableLogo.Rows.Add();

Cell cellImage = row1.Cells.Add();


tableLogo.Rows[0].Cells[0].ColumnsSpan = 2;

Row row2 = tableLogo.Rows.Add();

row2.BackgroundColor = new Aspose.Pdf.Generator.Color("#0000A0");

row2.DefaultCellTextInfo.Color = new Aspose.Pdf.Generator.Color("#FFFFFF");

row2.DefaultCellTextInfo.FontName = "Verdana";

row2.DefaultCellTextInfo.FontSize = 12;

Cell cellTitle = row2.Cells.Add("Title");

cellTitle.Alignment = AlignmentType.Left;

Cell cellDate = row2.Cells.Add("20 November 2011");

cellDate.Alignment = AlignmentType.Right;

Row row3 = tableLogo.Rows.Add();

row3.DefaultCellTextInfo.FontSize = 12;

row3.DefaultCellTextInfo.FontName = "Arial";

Cell cellName = row3.Cells.Add("FirstName LastName");

cellName.Alignment = AlignmentType.Left;

Cell cellEmail = row3.Cells.Add("FirstName.LastName@companyname.com");

cellEmail.DefaultCellTextInfo.Color = new Aspose.Pdf.Generator.Color("#00FFFF");

cellEmail.Alignment = AlignmentType.Right;


Hi Herman404,

I have gone through your requirement and also have tried the code that you have shared. The code generates a table and places it inside Header area of the document. Let me share my thoughts over your requirement. Aspose.Pdf also supports the feature to render HTML contents into PDF format, so I think you can use Aspose.Pdf to create Header, Footer and body area of the PDF file. In order to convert HTML into PDF, check out HTML Tags in Text.

There can be another approach. Once you have generated the PDF from Aspose.Words, you can use following approaches to add Header and Footer to this PDF file. Add Header in a PDF File (Facades) and also Add Footer in a PDF File (Facades)

Another approach can be to convert HTML to PDF using Aspose.Words and also create a PDF file with Header and Footer using Aspose.Pdf and then add this PDF file as watermark to PDF document generated with Aspose.Words. So the theme of this approach will be to, add one PDF file as watermark to another file. For more information, check out Add PDF Page Stamp on All Pages in a PDF File (Facades)

Hi Hassan,

Thanks for the information about creating a Watermark. Is there a way I can specify Aspose.Pdf to create this watermark only on the first page of the document?

Hi Herman,

You may check the following documentation link for details and code snippets as per your requirement.

Add PDF Page Stamp on Particular Pages in a PDF File (Facades)

Please do let us know if you need any further assistance.

Thanks & Regards,