Trying to transition from the Generator to Document namespace I’m having trouble knowing what to replace some items with:
public bool GenerateIntroPageForAuditTrail(DataTable data, string resultLocation, string name)
{
bool _result = false;
try
{
if (!string.IsNullOrWhiteSpace(resultLocation) && data != null && data.Rows.Count > 0)
{
if (File.Exists(resultLocation))
File.Delete(resultLocation);
// Instantiate a Pdf instance
Aspose.Pdf.Generator.Pdf doc = new Aspose.Pdf.Generator.Pdf();
// Create a section in the Pdf instance
//Document
Aspose.Pdf.Generator.Section section = doc.Sections.Add();
section.IsLandscape = true;
section.PageInfo.PageHeight = Aspose.Pdf.Generator.PageSize.A3Height;
section.PageInfo.PageWidth = Aspose.Pdf.Generator.PageSize.A3Width;
//What I sthe replace ment for Aspose.Pdf.Generator.Text
Aspose.Pdf.Generator.Text theader = new Aspose.Pdf.Generator.Text(section);
//What I sthe replace ment for Aspose.Pdf.Generator.Segment
Aspose.Pdf.Generator.Segment seg1 = new Aspose.Pdf.Generator.Segment(theader);
seg1.Content = name;
seg1.TextInfo.FontSize = 32.0f;
seg1.TextInfo.Alignment = Aspose.Pdf.Generator.AlignmentType.FullJustify;
seg1.TextInfo.IsTrueTypeFontBold = true;
theader.Margin.Top = 100f;
theader.Margin.Left = 250f;
theader.Margin.Right = 250f;
theader.Margin.Bottom = 50f;
//seg1.TextInfo.FontName = "TimesRoman";
theader.Segments.Add(seg1);
section.Paragraphs.Add(theader);
// Create a Table object
Aspose.Pdf.Generator.Table table = new Aspose.Pdf.Generator.Table();
table.Margin.Top = 10f;
//table.Margin.Left = 150f;
//table.Margin.Bottom = 150f;
//table.Margin.Right = 150f;
//table.IsRowBroken = false;
table.Alignment = Aspose.Pdf.Generator.AlignmentType.Center;
table.ColumnAdjustment = Aspose.Pdf.Generator.ColumnAdjustmentType.AutoFitToWindow;
table.Border = borderInfo;
// Add the Table object in the paragraphs collection of the section
section.Paragraphs.Add(table);
// Set column widths of the table
table.ColumnWidths = "400 400";//"40 40 40 40 40 40 40 40 40";
// Set default cell border of the table using BorderInfo object
table.DefaultCellBorder = borderInfo;
// Import data into the Table object from the DataTable created above
table.ImportDataTable(data, false, 0, 0, data.Rows.Count, data.Columns.Count);
//What I sthe replace ment for Aspose.Pdf.Generator.textformats
Aspose.Pdf.Generator.TextInfo textformats = new Aspose.Pdf.Generator.TextInfo();
textformats.IsTrueTypeFontBold = true;
textformats.BackgroundColor = new Aspose.Pdf.Generator.Color("White");
textformats.Alignment = Aspose.Pdf.Generator.AlignmentType.Left;
textformats.FontSize = 24.0f;
Aspose.Pdf.Generator.MarginInfo cmargin = new Aspose.Pdf.Generator.MarginInfo();
cmargin.Top = 10f;
cmargin.Left = 10f;
cmargin.Right = 10f;
cmargin.Bottom = 10f;
foreach (Aspose.Pdf.Generator.Row item in table.Rows)
{
// Iterate through all cells in the row and set their background color to blue
foreach (Aspose.Pdf.Generator.Cell curCell in item.Cells)
{
curCell.DefaultCellTextInfo = textformats;
curCell.IsWordWrapped = true;
curCell.VerticalAlignment = Aspose.Pdf.Generator.VerticalAlignmentType.Center;
curCell.Padding = cmargin;
}
}
// Save the Pdf
doc.Save(resultLocation);
Thread.Sleep(1000);
_result = true;
}
}
catch (Exception ex)
{
Logger.Error(ex);
}
return _result;
}