I was trying to generate a PDF file using Migradoc and PDFsharp with the following elements in it.
1. A paragraph with a long text in it
2. A table with one row and one column
The page format used is
Letter and orientation is
Landscape.
The PDF file got generated with both the elements, but the paragraph was displayed in full page width but the table was lesser in width. I have attached the screen of the generated file.
My code is as below:
Code:
PdfDocumentRenderer renderer = new PdfDocumentRenderer();
//Add section to document
MigraDoc.DocumentObjectModel.Document document = new MigraDoc.DocumentObjectModel.Document();
//assign page format and orientation
document.DefaultPageSetup.PageFormat = PageFormat.Letter;
document.DefaultPageSetup.Orientation = MigraDoc.DocumentObjectModel.Orientation.Landscape;
//Add a section to document
MigraDoc.DocumentObjectModel.Section section = document.AddSection();
//Get the page size for the specified page format
Unit Width, Height;
PageSetup.GetPageSize(PageFormat.Letter, out Width, out Height);
//Add a paragraph in to the section with long string
section.AddParagraph("fejhfwehfhefehw fehwfjke fhehf wejkfh jfhef hwejfhewjf hwefhwe hfjwe jhefjhew jfhwejfhe jehje hfjwe hfjkehf jefh ehfejf hejkfhew fjkwehfjk wehfjw ehfjwe hjkfwe hjfhwe jkfhwe jkfhwef hwe jkfke gfdg fgdfg fdgdf gdf dfgdfg dfgdfg dfgdfg ");
//Below table to be added to the section
MigraDoc.DocumentObjectModel.Tables.Table migradocTable = new MigraDoc.DocumentObjectModel.Tables.Table();
MigraDoc.DocumentObjectModel.Tables.Column column;
//Add one column to the table
for (int i = 0; i < 1; i++)
{
column = migradocTable.AddColumn(Width);
column.Borders.Visible = true;
column.Borders.Width = 1;
}
for (int i = 0; i < 1; i++)
{
//Add one row to the table
MigraDoc.DocumentObjectModel.Tables.Row row = migradocTable.AddRow();
row.Cells[i].AddParagraph("Test.....");
}
//Add the table to the section
section.Add(migradocTable);
//Render document
renderer.Document = document;
renderer.RenderDocument();
//Save the document
renderer.PdfDocument.Save("C:\\Sample.pdf");
Please help me to make both paragraph and table of same width and they have to take the full page width of the document (both margins can be subtracted from the page width).