linkedinfacebooktwittermenuarrow-up

GemBox Support Forum

I want add text left side and image right side in header using gembox.document in PDF

Hi team,
I want add text left side and image right side in header using gembox.document in PDF

Hi,

Probably the easiest way would be to use a borderless table with two columns and 1 row.
Something like this:

var document = new DocumentModel();
document.Content.LoadText("Sample body text.");

var headerTable = new Table(document, 1, 2);
headerTable.TableFormat.PreferredWidth = new TableWidth(100, TableWidthUnit.Percentage);
headerTable.TableFormat.Borders.SetBorders(MultipleBorderTypes.All, BorderStyle.None, Color.Empty, 0);

headerTable.Rows[0].Cells[0].Blocks.Add(
    new Paragraph(document,
        new Run(document, "Sample header text.")));

headerTable.Rows[0].Cells[1].Blocks.Add(
    new Paragraph(document,
        new Picture(document, "image.png"))
    { ParagraphFormat = { Alignment = HorizontalAlignment.Right } });

document.Sections[0].HeadersFooters.Add(
    new HeaderFooter(document, HeaderFooterType.HeaderDefault, headerTable));

document.Save("output.pdf");

I hope this helps.

Regards,
Mario

I am converting html to pdf. after adding above header code html data not showing in PDF. only header is showing in PDF.

Please send us the whole code that you have so that we can reproduce your issue and investigate it.

Issue is resolved.
Thanks for the help to set header.