diff --git a/.editorconfig b/.editorconfig
index 9c972d0..d3e9812 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -11,7 +11,7 @@ insert_final_newline = true
[*.cs]
dotnet_diagnostic.IDE0008.severity = none # use explicit type instead of var
dotnet_diagnostic.IDE0011.severity = none # add braces to 'if' statement
-dotnet_diagnostic.IDE0005.severity = suggestion # using directive is unnecessary
+dotnet_diagnostic.IDE0005.severity = error # using directive is unnecessary
dotnet_diagnostic.IDE0049.severity = suggestion # name can be simplified
dotnet_diagnostic.IDE0055.severity = suggestion # fix formatting
dotnet_diagnostic.IDE0130.severity = error # namespace match directory structure
diff --git a/Directory.Build.props b/Directory.Build.props
new file mode 100644
index 0000000..efd8a45
--- /dev/null
+++ b/Directory.Build.props
@@ -0,0 +1,11 @@
+
+
+ true
+
+ true
+
+
+
+ CA1819;CA1720;CS1591
+
+
diff --git a/LICENSE.md b/LICENSE.md
index 7053b45..e6bd3f6 100644
--- a/LICENSE.md
+++ b/LICENSE.md
@@ -1,6 +1,6 @@
Unless otherwise stated in the source file, the code is release under the MIT License
-Copyright (c) 2011-2024 SafeRapidPdf contributors
+Copyright (c) 2011-2026 SafeRapidPdf contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/PdfInfoTool/Command/Show.cs b/PdfInfoTool/Command/Show.cs
index 33de650..3a10878 100644
--- a/PdfInfoTool/Command/Show.cs
+++ b/PdfInfoTool/Command/Show.cs
@@ -68,10 +68,12 @@ internal static int RunShowAndReturnExitCode(ShowOptions opts)
type = objectType.ToString();
}
}
- catch
+#pragma warning disable CA1031 // Intentional: swallow all parsing errors for this CLI diagnostic tool
+ catch (Exception)
{
type = $"Not found {o} {g}";
}
+#pragma warning restore CA1031
}
Console.WriteLine($"{obj}: {entry} - {type}");
diff --git a/PdfInfoTool/Options.cs b/PdfInfoTool/Options.cs
index 6c7bc91..61d9de5 100644
--- a/PdfInfoTool/Options.cs
+++ b/PdfInfoTool/Options.cs
@@ -20,7 +20,9 @@ internal interface IOptions
}
[Verb("dump", HelpText = "Dump an object out.")]
-internal class DumpOptions : IOptions
+#pragma warning disable CA1812 // Instantiated by CommandLineParser via reflection
+internal sealed class DumpOptions : IOptions
+#pragma warning restore CA1812
{
public bool Verbose { get; set; }
public bool Quiet { get; set; }
@@ -28,7 +30,9 @@ internal class DumpOptions : IOptions
}
[Verb("show", HelpText = "Show object contents in a human readable way.")]
-internal class ShowOptions : IOptions
+#pragma warning disable CA1812 // Instantiated by CommandLineParser via reflection
+internal sealed class ShowOptions : IOptions
+#pragma warning restore CA1812
{
public bool Verbose { get; set; }
public bool Quiet { get; set; }
diff --git a/SafeRapidPdf.UnitTests/File/PdfFileTests.cs b/SafeRapidPdf.UnitTests/File/PdfFileTests.cs
index 1c0755a..6217dae 100644
--- a/SafeRapidPdf.UnitTests/File/PdfFileTests.cs
+++ b/SafeRapidPdf.UnitTests/File/PdfFileTests.cs
@@ -19,7 +19,7 @@ public class PdfFileTests
public void Parsing_TinyFile(string pdf)
{
var r = PdfFile.Parse(pdf.ToStream());
- Assert.True(r.Items.Count == 3);
+ Assert.Equal(3, r.Items.Count);
}
[Theory]
diff --git a/SafeRapidPdf.UnitTests/File/PdfXRefTests.cs b/SafeRapidPdf.UnitTests/File/PdfXRefTests.cs
index 2c20ce0..532bee0 100644
--- a/SafeRapidPdf.UnitTests/File/PdfXRefTests.cs
+++ b/SafeRapidPdf.UnitTests/File/PdfXRefTests.cs
@@ -22,8 +22,7 @@ public void Parsing_Uncompressed_XRef(string xref)
{
var r = PdfXRef.Parse(xref.ToLexer());
// 1 section
- Assert.Equal(1, r.Items.Count);
- var s = r.Items[0] as PdfXRefSection;
+ var s = Assert.Single(r.Items) as PdfXRefSection;
// 6 entries
Assert.Equal(6, s.Items.Count);
}
@@ -65,7 +64,7 @@ public void Parsing_CompressedXRef()
// W[1 3 1] (5 columns, larger indexes)
// needed to resolve the values for refs encoded with 2
- var base64Object706 = @"NzA2IDAgb2JqDTw8L0ZpbHRlci9GbGF0ZURlY29kZS9GaXJzdCAzMC9MZW5ndGggMTkzL04gNC9U
+ _ = @"NzA2IDAgb2JqDTw8L0ZpbHRlci9GbGF0ZURlY29kZS9GaXJzdCAzMC9MZW5ndGggMTkzL04gNC9U
eXBlL09ialN0bT4+c3RyZWFtDQpo3kSOwQ6CMBBEf2W/wG0BARPSRFAJBwKxHkwIh1qrUcES6EH/
3gIaTzO78zKZgDpAIKAuUOpZ9YC6rtUlUD+EKMJEN7rnnZBqPAZ/YgnsrQ8n3nrGcPsyKTfCjFTK
6dQwJ2WvJVemwnKzw6wVVxXXeCxOdyWNhbN2hMkMM1ZhliSxGNQZAhKO37pCrjrRC3PTT4wbIR+/
diff --git a/SafeRapidPdf.UnitTests/SafeRapidPdf.UnitTests.csproj b/SafeRapidPdf.UnitTests/SafeRapidPdf.UnitTests.csproj
index e2ba1ec..89bba1e 100644
--- a/SafeRapidPdf.UnitTests/SafeRapidPdf.UnitTests.csproj
+++ b/SafeRapidPdf.UnitTests/SafeRapidPdf.UnitTests.csproj
@@ -17,7 +17,12 @@
all
+
+
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+ all
+
all
runtime; build; native; contentfiles; analyzers
diff --git a/SafeRapidPdf.UnitTests/Util/StringExtensions.cs b/SafeRapidPdf.UnitTests/Util/StringExtensions.cs
index 21016ea..1b35927 100644
--- a/SafeRapidPdf.UnitTests/Util/StringExtensions.cs
+++ b/SafeRapidPdf.UnitTests/Util/StringExtensions.cs
@@ -6,7 +6,7 @@
namespace SafeRapidPdf.UnitTests.Util;
-public static class StringExtensions
+internal static class StringExtensions
{
public static Stream ToStream(this string input)
{
@@ -36,7 +36,7 @@ public static Lexer Base64ToLexer(this string input)
public static string ToHexString(this byte[] ba)
{
- if (ba == null) throw new ArgumentNullException(nameof(ba));
+ ArgumentNullException.ThrowIfNull(ba);
var hex = new StringBuilder(ba.Length * 2);
foreach (byte b in ba)
diff --git a/SafeRapidPdf/Attributes/ParameterTypeAttribute.cs b/SafeRapidPdf/Attributes/ParameterTypeAttribute.cs
index b7de95a..477b791 100644
--- a/SafeRapidPdf/Attributes/ParameterTypeAttribute.cs
+++ b/SafeRapidPdf/Attributes/ParameterTypeAttribute.cs
@@ -1,37 +1,29 @@
namespace SafeRapidPdf.Attributes;
[AttributeUsage(AttributeTargets.Property)]
-public sealed class ParameterTypeAttribute : Attribute
+public sealed class ParameterTypeAttribute(
+ bool required,
+ bool inheritable = false,
+ string version = "",
+ bool obsolete = false) : Attribute
{
- public ParameterTypeAttribute(
- bool required,
- bool inheritable = false,
- string version = "",
- bool obsolete = false)
- {
- Required = required;
- Inheritable = inheritable;
- Version = version;
- Obsolete = obsolete;
- }
-
///
/// Required or Optional
///
- public bool Required { get; }
+ public bool Required { get; } = required;
///
/// Inheritable attribute
///
- public bool Inheritable { get; }
+ public bool Inheritable { get; } = inheritable;
///
/// PDF version from which this parameter is allowed
///
- public string Version { get; }
+ public string Version { get; } = version;
///
/// Was this parameter obsoleted?
///
- public bool Obsolete { get; }
+ public bool Obsolete { get; } = obsolete;
}
diff --git a/SafeRapidPdf/Document/PdfArtBox.cs b/SafeRapidPdf/Document/PdfArtBox.cs
index af20543..c1f2ef1 100644
--- a/SafeRapidPdf/Document/PdfArtBox.cs
+++ b/SafeRapidPdf/Document/PdfArtBox.cs
@@ -5,10 +5,6 @@ namespace SafeRapidPdf.Document;
///
/// Extent of the page’s meaningful content
///
-public sealed class PdfArtBox : PdfRectangle
+public sealed class PdfArtBox(PdfArray box) : PdfRectangle(PdfObjectType.ArtBox, box)
{
- public PdfArtBox(PdfArray box)
- : base(PdfObjectType.ArtBox, box)
- {
- }
}
diff --git a/SafeRapidPdf/Document/PdfBaseObject.cs b/SafeRapidPdf/Document/PdfBaseObject.cs
index 2c994bb..50f2930 100644
--- a/SafeRapidPdf/Document/PdfBaseObject.cs
+++ b/SafeRapidPdf/Document/PdfBaseObject.cs
@@ -1,13 +1,8 @@
namespace SafeRapidPdf.Document;
-public abstract class PdfBaseObject : IPdfObject
+public abstract class PdfBaseObject(PdfObjectType type) : IPdfObject
{
- protected PdfBaseObject(PdfObjectType type)
- {
- ObjectType = type;
- }
-
- public PdfObjectType ObjectType { get; }
+ public PdfObjectType ObjectType { get; } = type;
public bool IsContainer { get; protected set; }
@@ -16,5 +11,5 @@ protected PdfBaseObject(PdfObjectType type)
public virtual IReadOnlyList Items
=> !IsContainer
? null
- : throw new NotImplementedException();
+ : throw new InvalidOperationException("Subclass must override Items when IsContainer is true.");
}
diff --git a/SafeRapidPdf/Document/PdfBleedBox.cs b/SafeRapidPdf/Document/PdfBleedBox.cs
index d580962..cedd045 100644
--- a/SafeRapidPdf/Document/PdfBleedBox.cs
+++ b/SafeRapidPdf/Document/PdfBleedBox.cs
@@ -6,10 +6,6 @@ namespace SafeRapidPdf.Document;
/// region to which the contents of the page should be clipped
/// when output in a production environment
///
-public sealed class PdfBleedBox : PdfRectangle
+public sealed class PdfBleedBox(PdfArray box) : PdfRectangle(PdfObjectType.BleedBox, box)
{
- public PdfBleedBox(PdfArray box)
- : base(PdfObjectType.BleedBox, box)
- {
- }
}
diff --git a/SafeRapidPdf/Document/PdfCatalog.cs b/SafeRapidPdf/Document/PdfCatalog.cs
index fcc3838..d8da681 100644
--- a/SafeRapidPdf/Document/PdfCatalog.cs
+++ b/SafeRapidPdf/Document/PdfCatalog.cs
@@ -6,7 +6,7 @@ namespace SafeRapidPdf.Document;
public sealed class PdfCatalog : PdfBaseObject
{
- private readonly List _items = new();
+ private readonly List _items = [];
public PdfCatalog(PdfDictionary catalog)
: base(PdfObjectType.Catalog)
diff --git a/SafeRapidPdf/Document/PdfCropBox.cs b/SafeRapidPdf/Document/PdfCropBox.cs
index 2205ea5..772287f 100644
--- a/SafeRapidPdf/Document/PdfCropBox.cs
+++ b/SafeRapidPdf/Document/PdfCropBox.cs
@@ -5,10 +5,6 @@ namespace SafeRapidPdf.Document;
///
/// visible region of default user space
///
-public sealed class PdfCropBox : PdfRectangle
+public sealed class PdfCropBox(PdfArray box) : PdfRectangle(PdfObjectType.CropBox, box)
{
- public PdfCropBox(PdfArray box)
- : base(PdfObjectType.CropBox, box)
- {
- }
}
diff --git a/SafeRapidPdf/Document/PdfMediaBox.cs b/SafeRapidPdf/Document/PdfMediaBox.cs
index f2d251a..dd6b1af 100644
--- a/SafeRapidPdf/Document/PdfMediaBox.cs
+++ b/SafeRapidPdf/Document/PdfMediaBox.cs
@@ -6,10 +6,6 @@ namespace SafeRapidPdf.Document;
/// boundaries of the physical medium on which the page is
/// intended to be displayed or printed
///
-public sealed class PdfMediaBox : PdfRectangle
+public sealed class PdfMediaBox(PdfArray box) : PdfRectangle(PdfObjectType.MediaBox, box)
{
- public PdfMediaBox(PdfArray box)
- : base(PdfObjectType.MediaBox, box)
- {
- }
}
diff --git a/SafeRapidPdf/Document/PdfPage.cs b/SafeRapidPdf/Document/PdfPage.cs
index 7cd0627..25f7eed 100644
--- a/SafeRapidPdf/Document/PdfPage.cs
+++ b/SafeRapidPdf/Document/PdfPage.cs
@@ -1,4 +1,5 @@
using System.IO;
+using System.Linq;
using SafeRapidPdf.Attributes;
using SafeRapidPdf.Objects;
@@ -7,7 +8,7 @@ namespace SafeRapidPdf.Document;
public class PdfPage : PdfBaseObject
{
- private readonly List _items = new();
+ private readonly List _items = [];
public PdfPage(PdfIndirectReference pages, PdfPageTree parent)
: this(pages, parent, PdfObjectType.Page)
@@ -20,7 +21,7 @@ public PdfPage(PdfIndirectReference pages, PdfPageTree parent)
page.ExpectsType("Page");
- foreach (PdfKeyValuePair pair in page.Items)
+ foreach (PdfKeyValuePair pair in page.Items.Cast())
{
HandleKeyValuePair(pair);
}
diff --git a/SafeRapidPdf/Document/PdfPageTree.cs b/SafeRapidPdf/Document/PdfPageTree.cs
index b921c28..79536e9 100644
--- a/SafeRapidPdf/Document/PdfPageTree.cs
+++ b/SafeRapidPdf/Document/PdfPageTree.cs
@@ -1,4 +1,5 @@
using System.IO;
+using System.Linq;
using SafeRapidPdf.Attributes;
using SafeRapidPdf.Objects;
@@ -21,7 +22,7 @@ public PdfPageTree(PdfIndirectReference pages, PdfPageTree parent)
var pageTree = pages.Dereference();
pageTree.ExpectsType("Pages");
- foreach (PdfKeyValuePair pair in pageTree.Items)
+ foreach (PdfKeyValuePair pair in pageTree.Items.Cast())
{
switch (pair.Key.Text)
{
@@ -29,8 +30,8 @@ public PdfPageTree(PdfIndirectReference pages, PdfPageTree parent)
break;
case "Kids":
var kids = (PdfArray)pair.Value;
- Kids = new List();
- foreach (PdfIndirectReference item in kids.Items)
+ Kids = [];
+ foreach (PdfIndirectReference item in kids.Items.Cast())
{
var dic = item.Dereference();
string type = dic["Type"].Text;
diff --git a/SafeRapidPdf/Document/PdfTrimBox.cs b/SafeRapidPdf/Document/PdfTrimBox.cs
index 140c9e2..4bfbdbe 100644
--- a/SafeRapidPdf/Document/PdfTrimBox.cs
+++ b/SafeRapidPdf/Document/PdfTrimBox.cs
@@ -5,10 +5,6 @@ namespace SafeRapidPdf.Document;
///
/// intended dimensions of the finished page after trimming
///
-public sealed class PdfTrimBox : PdfRectangle
+public sealed class PdfTrimBox(PdfArray box) : PdfRectangle(PdfObjectType.TrimBox, box)
{
- public PdfTrimBox(PdfArray box)
- : base(PdfObjectType.TrimBox, box)
- {
- }
}
diff --git a/SafeRapidPdf/IPdfObject.cs b/SafeRapidPdf/IPdfObject.cs
index d7ad976..54b39ce 100644
--- a/SafeRapidPdf/IPdfObject.cs
+++ b/SafeRapidPdf/IPdfObject.cs
@@ -1,5 +1,4 @@
-using System.Collections.Generic;
-
+
namespace SafeRapidPdf;
///
diff --git a/SafeRapidPdf/Objects/PdfFile.cs b/SafeRapidPdf/Objects/PdfFile.cs
index e129164..6b4848f 100644
--- a/SafeRapidPdf/Objects/PdfFile.cs
+++ b/SafeRapidPdf/Objects/PdfFile.cs
@@ -22,7 +22,7 @@ private PdfFile(IReadOnlyList objects)
Items = objects;
// build up the fast object lookup dictionary
- _indirectObjects = new Dictionary();
+ _indirectObjects = [];
foreach (var obj in Items.OfType())
{
diff --git a/SafeRapidPdf/Objects/PdfIndirectObject.cs b/SafeRapidPdf/Objects/PdfIndirectObject.cs
index 9044ea1..179d470 100644
--- a/SafeRapidPdf/Objects/PdfIndirectObject.cs
+++ b/SafeRapidPdf/Objects/PdfIndirectObject.cs
@@ -1,4 +1,3 @@
-using System.Collections.Generic;
using System.Globalization;
using SafeRapidPdf.Parsing;
@@ -22,7 +21,7 @@ private PdfIndirectObject(int objectNumber, int generationNumber, IPdfObject obj
public IPdfObject Object { get; }
- public override IReadOnlyList Items => new[] { Object };
+ public override IReadOnlyList Items => [Object];
internal static PdfIndirectObject Parse(Lexer lexer)
{
diff --git a/SafeRapidPdf/Objects/PdfKeyValuePair.cs b/SafeRapidPdf/Objects/PdfKeyValuePair.cs
index 17b3a78..60adc7b 100644
--- a/SafeRapidPdf/Objects/PdfKeyValuePair.cs
+++ b/SafeRapidPdf/Objects/PdfKeyValuePair.cs
@@ -1,5 +1,4 @@
-using System.Collections.Generic;
-
+
namespace SafeRapidPdf.Objects;
///
@@ -20,7 +19,7 @@ public PdfKeyValuePair(PdfName key, PdfObject value)
public PdfObject Value { get; }
- public override IReadOnlyList Items => new[] { Value };
+ public override IReadOnlyList Items => [Value];
public override string ToString()
{
diff --git a/SafeRapidPdf/Objects/PdfName.cs b/SafeRapidPdf/Objects/PdfName.cs
index 9a8a39b..cfe6a36 100644
--- a/SafeRapidPdf/Objects/PdfName.cs
+++ b/SafeRapidPdf/Objects/PdfName.cs
@@ -2,19 +2,22 @@
namespace SafeRapidPdf.Objects;
-public sealed class PdfName : PdfObject
+public sealed partial class PdfName : PdfObject
{
- private readonly string _rawName;
-
private PdfName(string name)
: base(PdfObjectType.Name)
{
- _rawName = name;
+ RawName = name;
}
+ private string RawName { get; }
+
+ [GeneratedRegex(@"#(\d\d)")]
+ private static partial Regex HexEncodedCharRegex();
+
public string Name
// process the # encoded chars
- => Regex.Replace(_rawName, @"#(\d\d)", x =>
+ => HexEncodedCharRegex().Replace(RawName, x =>
{
byte val = Convert.ToByte(x.Groups[1].Value, 16);
return ((char)val).ToString();
diff --git a/SafeRapidPdf/Objects/PdfObject.cs b/SafeRapidPdf/Objects/PdfObject.cs
index 9c677d6..08c3b83 100644
--- a/SafeRapidPdf/Objects/PdfObject.cs
+++ b/SafeRapidPdf/Objects/PdfObject.cs
@@ -4,14 +4,9 @@
namespace SafeRapidPdf.Objects;
-public abstract class PdfObject : IPdfObject
+public abstract class PdfObject(PdfObjectType type) : IPdfObject
{
- protected PdfObject(PdfObjectType type)
- {
- ObjectType = type;
- }
-
- public PdfObjectType ObjectType { get; }
+ public PdfObjectType ObjectType { get; } = type;
public bool IsContainer { get; protected set; }
@@ -20,7 +15,7 @@ protected PdfObject(PdfObjectType type)
public virtual IReadOnlyList Items
=> !IsContainer
? null
- : throw new NotImplementedException();
+ : throw new InvalidOperationException("Subclass must override Items when IsContainer is true.");
internal static PdfObject ParseAny(Lexer lexer)
{
diff --git a/SafeRapidPdf/Objects/PdfStartXRef.cs b/SafeRapidPdf/Objects/PdfStartXRef.cs
index f96f1f9..4ea4b65 100644
--- a/SafeRapidPdf/Objects/PdfStartXRef.cs
+++ b/SafeRapidPdf/Objects/PdfStartXRef.cs
@@ -13,7 +13,7 @@ private PdfStartXRef(PdfNumeric value)
public PdfNumeric Numeric { get; }
- public override IReadOnlyList Items => new[] { Numeric };
+ public override IReadOnlyList Items => [Numeric];
public static PdfStartXRef Parse(Lexer lexer)
{
diff --git a/SafeRapidPdf/Objects/PdfStream.cs b/SafeRapidPdf/Objects/PdfStream.cs
index 121ae2e..2e48a29 100644
--- a/SafeRapidPdf/Objects/PdfStream.cs
+++ b/SafeRapidPdf/Objects/PdfStream.cs
@@ -21,24 +21,16 @@ private PdfStream(PdfDictionary dictionary, PdfData data)
public PdfData Data { get; }
public override IReadOnlyList Items
- {
- get
- {
- var list = new List(StreamDictionary.Items.Count + 1);
- list.AddRange(StreamDictionary.Items);
- list.Add(Data);
- return list;
- }
- }
+ => [..StreamDictionary.Items, Data];
- private byte[] FlateDecodeWithPredictorNone(int _, byte[] decompressed)
+ private static byte[] FlateDecodeWithPredictorNone(int _, byte[] decompressed)
{
return decompressed;
}
- private byte[] FlateDecodeWithPredictorPngUp(int columns, byte[] decompressed)
+ private static byte[] FlateDecodeWithPredictorPngUp(int columns, byte[] decompressed)
{
- var output = new List(32 * 1024);
+ List output = new(32 * 1024);
var previousRow = new byte[columns];
for (int i = 0; i < columns; i++)
previousRow[i] = 0;
@@ -60,10 +52,10 @@ private byte[] FlateDecodeWithPredictorPngUp(int columns, byte[] decompressed)
}
previousRow = currentRow;
}
- return output.ToArray();
+ return [..output];
}
- private byte[] FlateDecodeWithPredictor(int predictor, int columns, byte[] input)
+ private static byte[] FlateDecodeWithPredictor(int predictor, int columns, byte[] input)
{
// now we have to handle the predictors...
return predictor switch
@@ -78,7 +70,7 @@ private byte[] FlateDecodeWithPredictor(int predictor, int columns, byte[] input
public byte[] Decode()
{
- if (!StreamDictionary.TryGetValue("Filter", out IPdfObject? filter))
+ if (!StreamDictionary.TryGetValue("Filter", out IPdfObject filter))
{
// filter is optional
// no filter provided= return the data as-is
diff --git a/SafeRapidPdf/Objects/PdfXRef.cs b/SafeRapidPdf/Objects/PdfXRef.cs
index 34b7fe3..18bfd48 100644
--- a/SafeRapidPdf/Objects/PdfXRef.cs
+++ b/SafeRapidPdf/Objects/PdfXRef.cs
@@ -1,11 +1,10 @@
-using System.Collections.Generic;
namespace SafeRapidPdf.Objects;
public sealed class PdfXRef : PdfObject
{
private readonly IList _sections;
- private readonly Dictionary _offsets = new();
+ private readonly Dictionary _offsets = [];
private PdfXRef(IList sections)
: base(PdfObjectType.XRef)
@@ -69,10 +68,7 @@ internal static PdfXRef Parse(Parsing.Lexer lexer)
/// The parsed PdfXRef
public static PdfXRef Parse(params PdfStream[] xrefStream)
{
- if (xrefStream is null)
- {
- throw new System.ArgumentNullException(nameof(xrefStream));
- }
+ ArgumentNullException.ThrowIfNull(xrefStream);
var sections = new List(xrefStream.Length);
foreach (var pdfStream in xrefStream)
diff --git a/SafeRapidPdf/Parsing/Lexer.cs b/SafeRapidPdf/Parsing/Lexer.cs
index 348e0c5..ef14ca6 100644
--- a/SafeRapidPdf/Parsing/Lexer.cs
+++ b/SafeRapidPdf/Parsing/Lexer.cs
@@ -1,5 +1,4 @@
-using System.Collections.Generic;
-using System.IO;
+using System.IO;
using System.Text;
using SafeRapidPdf.Services;
@@ -270,7 +269,7 @@ b is '/' or // 47
public static bool IsEol(int b)
{
// -1 was added to catch %%EOF without CR or LF
- return b is 10 or 13 or (-1);
+ return b is 10 or 13 or -1;
}
public void PushPosition(long newPosition)
diff --git a/SafeRapidPdf/PdfDocument.cs b/SafeRapidPdf/PdfDocument.cs
index 104e3ca..a919b39 100644
--- a/SafeRapidPdf/PdfDocument.cs
+++ b/SafeRapidPdf/PdfDocument.cs
@@ -1,5 +1,4 @@
-using System.Collections.Generic;
-using System.IO;
+using System.IO;
using SafeRapidPdf.Document;
using SafeRapidPdf.Objects;
@@ -53,7 +52,7 @@ public override string ToString()
return "Document";
}
- private IEnumerable GetPages(IReadOnlyList objects)
+ private static IEnumerable GetPages(IReadOnlyList objects)
{
if (objects != null)
{
diff --git a/SafeRapidPdf/Services/IndirectReferenceResolver.cs b/SafeRapidPdf/Services/IndirectReferenceResolver.cs
index 6942487..58c68bd 100644
--- a/SafeRapidPdf/Services/IndirectReferenceResolver.cs
+++ b/SafeRapidPdf/Services/IndirectReferenceResolver.cs
@@ -63,11 +63,13 @@ private void TryParseLinearizationHeader()
}
}
}
+#pragma warning disable CA1031 // Intentional: linearization header parsing errors are non-fatal
catch
{
// ignore... I know bad style
// in this case the linearization header is assumed to not have been found
}
+#pragma warning restore CA1031
}
public PdfIndirectObject GetObject(int objectNumber, int generationNumber)