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

Free Support Forum - aspose.com

How to create the same heading


image.png (3.0 KB)

I want to have the same heading in each page of a pdf as there is in this image , this was generated using a different technology and i want to implement the same using aspose pdf.

Kindly help.


if you have existing PDF document, you can use image stamp:

 Document doc = new Document(pdfPath);
 ImageStamp header = new ImageStamp(imagePath);
 System.Drawing.Image img = System.Drawing.Image.FromFile(imagePath);
  int imageWidth = img.Width;
  header.HorizontalAlignment = HorizontalAlignment.Center;
  header.VerticalAlignment = VerticalAlignment.Top;
  foreach (Page page in doc.Pages)
       header.ZoomX = (float) page.MediaBox.Width / imageWidth;
        header.ZoomY = header.ZoomX;

if you are genearating PDF document using the generator, you can use Page.Header property:

Document doc = new Document();
Image img = new Image();
img.File = imagePath;
for (int i = 1; i <= 10; i++)
    Page page = doc.Pages.Add();
    page.Header = new HeaderFooter();
   page.Header.Margin.Top = 0;
   page.Header.Margin.Left = 0;
   page.Header.Margin.Right = 0;
   page.Paragraphs.Add(new TextFragment("Page " + i));

Thanks for your reply but I don’t want to use an image , this image i have attached was a snapshot i took from an existing pdf that was already generated using a different technology , i want to generate this header for each page in the pdf , i have used FloatingBox but couldn’t place 2 pieces of text in left and right simultaneously. Kindly help me how could i achieve this

I got it. We will investigate the issue and try to provide the solution. Issue PDFNET-51733 was created for the issue. Could you please also share code snippet which you tried to use to create header?


Here is the code snippet which i am using to create header

Document pdfDocumentTemp = new Document(PDFSummaryDirectoryPath + “\” + fileName);

Aspose.Pdf.FloatingBox floatBox = new Aspose.Pdf.FloatingBox();
floatBox.VerticalAlignment = VerticalAlignment.Center;
floatBox.BackgroundColor = Aspose.Pdf.Color.DarkBlue;
floatBox.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center;

var textInfo = new Aspose.Pdf.Text.TextState();
textInfo.ForegroundColor = Aspose.Pdf.Color.White;

var textCover = new Aspose.Pdf.Text.TextFragment(document.Filename.Split(’.’)[0]);

floatBox.Margin = new MarginInfo(0, 0, 0, 0);

floatBox.Height = 50;
floatBox.Top = -80;
floatBox.Left = -90;

floatBox.Width = pdfDocumentTemp.Pages[i].PageInfo.Width + 100;
pdfDocumentTemp.Save(PDFSummaryDirectoryPath + “\” + fileName, SaveFormat.Pdf);



Thanks for sharing the code snippet. We have logged it in our issue tracking system. We will inform you once there is an update available on this issue.