This commit is contained in:
BobLd
2025-04-20 18:03:04 +01:00
parent 580858348b
commit afdd1f8924
3 changed files with 37 additions and 2 deletions
@@ -7,6 +7,29 @@
public class GithubIssuesTests
{
[Fact]
public void Issue1013()
{
// NB: We actually do not fix issue 953 here, but another bug found with the same document.
var path = IntegrationHelpers.GetSpecificTestDocumentPath("document_with_failed_fonts.pdf");
// Lenient parsing ON + Skip missing fonts
using (var document = PdfDocument.Open(path, new ParsingOptions() { UseLenientParsing = true, SkipMissingFonts = true }))
{
var page2 = document.GetPage(2);
Assert.NotEmpty(page2.Letters);
var words2 = NearestNeighbourWordExtractor.Instance.GetWords(page2.Letters).ToArray();
Assert.Equal("Doplňující", words2[0].Text);
var page3 = document.GetPage(3);
Assert.NotEmpty(page3.Letters);
var words3 = NearestNeighbourWordExtractor.Instance.GetWords(page3.Letters).ToArray();
Assert.Equal("Vinohradská", words3[8].Text);
}
}
[Fact]
public void Issue1016()
{
@@ -835,11 +835,13 @@
}
if (!stream.StreamDictionary.TryGet(NameToken.First, out var firstToken)
|| !(firstToken is NumericToken))
|| !(firstToken is NumericToken firstTokenNum))
{
throw new PdfDocumentFormatException($"Object stream dictionary did not provide first object offset {stream.StreamDictionary}.");
}
long firstTokenOffset = firstTokenNum.Long;
// Read the N integers
var bytes = new MemoryInputBytes(stream.Decode(filterProvider, this));
@@ -854,7 +856,7 @@
scanner.MoveNext();
var byteOffset = (NumericToken)scanner.CurrentToken;
objects.Add((objectNumber.Long, byteOffset.Long));
objects.Add((objectNumber.Long, firstTokenOffset + byteOffset.Long));
}
var results = new List<ObjectToken>();
@@ -863,6 +865,16 @@
{
var obj = objects[i];
// Check item offset is in [currentPosition - 1; currentPosition + 1]
bool isBetween = ((obj.Item2 - (scanner.CurrentPosition - 1)) | ((scanner.CurrentPosition + 1) - obj.Item2)) >= 0;
if (!isBetween)
{
// TODO - Not sure if it belongs here but fixes issue 1013.
// It is not clear what happens with this specific document 'document_with_failed_fonts.pdf'
// I could not find where the same logic is applied in pdfbox.
scanner.Seek(obj.Item2);
}
scanner.MoveNext();
var token = scanner.CurrentToken;