Hi
I’ve got a problem related to saving a pdf file. I have the below function to which I pass a table and two strings. I open a template pdf file and insert the table to the file and subsequently I attempt to save the file but it fails with the error: Cannot instantiate Artifact class.
I have number of other places where is use pretty much same code so I am a bit confused as to the reason for the problem.
public static void ReturnPDF(DataTable res, string reviewer, string PM)
{
Aspose.Pdf.License licensepdf = new Aspose.Pdf.License();
licensepdf.SetLicense(“Aspose.Pdf.lic”);
int totalRows = res.Rows.Count;
int totalColumns = res.Columns.Count;
string code = DateTime.Now.ToString(“yyyyMMddHHmmss”);
Document pdfDocument = new Document(root + “\Files\EURALandtemplate.pdf”);
// Get particular page
Aspose.Pdf.Page pdfPage = (Aspose.Pdf.Page)pdfDocument.Pages[1];
pdfPage.PageInfo.Margin = new Aspose.Pdf.MarginInfo();
pdfPage.PageInfo.Margin.Left = 22;
pdfPage.PageInfo.Margin.Right = 22;
pdfPage.PageInfo.Margin.Top = 72;
pdfPage.PageInfo.Margin.Bottom = 72;
Aspose.Pdf.Table table = new Aspose.Pdf.Table();
table.ColumnWidths = “30 40 30 40 50 40 40 40 60 60 40 40 40 40 45 50 55”;
// Set the table border color as LightGray
table.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray));
// Set the border for table cells
table.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray));
table.ImportDataTable(res, true, 0, 0, totalRows, totalColumns);
pdfDocument.Pages[1].Paragraphs.Add(table);
string pdfFilePath = root + “\Files\” + code + “.pdf”;
using (FileStream pdfFileStream = File.Create(pdfFilePath))
{
// Convert the Document to a Pdf file stream
pdfDocument.Save(pdfFileStream, SaveFormat.Pdf);
}
}