Im doing some testing with aspose.pdf and I am having problems with generating text areas with a border surrounding the text. As you can see from the code I have a function that adds a text paragraph with the TextInfo.TextBorder set, to a section. The problem is that if I add multiple text paragraph's to a section using the function, all the text paragraphs share the same TextBorder, and does not surround the individual paragraphs I added. The paragraph and the text border is also cut/broken at page break.
This was run in a visual studio 2005 asp.net project.
I find it unintuitive that the border area is merged considering that I am adding individual Text paragraphs with individual borders. And the aspose.pdf documentation is poor to say the least.
// CODE FOLLOWS
// This is the function that add a Text paragraph and set the TextInfo.TextBorder
private void AddTextWithTitleStandard(string title, string content, Section section1)
{
Text text1 = new Text(section1);
BorderInfo text1Border = new BorderInfo((int)BorderSide.All, 2, new Color(84, 84, 84));
text1.TextInfo.TextBorder = text1Border;
text1.Margin.Top = 10;
//text1.Margin.Left = 1;
//text1.Margin.Right = 1;
text1.Margin.Bottom = 10;
text1.TextInfo.Color = new Color("Black");
Segment header1 = new Segment(text1);
header1.TextInfo.FontSize = 16;
header1.TextInfo.IsTrueTypeFontBold = true;
header1.Content = title + "\r\n";
Segment content1 = new Segment(text1);
content1.Content = content;
text1.Segments.Add(header1);
text1.Segments.Add(content1);
text1.IsKeptTogether = true;
text1.IsKeptWithNext = false;
section1.Paragraphs.Add(text1);
}
private void InitializePdf(Pdf pdf1)
{
BorderInfo bi = new BorderInfo((int)BorderSide.All, 2, new Color("Black"));
pdf1.PageSetup.Margin.Top = 40;
pdf1.PageSetup.Margin.Left = 1;
pdf1.PageSetup.Margin.Right = 1;
pdf1.PageSetup.Margin.Bottom = 1;
pdf1.PageSetup.PageBorder = bi;
pdf1.PageSetup.PageBorderMargin.Top = 60;
Security s = new Security();
s.Is128BitsEncrypted = true;
s.IsContentsModifyingAllowed = false;
pdf1.Security = s;
}
private void InitializeSection(Section section1)
{
BorderInfo bi = new BorderInfo((int)BorderSide.All, 2, new Color("Black"));
HeaderFooter mainHeader = new HeaderFooter(section1);
HeaderFooter mainFooter = new HeaderFooter(section1);
Aspose.Pdf.Image headerImage = new Aspose.Pdf.Image(mainHeader);
headerImage.ZIndex = -1;
headerImage.Margin.Top = 20;
headerImage.ImageInfo.Alignment = AlignmentType.Center;
headerImage.ImageInfo.File = Server.MapPath("lvtfetop.jpg");
headerImage.ImageInfo.ImageFileType = ImageFileType.Jpeg;
Graph footGraph = new Graph(mainFooter);
Rectangle footRect = new Rectangle(0, 12, 560, 10);
footGraph.Shapes.Add(footRect);
footRect.GraphInfo.IsFilled = true;
footRect.GraphInfo.FillColor = new Color("Black");
section1.EvenHeader = mainHeader;
section1.OddHeader = mainHeader;
section1.EvenFooter = mainFooter;
section1.OddFooter = mainFooter;
section1.PageInfo.PageBorder = bi;
section1.PageInfo.PageBorderMargin.Top = 60;
section1.PageInfo.PageBorderMargin.Left = 20;
section1.PageInfo.PageBorderMargin.Right = 20;
section1.PageInfo.PageBorderMargin.Bottom = 40;
section1.PageInfo.Margin.Left = 40;
section1.PageInfo.Margin.Right = 40;
mainHeader.Paragraphs.Add(headerImage);
}
// This is the "Main" code
string pdffilename = "pdftest.pdf";
string pdfpathmap = Server.MapPath(pdffilename);
Pdf pdf1 = new Pdf();
Section section1 = pdf1.Sections.Add();
InitializePdf(pdf1);
InitializeSection(section1);
AddTextWithTitleStandard("2. THIS IS A TEST TITLE - TEXT AREA", "This is some content\r\nThis is more content", section1);
AddTextWithTitleStandard("2. THIS IS A TEST TITLE - TEXT AREA", "This is some content\r\nThis is more content", section1);
AddTextWithTitleStandard("2. THIS IS A TEST TITLE - TEXT AREA", "This is some content\r\nThis is more content", section1);
AddTextWithTitleStandard("2. THIS IS A TEST TITLE - TEXT AREA", "This is some content\r\nThis is more content", section1);
AddTextWithTitleStandard("2. THIS IS A TEST TITLE - TEXT AREA", "This is some content\r\nThis is more content", section1);
AddTextWithTitleStandard("2. THIS IS A TEST TITLE - TEXT AREA", "This is some content\r\nThis is more content", section1);
AddTextWithTitleStandard("2. THIS IS A TEST TITLE - TEXT AREA", "This is some content\r\nThis is more content", section1);
AddTextWithTitleStandard("2. THIS IS A TEST TITLE - TEXT AREA", "This is some content\r\nThis is more content", section1);
AddTextWithTitleStandard("2. THIS IS A TEST TITLE - TEXT AREA", "This is some content\r\nThis is more content", section1);
pdf1.Save(pdfpathmap);