I am trying to create a document using PDF.Generator where an image appears at the top of the text page with grey text placed atop it and I’m unable to make this happen. The header appears at the top, but I can’t get my text to go on top of it. Here’s my code and I’m attaching a sample of what it creates:
// Add Header Section
Aspose.Pdf.Generator.Section sec0 = myDocument.Sections.Add();
Aspose.Pdf.Generator.Image imgHeader = new Aspose.Pdf.Generator.Image(sec0);
sec0.Paragraphs.Add(imgHeader);
imgHeader.ImageInfo.File = MapPath("~/images/printing/Test-header.jpg");
imgHeader.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Jpeg;
sec0.PageInfo.PageWidth = Aspose.Pdf.Generator.PageSize.A4Width;
sec0.PageInfo.PageHeight = Aspose.Pdf.Generator.PageSize.A4Height;
Aspose.Pdf.Generator.MarginInfo headerMargin = new Aspose.Pdf.Generator.MarginInfo();
headerMargin.Top = 0;
headerMargin.Left = 0;
headerMargin.Right = 0;
headerMargin.Bottom = 0;
sec0.PageInfo.Margin = headerMargin;
string HtmlString = “Header”;
Aspose.Pdf.Generator.Text myText = new Text(HtmlString);
myText.IsHtmlTagSupported = true;
myText.Top = -72;
myText.Left = 183;
sec0.Paragraphs.Add(myText);
//Add a section into the pdf document
Aspose.Pdf.Generator.Section sec1 = myDocument.Sections.Add();
sec1.IsNewPage = false;
Aspose.Pdf.Generator.MarginInfo contentMargin = new Aspose.Pdf.Generator.MarginInfo();
contentMargin.Top = 72;
contentMargin.Left = 72;
contentMargin.Right = 72;
contentMargin.Bottom = 72;
sec1.PageInfo.Margin = contentMargin;
//Add a text paragraph into the section
sec1.Paragraphs.Add(new Aspose.Pdf.Generator.Text(“Now is the winter of our discontent made glorious summer by this sun of York.”));
Any ideas?
Thanks!
Laurie
Hi Laurie,
Thanks for contacting support.
As per my understanding, you need to place text on top of image placed inside the document. Please note that all the contents are added in flow layout (Top-Left to Bottom-Right), therefore the text added after the image appears beneath it. In order to place the text on top of image element, you need to try using FloatingBox object. The floatingbox uses obsolete positioning rather than flow layout. Please try using following code lines to accomplish your requirements.
You may visit the following link for further information on Customizing Watermark
[C#]
//
sec1.Paragraphs.Add(new Aspose.Pdf.Generator.Text(“Now is the
winter of our discontent made glorious summer by this sun of York.”));<o:p></o:p>
//add text as watermark
Aspose.Pdf.Generator.Text text3 = new Aspose.Pdf.Generator.Text("Now is the winter of our discontent made glorious summer by this sun of York.");
Aspose.Pdf.Generator.FloatingBox watermark1 = new Aspose.Pdf.Generator.FloatingBox(108, 80);
watermark1.Left = 50;
watermark1.Top = 100;
watermark1.Paragraphs.Add(text3);
myDocument.Watermarks.Add(watermark1);
Thanks, I was able to get that to work. ONe more question: how can I get the watermark to only show up on the first page of the document?
Hi Laurie,
The watermark (FloatingBox) object is added to particular Section of PDF file. So as per your requirement, you can create more than one section in PDF file and add FloatingBox to only first Section. Please note that by default, every new section starts from new page.
PS, Pdf object can have one or more section objects.