Skip to content

Commit 5cc2f77

Browse files
author
Petri Roivas
committed
Fix pdf outline handling
1 parent 19b6c95 commit 5cc2f77

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

PdfSharpCore/Pdf/PdfArray.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#region PDFsharp - A .NET library for processing PDF
1+
#region PDFsharp - A .NET library for processing PDF
22
//
33
// Authors:
44
// Stefan Lange
@@ -213,7 +213,7 @@ public bool GetBoolean(int index)
213213
throw new ArgumentOutOfRangeException("index", index, PSSR.IndexOutOfRange);
214214

215215
object obj = this[index];
216-
if (obj == null)
216+
if (obj == null || obj is PdfNull)
217217
return false;
218218

219219
PdfBoolean boolean = obj as PdfBoolean;
@@ -239,7 +239,7 @@ public int GetInteger(int index)
239239
throw new ArgumentOutOfRangeException("index", index, PSSR.IndexOutOfRange);
240240

241241
object obj = this[index];
242-
if (obj == null)
242+
if (obj == null || obj is PdfNull)
243243
return 0;
244244

245245
PdfInteger integer = obj as PdfInteger;
@@ -265,7 +265,7 @@ public double GetReal(int index)
265265
throw new ArgumentOutOfRangeException("index", index, PSSR.IndexOutOfRange);
266266

267267
object obj = this[index];
268-
if (obj == null)
268+
if (obj == null || obj is PdfNull)
269269
return 0;
270270

271271
PdfReal real = obj as PdfReal;
@@ -299,7 +299,7 @@ public string GetString(int index)
299299
throw new ArgumentOutOfRangeException("index", index, PSSR.IndexOutOfRange);
300300

301301
object obj = this[index];
302-
if (obj == null)
302+
if (obj == null || obj is PdfNull)
303303
return String.Empty;
304304

305305
PdfString str = obj as PdfString;
@@ -325,7 +325,7 @@ public string GetName(int index)
325325
throw new ArgumentOutOfRangeException("index", index, PSSR.IndexOutOfRange);
326326

327327
object obj = this[index];
328-
if (obj == null)
328+
if (obj == null || obj is PdfNull)
329329
return String.Empty;
330330

331331
PdfName name = obj as PdfName;

PdfSharpCore/Pdf/PdfOutline.cs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#region PDFsharp - A .NET library for processing PDF
1+
#region PDFsharp - A .NET library for processing PDF
22
//
33
// Authors:
44
// Stefan Lange
@@ -354,11 +354,9 @@ void Initialize()
354354
PdfItem a = Elements.GetValue(Keys.A);
355355
Debug.Assert(dest == null || a == null, "Either destination or goto action.");
356356

357-
PdfArray destArray = null;
358357
if (dest != null)
359358
{
360-
destArray = dest as PdfArray;
361-
if (destArray != null)
359+
if (dest is PdfArray destArray)
362360
{
363361
SplitDestinationPage(destArray);
364362
}
@@ -374,14 +372,20 @@ void Initialize()
374372
if (action != null && action.Elements.GetName(PdfAction.Keys.S) == "/GoTo")
375373
{
376374
dest = action.Elements[PdfGoToAction.Keys.D];
377-
destArray = dest as PdfArray;
378-
if (destArray != null)
375+
if (dest is PdfArray destArray)
379376
{
380377
// Replace Action with /Dest entry.
381378
Elements.Remove(Keys.A);
382379
Elements.Add(Keys.Dest, destArray);
383380
SplitDestinationPage(destArray);
384381
}
382+
else if (dest is PdfReference detRef)
383+
{
384+
// Replace Action with /Dest entry.
385+
Elements.Remove(Keys.A);
386+
Elements.Add(Keys.Dest, detRef.Value);
387+
SplitDestinationPage((PdfArray)detRef.Value);
388+
}
385389
else
386390
{
387391
throw new Exception("Destination Array expected.");
@@ -732,14 +736,14 @@ internal sealed class Keys : KeysBase
732736

733737
/// <summary>
734738
/// (Required if the item has any descendants; must be an indirect reference)
735-
/// The first of this item’s immediate children in the outline hierarchy.
739+
/// The first of this items immediate children in the outline hierarchy.
736740
/// </summary>
737741
[KeyInfo(KeyType.Dictionary | KeyType.Required)]
738742
public const string First = "/First";
739743

740744
/// <summary>
741745
/// (Required if the item has any descendants; must be an indirect reference)
742-
/// The last of this item’s immediate children in the outline hierarchy.
746+
/// The last of this items immediate children in the outline hierarchy.
743747
/// </summary>
744748
[KeyInfo(KeyType.Dictionary | KeyType.Required)]
745749
public const string Last = "/Last";
@@ -780,15 +784,15 @@ internal sealed class Keys : KeysBase
780784

781785
/// <summary>
782786
/// (Optional; PDF 1.4) An array of three numbers in the range 0.0 to 1.0, representing the
783-
/// components in the DeviceRGB color space of the color to be used for the outline entry’s text.
787+
/// components in the DeviceRGB color space of the color to be used for the outline entrys text.
784788
/// Default value: [0.0 0.0 0.0].
785789
/// </summary>
786790
[KeyInfo(KeyType.Array | KeyType.Optional)]
787791
public const string C = "/C";
788792

789793
/// <summary>
790794
/// (Optional; PDF 1.4) A set of flags specifying style characteristics for displaying the outline
791-
/// item’s text. Default value: 0.
795+
/// items text. Default value: 0.
792796
/// </summary>
793797
[KeyInfo(KeyType.Integer | KeyType.Optional)]
794798
public const string F = "/F";

0 commit comments

Comments
 (0)