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

Free Support Forum - aspose.com

Combining Word body with Pdf header

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;



Thanks for your inquiry. I think in this case you can try using Aspose.Words instead of Aspose.Pdf. Please see the following link to learn how to create headers/footers using Aspose.Words:


After creating header and footer you can convert your document to PDF using Aspose.Words.

Please see the following code:

// Open your HTML.

Document doc = new Document("C:\\Temp\\in.html");

DocumentBuilder builder = new DocumentBuilder(doc);

// Specify that we want headers and footers different for first and other pages.

builder.PageSetup.DifferentFirstPageHeaderFooter = true;

// Specify that we want headers and footers different for even and odd pages.

builder.PageSetup.OddAndEvenPagesHeaderFooter = true;

// Create the headers.


builder.Writeln("Header First");


builder.Writeln("Header Primary/Odd");


builder.Writeln("Header Even");

// Create pages in the document for example.










Best regards,

Hi Andrey,

I have already tried this, and the header gets corrupted by the formatting in the HTML body, which we have no control over because it is sent from Outlook. Is there not a way to mix elements from Aspose.Words into an Aspose.Pdf document and vice versa?



Hi Herman,

Thanks for your inquiry.

It would be difficult to combine PDFs from Aspose.Words and Aspose.Pdf together. Instead, as Alexey has suggested, it would be better to create the whole thing using Aspose.Words.

Could you please attach a sample output which demonstrates the issue you are having when creating the header in Aspose.Words. We will provide some suggestions to avoid this.