Hi,
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.
Regards,
kunal
Hi,
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.
Regards,
kunal
Hello,
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;
page.AddStamp(header);
}
doc.Save(outputPdfPath);
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.Header.Paragraphs.Add(img);
page.Paragraphs.Add(new TextFragment("Page " + i));
}
doc.Save(outPdfPath);
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?
Hi,
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]);
textCover.TextState.ApplyChangesFrom(textInfo);
floatBox.Margin = new MarginInfo(0, 0, 0, 0);
floatBox.Height = 50;
floatBox.Top = -80;
floatBox.Left = -90;
floatBox.Paragraphs.Add(textCover);
floatBox.Width = pdfDocumentTemp.Pages[i].PageInfo.Width + 100;
pdfDocumentTemp.Pages[i].Paragraphs.Add(floatBox);
pdfDocumentTemp.Save(PDFSummaryDirectoryPath + “\” + fileName, SaveFormat.Pdf);
pdfDocumentTemp.FreeMemory();
pdfDocumentTemp.Dispose();
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.