mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-08-20 09:37:44 +08:00
Support not finding the Pages dictionary in lenient mode
This commit is contained in:
parent
1bfd6dedb4
commit
6eebb89579
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user