Issue with HTML to PDF conversion for large HTML

Hi,


We are getting following issue while we are converting large HTML files to PDF using Aspose PDF.
We are using 8.5.0.0 version of Aspose.PDF dlls.

Logging started
28/11/2013 10:46:46 AM Error : System.Threading.ThreadAbortExceptionThread was being aborted.Inner:StackTrace: at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length, Boolean reliable)
at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length)
at System.SZArrayHelper.CopyTo[T](T[] array, Int32 index)
at System.Collections.Generic.List1.InsertRange(Int32 index, IEnumerable1 collection)
at System.Collections.Generic.List1.AddRange(IEnumerable1 collection)
at „..“()
at „..”()
at „..“()
at ‹.…ctor()
at Ž.•.“( )
at ‹..“(a )
at ‹..“( , )
at ‹..“( )
at ‹..“( , )
at .’.“(& , , , String& , String& , String& )
at .’.“(& , , )
at .—.“( , )
at .—.“( , )
at .—.“( , )
at .—.“( , )
at .—.“( , )
at .—.(String )
at ..“(String )
at .—.“(String , Pdf , Section , Text )
at .—.“(Pdf , Section , Text , Cell , HeaderFooter , ˆ )
at .—.“(Pdf , Section , Table , Cell , Text , HeaderFooter , e , ˆ )
at .™.“(Pdf , Section , HeaderFooter , Table , Row , Cell , Text , e , ˆ , Boolean )
at ..“(Pdf , Section , e )
at ..“(Pdf )
at ..“( , Pdf )
at Aspose.Pdf.Generator.Pdf.Save(Stream stream)
at ArmsRepository.ARMSReportHelper.ExportToPDF(String readTemplate, HttpResponse response, String[] sHeaderFooter, String sReportNumber, String sUserID)
Logging ended

Please suggest if there is any fix for this issue.


Regards,
Manish Verma

Hi Manish,


Thanks for contacting support.

Can you please share the source HTML file so that we can test the scenario at our end. We are sorry for this inconvenience.

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,


Thanks for sharing the details.

In our earlier attempt, we have tried replicating the issue over Windows 7 and as per our observations, OutOfMemoryException is being generated when trying to convert HTML file to PDF format. However we will definitely consider the error which you have been facing and will try our level best to investigate the problem with that perspective. The development team will further look into the details of these problems and we will keep you posted on the status of correction. Please be patient and spare us little time.

The issues you have found earlier (filed as PDFNEWNET-36106) have been fixed in Aspose.Pdf for .NET 9.5.0.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.