i am trying to convert a text file to a pdf in a table format but the pdf alignment is not proper.
Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();
//Create a new section in the Pdf object
pdf1.PageSetup.Margin.Top = -10f;
Aspose.Pdf.Generator.Section sec1 = pdf1.Sections.Add();
//Aspose.Pdf.Generator.MarginInfo marginInfo = new Aspose.Pdf.Generator.MarginInfo();
//marginInfo.Top=0;
//marginInfo.Left = 20;
//marginInfo.Bottom = 10;
//sec1.PageInfo.Margin = marginInfo;
sec1.PageInfo.PageWidth = Aspose.Pdf.Generator.PageSize.A4Width;
sec1.PageInfo.PageHeight = Aspose.Pdf.Generator.PageSize.A4Height;
Aspose.Pdf.Generator.Table tab= new Aspose.Pdf.Generator.Table();
Aspose.Pdf.Generator.MarginInfo margin = new Aspose.Pdf.Generator.MarginInfo();
margin.Top = 5f;
margin.Left = 5f;
margin.Right = 5f;
margin.Bottom = 5f;
tab.ColumnWidths = "60 300 80";
tab.DefaultCellPadding = margin;
//Specify the location of input text file
String FILE_NAME = "E:/Gowtham/projects/PolyInnovations/PolyInnovations/FileRepository/ChatLog/PolyInnovations_ChatLog_8.txt";
System.IO.TextReader objReader = new System.IO.StreamReader(FILE_NAME);
Aspose.Pdf.Generator.Row row1 = tab.Rows.Add();
row1.Cells.Add("User");
row1.Cells.Add("Message");
row1.Cells.Add("Time");
sec1.Paragraphs.Add(tab);
Aspose.Pdf.Generator.Row row2 = tab.Rows.Add();
row2.Cells.Add("=====");
row2.Cells.Add("========");
row2.Cells.Add("=======");
sec1.Paragraphs.Add(tab);
Aspose.Pdf.Generator.Row row = tab.Rows.Add();
// Read the file till the end of the file has come
do
{
string data = objReader.ReadLine();
if (data=="") { continue; }
//return data.Split("",StringSplitOptions.None);
if (data.StartsWith( "ProfileId:")) {
continue;
}
if (data.StartsWith("User Name:"))
{
data=data.Replace("User Name:", "");
row.Cells.Add(data);
}
if (data.StartsWith("Message:"))
{
data=data.Replace("Message:", "");
row.Cells.Add(data);
}
if (data.StartsWith("Time:")) {
data=data.Remove(0, 5);
data = data.Remove(15, 3);
row.Cells.Add(data);
}
if (data=="================================================================================================")
{
sec1.Paragraphs.Add(tab);
row = tab.Rows.Add();
}
//Create a new text paragraph & pass text to its constructor as argument
//Aspose.Pdf.Generator.Text t2 = new Aspose.Pdf.Generator.Text(objReader.ReadLine());
// add the text object to paragraphs collection of section
//sec1.Paragraphs.Add(t2);
// Read till the end of file
} while (objReader.Peek() != -1);
// Close the StreamReader object
objReader.Close();
// Save the PDF file
pdf1.Save("E:/Gowtham/projects/PolyInnovations/PolyInnovations/FileRepository/ChatLog/PolyInnovations_ChatLog_2.pdf");