System.ArgumentOutOfRangeException: Length cannot be less than zero

Hi,

I am getting the following error:

Exception: System.ArgumentOutOfRangeException: Length cannot be less than zero.
Parameter name: length
at System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy)
at ..( , String , Single , Int32 , Single , Boolean )
at .?.(Text text, Pdf doc, tempGen, Single maxSizeWithoutInline, assignInfo, Cell cell, Section currentPart, Table table, Int32 index, Segment currentSegment, Single textHeightByNow, Int32 font, Boolean& isFirstLine, Single bakcurpos, Int32& startSegIndex, Single& maxSize, Boolean& needReprocessForPageNumber, Row row, Single descender, Int32 breakSegIndex, Int32 wrapCount)
at .?.(Text , Pdf , , Single , , Cell , Single , Section , Table , Int32 , Segment , Single , Int32 , Boolean& , Single& , String ,  , String , Boolean , Single , Int32& , Single& , Boolean& , Row , Single , Int32 , Int32 )
at .?.(Pdf , Section , Table , Row , Cell , Text , , , Boolean )
at ..(Pdf , Section , HeaderFooter , Table , Row , Cell , Text , , , Boolean )
at ..(Pdf , Section , )
at .?.(Pdf )
at .?.( , Pdf )
at Aspose.Pdf.Generator.Pdf.Save(Stream stream)
at Aspose.Pdf.Document.(Pdf )
at Aspose.Pdf.Document…ctor(Pdf pdf)


I need to clear it with our client before I post the data.

The file is an htm file, here it is zipped and attached.

Hi there,


Thanks for sharing source file. I’m afraid, I see junk data except couple of starting paragraphs in your file and an empty PDF document is being generated. Are you getting issue with this specific file or also with others? It would help us to investigate the issue if you please share your sample code, some other source documents and confirm your Aspose.Pdf DLL version as well.

Sorry for the inconvenience faced.

Best Regards,

Hi

We are using Aspose PDF version 7.0
We haven’t had any problems with other files, just this one that generates the error shown.

Here is the code we are using:

public override bool CreateTiff(string pInputFile, string pOutputFile, out int pNumPages)
{
bool success = true;
pNumPages = 0;

try
{
InitializeTiffer(pInputFile, pOutputFile);

//Instantiate Pdf pbject by calling its empty constructor
Aspose.Pdf.Generator.Pdf pdfGenerator = new Aspose.Pdf.Generator.Pdf();
//Create a new section in the Pdf object
Aspose.Pdf.Generator.Section sec1 = pdfGenerator.Sections.Add();

using (System.IO.TextReader objReader = new System.IO.StreamReader(InputFilePath))
{
// Read the file till the end of the file has come
do
{
//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();
}

// Load the MHTML stream using Aspose.Words for .NET
using (Document pdfDocument = new Document(pdfGenerator))
{

if (TiffOptions.SaveAsPdf)
success = CreatePdfFromPdfDocument(pdfDocument, out pNumPages);
else
success = CreateTiffFromPdfDocument(pdfDocument, out pNumPages);
}
}
catch (Exception ex)
{
log.ErrorFormat(“Failed to convert Text file {0} to TIFF.\nException: {1}”, InputFilePath, ex);
new UnsupportedTiffer().CreateTiff(InputFilePath, OutputFilePath, TiffOptions, out pNumPages);
success = false;
}

return success;
}







Hi there,


Thanks for your feedback. While testing your sample code with latest Aspose.Pdf for .NET 8.0 API, I’m unable to get any exception but an empty PDF file is being is generated. I’ve logged issue as PDFNEWNET-35278 in our issue tracking system for further investigation and resolution. We will update you as soon as it is resolved.

Meanwhile, can you please download and try latest Aspose.Pdf for .NET API and share the results?

Sorry for the inconvenience faced.

Best Regards,

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


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