FloatingBox to top left corner every pdf doc

hey,


i’ve write some code:

Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();
Aspose.Pdf.Generator.Section sec1 = pdf1.Sections.Add();
Aspose.Pdf.Generator.FloatingBox box1 = new Aspose.Pdf.Generator.FloatingBox(108, 180);
sec1.Paragraphs.Add(box1);
box1.BoxHorizontalPositioning = Aspose.Pdf.Generator.BoxHorizontalPositioningType.Page;
box1.BoxHorizontalAlignment = Aspose.Pdf.Generator.BoxHorizontalAlignmentType.Left;
box1.BoxVerticalPositioning = Aspose.Pdf.Generator.BoxVerticalPositioningType.Page;
box1.BoxVerticalAlignment = Aspose.Pdf.Generator.BoxVerticalAlignmentType.Top;
box1.Paragraphs.Add(new Aspose.Pdf.Generator.Text(“Hello.”));

pdf1.Save(“test.pdf”);

Aspose.Pdf.Document doc = new Aspose.Pdf.Document(“test.pdf”);
var page = doc.Pages[1];
Aspose.Pdf.FloatingBox aBox = new Aspose.Pdf.FloatingBox(40, 60);
aBox.Left = 0;
aBox.Top = 0;
aBox.VerticalAlignment = Aspose.Pdf.VerticalAlignment.Top;
aBox.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Left;
aBox.Paragraphs.Add((new Aspose.Pdf.Text.TextFragment(“main text”)));
aBox.Border = new Aspose.Pdf.BorderInfo();
aBox.BackgroundColor = Aspose.Pdf.Color.Yellow;
page.Paragraphs.Add(aBox);
doc.Save(“test2.pdf”);



that code, generates two pdf files. i’ve attached them to post.
first part of code add HELLO text to the floatingBox at top left corner of page and save pdf.
second part of code opens that pdf document again and adds another (yellow) floatingbox with text MAIN TEXT again on top left corner then save pdf

second floating box is not at top left corner.

can i add floatingbox to left top corner on existsing pdf document (every pdf document or only generated with pdf.generator) ? can i add floatingbox to left border of page existsing documents (every pdf document or only generated with pdf.generator) ?

thanks for replay

Hi Podlaski,

Thanks for your inquiry. If you want to add a floating box in the top left corner of a PDF using Aspose.Pdf (new generator), then you need to add the floating box in the header object as following. Moreover, please note that the new generator is improved and efficient. You can use it for both creating PDF documents from scratch and manipulating existing PDF documents.

Aspose.Pdf.Document
doc = new Aspose.Pdf.Document("test.pdf");

var page = doc.Pages[1];

Aspose.Pdf.FloatingBox
aBox = new Aspose.Pdf.FloatingBox(40, 60);

aBox.Left = 0;

aBox.Top = 0;

aBox.VerticalAlignment = Aspose.Pdf.VerticalAlignment.Top;

aBox.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Left;

aBox.Paragraphs.Add((new Aspose.Pdf.Text.TextFragment("main text")));

aBox.Border = new Aspose.Pdf.BorderInfo();

aBox.BackgroundColor = Aspose.Pdf.Color.Yellow;

HeaderFooter header = new HeaderFooter();

header.Margin.Left = 0;

header.Paragraphs.Add(aBox);

page.Header = header;

doc.Save("test2.pdf");

Please feel free to contact us for any further assistance.

Best Regards,