------------------------------
Program Location:
at GemBox.Document.PdfLoadOptions.7k4lmxmhj5tk8h83eglk6fss34tasuhn (Stream , String )
at GemBox.Document.DocumentModel.Load(Stream stream)
===================================
Input string was not in a correct format. (mscorlib)
------------------------------
Program Location:
at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
at . ()
at .()
at .( )
at .(PdfArray , Boolean )
at .( )
at .( , Boolean )
at .(PdfReferenceTable )
at .()
at .(Stream , String , , )
at GemBox.Document.PdfLoadOptions.7k4lmxmhj5tk8h83eglk6fss34tasuhn (Stream , String )
Any clues what could be the source of these random exceptions?
class Program
{
static DocumentModel _LoadPdfFile(string path, string password = null)
{
using (MemoryStream outputPdfStream = new MemoryStream())
{
PdfDocument pdfDocument = password == null ?
PdfDocument.Load(path, new GemBox.Pdf.PdfLoadOptions()) :
PdfDocument.Load(path, new GemBox.Pdf.PdfLoadOptions {Password = password});
pdfDocument.SaveOptions.CrossReferenceType = PdfCrossReferenceType.Table;
pdfDocument.SaveOptions.Encryption = null;
pdfDocument.Save(outputPdfStream);
return DocumentModel.Load(outputPdfStream);
}
}
static void Main()
{
GemBox.Pdf.ComponentInfo.SetLicense("FREE-LIMITED-KEY");
GemBox.Document.ComponentInfo.SetLicense("FREE-LIMITED-KEY");
GemBox.Pdf.ComponentInfo.FreeLimitReached += (sender, e) =>
e.FreeLimitReachedAction = GemBox.Pdf.FreeLimitReachedAction.Stop;
GemBox.Document.ComponentInfo.FreeLimitReached += (sender, e) =>
e.FreeLimitReachedAction = GemBox.Document.FreeLimitReachedAction.Stop;
for (int i = 0; i < 100; i++)
{
try
{
_LoadPdfFile(@"CustomInvoice.pdf");
}
catch (Exception e)
{
Console.WriteLine("Failed at iteration " + i);
Console.WriteLine(e);
}
}
Console.Read();
}
}
NOTE: If I do just DocumentModel.Load(path) without doing pdfDocument.SaveOptions.CrossReferenceType = PdfCrossReferenceType.Table; it seems to work fine.
It happens both with CustomInvoice.pdf (from your examples at /document/examples/c-sharp-read-extract-pdf-text/305 ) and another random PDF file I’ve tried.