throw informative exception when the document is encrypted

This commit is contained in:
Eliot Jones
2018-01-08 22:43:48 +00:00
parent bf7d3868da
commit 10df612a00
2 changed files with 18 additions and 1 deletions

View File

@@ -123,6 +123,11 @@
private static CosBase ParseTrailer(IRandomAccessRead reader, CrossReferenceTable crossReferenceTable,
DynamicParser dynamicParser, BruteForceSearcher bruteForceSearcher, CosObjectPool pool, bool isLenientParsing)
{
if (crossReferenceTable.Dictionary.ContainsKey(CosName.ENCRYPT))
{
throw new NotSupportedException("Cannot currently parse a document using encryption: " + crossReferenceTable.Dictionary);
}
foreach (var value in crossReferenceTable.Dictionary.Values)
{
if (value is CosObject temporaryObject)

View File

@@ -64,8 +64,20 @@
Pages = new Pages(log, Catalog, pdfObjectParser, pageFactory, reader, isLenientParsing);
}
/// <summary>
/// Creates a <see cref="PdfDocument"/> for reading from the provided file bytes.
/// </summary>
/// <param name="fileBytes">The bytes of the PDF file.</param>
/// <param name="options">Optional parameters controlling parsing.</param>
/// <returns>A <see cref="PdfDocument"/> providing access to the file contents.</returns>
public static PdfDocument Open(byte[] fileBytes, ParsingOptions options = null) => PdfDocumentFactory.Open(fileBytes, options);
public static PdfDocument Open(string filename, ParsingOptions options = null) => PdfDocumentFactory.Open(filename, options);
/// <summary>
/// Opens a file and creates a <see cref="PdfDocument"/> for reading from the provided file path.
/// </summary>
/// <param name="filePath">The full path to the file location of the PDF file.</param>
/// <param name="options">Optional parameters controlling parsing.</param>
/// <returns>A <see cref="PdfDocument"/> providing access to the file contents.</returns>
public static PdfDocument Open(string filePath, ParsingOptions options = null) => PdfDocumentFactory.Open(filePath, options);
/// <summary>
/// Get the page with the specified page number.