hi there
Hi,
Thanks for contacting support.
In order to accomplish your requirements, you may get page dimensions and set TableWidth information equal to page width information. Please take a look over following code snippet. In case you encounter any issue, please share the resource PDF file, so that we can test the scenario in our environment.
[C#]
// Open document
Document pdfDocument = new Document("c:/pdftest/S_B-AUTO-BROKERS-APPLICATION.pdf");
Aspose.Pdf.HeaderFooter header = new Aspose.Pdf.HeaderFooter();
var headerTable = new Aspose.Pdf.Table
{
DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.Top, 0.1F)
};
var margin = new Aspose.Pdf.MarginInfo
{
Top = 2f,
Left = 0f,
Right = 0f,
Bottom = 5f
};
headerTable.DefaultCellPadding = margin;
// Set table default column width equal to page width
headerTable.DefaultColumnWidth = pdfDocument.Pages[1].PageInfo.Width.ToString();
// Set table border color as Red
headerTable.Border = new BorderInfo(BorderSide.All, Aspose.Pdf.Color.Red);
var row1 = headerTable.Rows.Add();
var cell1 = row1.Cells.Add();
cell1.Alignment = Aspose.Pdf.HorizontalAlignment.Left;
var textCell = new Aspose.Pdf.Text.TextFragment("my column text that should stretch....");
cell1.Paragraphs.Add(textCell);
header.Paragraphs.Add(headerTable);
pdfDocument.Pages[1].Header = header;
pdfDocument.Save("c:/pdftest/TableInHeader.pdf");
Thank you, this is working. I did not realize you could just set DefaultColumnWidth prior to the columns being added.
Hi,
Please try using following code snippet to accomplish your requirements.
[C#]
// Open document
Document pdfDocument = new Document("c:/pdftest/S_B-AUTO-BROKERS-APPLICATION.pdf");
Aspose.Pdf.HeaderFooter header = new Aspose.Pdf.HeaderFooter();
var headerTable = new Aspose.Pdf.Table
{
DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.Top, 0.1F)
};
var margin = new Aspose.Pdf.MarginInfo
{
Top = 2f,
Left = 0f,
Right = 0f,
Bottom = 5f
};
headerTable.DefaultCellPadding = margin;
// Set table default column width equal to page width
headerTable.DefaultColumnWidth = pdfDocument.Pages[1].PageInfo.Width.ToString();
// Set table border color as Red
headerTable.Border = new BorderInfo(BorderSide.All, Aspose.Pdf.Color.Red);
var row1 = headerTable.Rows.Add();
var cell1 = row1.Cells.Add();
cell1.Alignment = Aspose.Pdf.HorizontalAlignment.Left;
var textCell = new Aspose.Pdf.Text.TextFragment();
// Create TextSegment instances
Aspose.Pdf.Text.TextSegment normalSegment = new Aspose.Pdf.Text.TextSegment("my column text that")
{
TextState = { ForegroundColor = Aspose.Pdf.Color.Red }
};
textCell.Segments.Add(normalSegment);
Aspose.Pdf.Text.TextSegment boldSegment = new Aspose.Pdf.Text.TextSegment(" Should ")
{
TextState =
{
ForegroundColor = Aspose.Pdf.Color.Red,
FontStyle = Aspose.Pdf.Text.FontStyles.Bold
}
};
textCell.Segments.Add(boldSegment);
Aspose.Pdf.Text.TextSegment thirdSegment = new Aspose.Pdf.Text.TextSegment("stretch....")
{
TextState = { ForegroundColor = Aspose.Pdf.Color.Red }
};
textCell.Segments.Add(thirdSegment);
cell1.Paragraphs.Add(textCell);
header.Paragraphs.Add(headerTable);
pdfDocument.Pages[1].Header = header;
pdfDocument.Save("c:/pdftest/TableInHeader.pdf");
Hi,
Thanks for sharing the details.
The reason second column do not render in PDF file is because you have set table width equal to page width and in order to generate correct output, you need to set smaller value to DefaultColumnWidth property. For your reference, I have also attached the output generated over my end.
[C#]
// set table default column width equal to page widht
headerTable.DefaultColumnWidth = “200”;
//pdfDocument.Pages[1].PageInfo.Width.ToString();
Hi there
Hi there
Hi,
Hi there
Hi,
Hi there
Thanks
Hi,
Thanks for your patience.