Hi,
1.InsertRange(Int32 index, IEnumerable
1 collection)1.AddRange(IEnumerable
1 collection)Hi,
1.InsertRange(Int32 index, IEnumerable
1 collection)1.AddRange(IEnumerable
1 collection)Hi Manish,
Hi,
Please find html attached and source code for conversion attached.
public static void ExportToPDF(string readTemplate, HttpResponse response, String[] sHeaderFooter, string sReportNumber, string sUserID)
{
string sFileName = string.Empty;
//string sVpath = string.Empty;
string docName = Path.GetFileNameWithoutExtension(readTemplate);
int FileExtPos = readTemplate.LastIndexOf(".");
String sName = sUserID;
sName = "_" + sName.Remove(0, sName.IndexOf(@"\") + 1);
sFileName = docName + sName;
readTemplate = readTemplate.Substring(0, FileExtPos) + sName + ".htm";
try
{
StreamReader r = File.OpenText(readTemplate);
Aspose.Pdf.License license = new Aspose.Pdf.License();
license.SetLicense(System.Web.HttpContext.Current.Server.MapPath("bin/Aspose.Total.lic"));
// Instantiate an object PDF class
Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();
// add the section to PDF document sections collection
Aspose.Pdf.Generator.Section section = pdf.Sections.Add();
// Create Header Section of the document
Aspose.Pdf.Generator.HeaderFooter header = new Aspose.Pdf.Generator.HeaderFooter(section);
// set the Odd header for the PDF file
section.OddHeader = header;
// Set the Even Header for the PDF file
section.EvenHeader = header;
// add the section to PDF document sections collection
Aspose.Pdf.Generator.Section section1 = pdf.Sections.Add();
// Create Footer Section of the document
Aspose.Pdf.Generator.HeaderFooter footer = new Aspose.Pdf.Generator.HeaderFooter(section1);
// set the Odd footer for the PDF file
section.OddFooter = footer;
// Set the Even footer for the PDF file
section.EvenFooter = footer;
// add the section to PDF document sections collection
Aspose.Pdf.Generator.Section section2 = pdf.Sections.Add();
Aspose.Pdf.Generator.Text txt = new Aspose.Pdf.Generator.Text(section, sHeaderFooter[0]);
Aspose.Pdf.Generator.Text txtFooter = new Aspose.Pdf.Generator.Text(section1, sHeaderFooter[1]);
txt.Margin.Top = ArMSReportConstants.PDFMarginTop;
txt.Margin.Left = ArMSReportConstants.PDFMarginLeft;
txt.TextInfo.FontSize = ArMSReportConstants.PDFTxtInfoFontSize;
txt.TextInfo.IsTrueTypeFontBold = true;
txt.TextInfo.FontName = ArMSReportConstants.FontArial;
txtFooter.Margin.Bottom = ArMSReportConstants.PDFFooterMarginBottom;
txtFooter.Margin.Top = ArMSReportConstants.PDFFooterMarginTop;
txtFooter.Margin.Left = ArMSReportConstants.PDFFooterMarginLeft;
txtFooter.TextInfo.FontSize = ArMSReportConstants.PDFFooterTxtInfoFontSize;
txtFooter.TextInfo.IsTrueTypeFontBold = true;
txtFooter.TextInfo.FontName = ArMSReportConstants.FontArial;
// Add text to footer section of the Pdf file
footer.Paragraphs.Add(txtFooter);
// Add text to Header section of the Pdf file
header.Paragraphs.Add(txt);
//Create text paragraphs containing HTML text
Aspose.Pdf.Generator.Text text2 = new Aspose.Pdf.Generator.Text(section, r.ReadToEnd());text2.IsHtmlTagSupported = true;
text2.TextInfo.FontSize = 8;
text2.TextInfo.FontName = ArMSReportConstants.FontArial;
text2.TextInfo.IsTrueTypeFontBold = true;
text2.IfHtmlTagSupportedOverwriteHtmlFontNames = true;
text2.IfHtmlTagSupportedOverwriteHtmlFontSizes = true;
if (string.Compare(sReportNumber, "07") == 0)
{
text2.TextInfo.IsTrueTypeFontBold = false;
}
if (string.Compare(sReportNumber, "05") == 0)
{
txt.TextInfo.FontSize = 7;
txt.TextInfo.IsTrueTypeFontBold = false;
header.Margin.Right = ArMSReportConstants.PdfHeaderMarginRight;
}
else if (string.Compare(sReportNumber, "01") == 0
|| string.Compare(sReportNumber, "02") == 0
|| string.Compare(sReportNumber, "03") == 0
|| string.Compare(sReportNumber, "04") == 0
|| string.Compare(sReportNumber, "06") == 0
|| string.Compare(sReportNumber, "08") == 0
|| string.Compare(sReportNumber, "10") == 0
|| string.Compare(sReportNumber, "11") == 0
|| string.Compare(sReportNumber, "13") == 0
|| string.Compare(sReportNumber, "14") == 0
|| string.Compare(sReportNumber, "15") == 0
|| string.Compare(sReportNumber, "16") == 0
|| string.Compare(sReportNumber, "17") == 0
|| string.Compare(sReportNumber, "19") == 0
|| string.Compare(sReportNumber, "20") == 0
)
{
text2.TextInfo.FontSize = 9;
}
section.Paragraphs.Add(text2);
response.ClearHeaders();
response.Clear();
response.ContentType = ArMSReportConstants.ContentTypePdf;
response.AppendHeader("Content-Disposition", "attachment; fileName= " + sFileName + ".pdf");
r.Close();
try
{
lock (_pdfLocker)
{
pdf.Save("E:\\test\\"+sFileName + ".pdf");
}
}
catch (Exception ex)
{
CustomExceptionHandler.WriteLog(HttpContext.Current.User.Identity.Name,"ReportsPDF - ExportToPDF - : Pdf Save" + readTemplate, ex);
}
response.TransmitFile("E:\\test\\" + sFileName + ".pdf");
response.OutputStream.Close();
response.End();
HttpContext.Current.ApplicationInstance.CompleteRequest();
}
#region Exceptions
catch (NotSupportedException notsupex)
{
CustomExceptionHandler.WriteLog(HttpContext.Current.User.Identity.Name,"ReportsPDF - ExportToPDF - Template : Not Supported Exception :", notsupex);
}
catch (UnauthorizedAccessException unauthex)
{
CustomExceptionHandler.WriteLog(HttpContext.Current.User.Identity.Name,"ReportsPDF - ExportToPDF - Template :Unauthorized access Exception :", unauthex);
}
catch (DirectoryNotFoundException direx)
{
CustomExceptionHandler.WriteLog(HttpContext.Current.User.Identity.Name,"ReportsPDF - ExportToPDF - Template : Directory not found Exception :", direx);
}
catch (ArgumentNullException argnull)
{
CustomExceptionHandler.WriteLog(HttpContext.Current.User.Identity.Name,"ReportsPDF - ExportToPDF - Template : Arguments Null Exception :", argnull);
}
catch (ArgumentOutOfRangeException argsoorex)
{
CustomExceptionHandler.WriteLog(HttpContext.Current.User.Identity.Name,"ReportsPDF - ExportToPDF - Template : Arguments Out of range Exception :", argsoorex);
}
catch (ArgumentException argex)
{
CustomExceptionHandler.WriteLog(HttpContext.Current.User.Identity.Name,"ReportsPDF - ExportToPDF - Template : Arguments Exception :", argex);
}
catch (PathTooLongException pathex)
{
CustomExceptionHandler.WriteLog(HttpContext.Current.User.Identity.Name,"ReportsPDF - ExportToPDF - Template : IO Path Too long Exception :", pathex);
}
catch (HttpException httpex)
{
CustomExceptionHandler.WriteLog(HttpContext.Current.User.Identity.Name,"ReportsPDF - ExportToPDF - Template : Http Exception :", httpex);
}
catch (Exception ex)
{
CustomExceptionHandler.WriteLog(HttpContext.Current.User.Identity.Name,"ReportsPDF - ExportToPDF - : Template Read ASPOSE API Issue - Can be ignored",ex);
throw;
}
finally
{
wordHeaderText1.Remove(0, wordHeaderText1.Length);
wordHeaderText2.Remove(0, wordHeaderText2.Length);
excelHeaderText.Remove(0, excelHeaderText.Length);
headerText.Remove(0, headerText.Length);
if (File.Exists(readTemplate))
{
File.Delete(readTemplate);
}
}
#endregion
}
Regards,
Manish
Hi Manish,
Thanks for sharing additional information. I have tested the scenario with Aspose.Pdf for NET 8.6.0 but I am getting an empty file instead any error. We have logged the issue in our bug tracking system as PDFNEWNET-36106 for further investigation and resolution. We will notify you via this thread as soon as it is resolved.
We are sorry for the inconvenience caused.
Best Regards,
Hi,
Lets assume you are not getting same error in logs which we are getting. Still this is your product. Could you let us know in what consitions this error would popup.
Also, please let me know following for test environment where you have tried replicating this issue:
(1) Operating System
(2) 32bits/64bits
(3) .Net framework
(4) IIS version
Regards,
Manish
Hi Manish,
The issues you have found earlier (filed as PDFNEWNET-36106) have been fixed in Aspose.Pdf for .NET 9.5.0.