Support not finding the Pages dictionary in lenient mode

This commit is contained in:
Arnaud TAMAILLON 2024-09-01 14:34:00 +02:00
parent 1bfd6dedb4
commit 6eebb89579
2 changed files with 31 additions and 0 deletions

View File

@ -1,6 +1,8 @@
namespace UglyToad.PdfPig.Tests.Integration
{
using Annotations;
using PdfPig.Core;
using System.IO;
public class CatGeneticsTests
{
@ -39,5 +41,22 @@
}
}
}
[Fact]
public void CanSupportPageInformationNotFoundInLenientMode()
{
var path = IntegrationHelpers.GetSpecificTestDocumentPath("pages-indirect-to-null.pdf");
// Lenient Parsing On -> can process
using (var document = PdfDocument.Open(path))
{
// unable to parse
Assert.Equal(1, document.NumberOfPages);
Assert.NotNull(document.GetPage(1));
}
// Lenient Parsing Off -> throws
var ex = Assert.Throws<PdfDocumentFormatException>(() => PdfDocument.Open(path, ParsingOptions.LenientParsingOff));
Assert.Equal("Pages entry is null", ex.Message);
}
}
}

View File

@ -46,6 +46,18 @@
pagesDictionary = DirectObjectFinder.Get<DictionaryToken>(value, scanner);
}
if (pagesDictionary == null)
{
if (isLenientParsing)
{
pagesDictionary = new DictionaryToken(new Dictionary<NameToken, IToken>());
}
else
{
throw new PdfDocumentFormatException($"Pages entry is null");
}
}
var pages = PagesFactory.Create(pagesReference, pagesDictionary, scanner, pageFactory, log, isLenientParsing);
var namedDestinations = NamedDestinationsProvider.Read(dictionary, scanner, pages, null);