Skip to content

Commit

Permalink
Default page number to 0 in ExplicitDestination when the Dest has no …
Browse files Browse the repository at this point in the history
…page number and fix #736
  • Loading branch information
BobLd committed Oct 25, 2024
1 parent e10609e commit 40af401
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
Binary file not shown.
13 changes: 13 additions & 0 deletions src/UglyToad.PdfPig.Tests/Integration/GithubIssuesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@

public class GithubIssuesTests
{
[Fact]
public void Issue736()
{
var doc = IntegrationHelpers.GetDocumentPath("Approved_Document_B__fire_safety__volume_2_-_Buildings_other_than_dwellings__2019_edition_incorporating_2020_and_2022_amendments.pdf");

using (var document = PdfDocument.Open(doc, new ParsingOptions() { UseLenientParsing = true, SkipMissingFonts = true }))
{
Assert.True(document.TryGetBookmarks(out var bookmarks));
Assert.Single(bookmarks.Roots);
Assert.Equal(36, bookmarks.Roots[0].Children.Count);
}
}

[Fact]
public void Issue693()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class ExplicitDestination
{
/// <summary>
/// The page number (1-based) of the destination.
/// <para>A value of <c>0</c> means no page destination was available (i.e. an invalid explicit destination).</para>
/// </summary>
public int PageNumber { get; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,19 @@ internal static bool TryGetExplicitDestination(
}
else
{
var errorMessage = $"{nameof(TryGetExplicitDestination)} No page number given in 'Dest': '{explicitDestinationArray}'.";
var errorMessage = $"{nameof(TryGetExplicitDestination)} No page number given in 'Dest': '{explicitDestinationArray}', defaulting to 0.";

log?.Error(errorMessage);

return false;
pageNumber = 0;
}

NameToken? destTypeToken = null;
if (explicitDestinationArray.Length > 1)
{
destTypeToken = explicitDestinationArray[1] as NameToken;
}

if (destTypeToken is null)
{
var errorMessage = $"Missing name token as second argument to explicit destination: {explicitDestinationArray}.";
Expand Down

0 comments on commit 40af401

Please sign in to comment.