-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix password issue #43; add password unit tests; introduce PDF specif…
…ic exceptions (#44)
- Loading branch information
Showing
47 changed files
with
3,207 additions
and
2,944 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using static PDFtoImage.PdfiumViewer.NativeMethods; | ||
|
||
namespace PDFtoImage.Exceptions | ||
{ | ||
/// <summary> | ||
/// Thrown if the PDF file was not found or could not be opened. | ||
/// </summary> | ||
public class PdfCannotOpenFileException : PdfException | ||
{ | ||
internal override FPDF_ERR Error => FPDF_ERR.FILE; | ||
|
||
/// <inheritdoc/> | ||
public PdfCannotOpenFileException() : base("File not found or could not be opened.") { } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System; | ||
using static PDFtoImage.PdfiumViewer.NativeMethods; | ||
|
||
namespace PDFtoImage.Exceptions | ||
{ | ||
/// <summary> | ||
/// Base class for all PDF related exceptions. | ||
/// </summary> | ||
public abstract class PdfException : Exception | ||
{ | ||
internal abstract FPDF_ERR Error { get; } | ||
|
||
/// <inheritdoc/> | ||
protected PdfException(string message) : base(message) { } | ||
|
||
internal static PdfException? CreateException(FPDF_ERR error) => error switch | ||
{ | ||
FPDF_ERR.SUCCESS => null, | ||
FPDF_ERR.UNKNOWN => new PdfUnknownException(), | ||
FPDF_ERR.FILE => new PdfCannotOpenFileException(), | ||
FPDF_ERR.FORMAT => new PdfInvalidFormatException(), | ||
FPDF_ERR.PASSWORD => new PdfPasswordProtectedException(), | ||
FPDF_ERR.SECURITY => new PdfUnsupportedSecuritySchemeException(), | ||
FPDF_ERR.PAGE => new PdfPageNotFoundException(), | ||
_ => new PdfUnknownException() | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using static PDFtoImage.PdfiumViewer.NativeMethods; | ||
|
||
namespace PDFtoImage.Exceptions | ||
{ | ||
/// <summary> | ||
/// Thrown if the PDF format is invalid or corrupted. | ||
/// </summary> | ||
public class PdfInvalidFormatException : PdfException | ||
{ | ||
internal override FPDF_ERR Error => FPDF_ERR.FORMAT; | ||
|
||
/// <inheritdoc/> | ||
public PdfInvalidFormatException() : base("File not in PDF format or corrupted.") { } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using static PDFtoImage.PdfiumViewer.NativeMethods; | ||
|
||
namespace PDFtoImage.Exceptions | ||
{ | ||
/// <summary> | ||
/// Thrown if the PDF does not contain the given page number. | ||
/// </summary> | ||
public class PdfPageNotFoundException : PdfException | ||
{ | ||
internal override FPDF_ERR Error => FPDF_ERR.PAGE; | ||
|
||
/// <inheritdoc/> | ||
public PdfPageNotFoundException() : base("Page not found or content error.") { } | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/PDFtoImage/Exceptions/PdfPasswordProtectedException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using static PDFtoImage.PdfiumViewer.NativeMethods; | ||
|
||
namespace PDFtoImage.Exceptions | ||
{ | ||
/// <summary> | ||
/// Thrown if the PDF requires a password and the given password was not given or incorrect. | ||
/// </summary> | ||
public class PdfPasswordProtectedException : PdfException | ||
{ | ||
internal override FPDF_ERR Error => FPDF_ERR.PASSWORD; | ||
|
||
/// <inheritdoc/> | ||
public PdfPasswordProtectedException() : base("Password required or incorrect password.") { } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using static PDFtoImage.PdfiumViewer.NativeMethods; | ||
|
||
namespace PDFtoImage.Exceptions | ||
{ | ||
/// <summary> | ||
/// Thrown on unknown PDF errors. | ||
/// </summary> | ||
public class PdfUnknownException : PdfException | ||
{ | ||
internal override FPDF_ERR Error => FPDF_ERR.UNKNOWN; | ||
|
||
/// <inheritdoc/> | ||
public PdfUnknownException() : base("Unknown error.") { } | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/PDFtoImage/Exceptions/PdfUnsupportedSecuritySchemeException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using static PDFtoImage.PdfiumViewer.NativeMethods; | ||
|
||
namespace PDFtoImage.Exceptions | ||
{ | ||
/// <summary> | ||
/// Thrown if the PDF file uses an unsupported security scheme. | ||
/// </summary> | ||
public class PdfUnsupportedSecuritySchemeException : PdfException | ||
{ | ||
internal override FPDF_ERR Error => FPDF_ERR.SECURITY; | ||
|
||
/// <inheritdoc/> | ||
public PdfUnsupportedSecuritySchemeException() : base("Unsupported security scheme.") { } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,28 @@ | ||
namespace PDFtoImage | ||
{ | ||
/// <summary> | ||
/// Specifies the rotation of pages shown in the PDF renderer. | ||
/// </summary> | ||
public enum PdfRotation | ||
{ | ||
/// <summary> | ||
/// No rotation. | ||
/// </summary> | ||
Rotate0 = 0, | ||
/// <summary> | ||
/// Specifies the rotation of pages shown in the PDF renderer. | ||
/// </summary> | ||
public enum PdfRotation | ||
{ | ||
/// <summary> | ||
/// No rotation. | ||
/// </summary> | ||
Rotate0 = 0, | ||
|
||
/// <summary> | ||
/// Rotated 90 degrees clockwise. | ||
/// </summary> | ||
Rotate90 = 1, | ||
/// <summary> | ||
/// Rotated 90 degrees clockwise. | ||
/// </summary> | ||
Rotate90 = 1, | ||
|
||
/// <summary> | ||
/// Rotated 180 degrees. | ||
/// </summary> | ||
Rotate180 = 2, | ||
/// <summary> | ||
/// Rotated 180 degrees. | ||
/// </summary> | ||
Rotate180 = 2, | ||
|
||
/// <summary> | ||
/// Rotated 90 degrees counter-clockwise. | ||
/// </summary> | ||
Rotate270 = 3 | ||
} | ||
/// <summary> | ||
/// Rotated 90 degrees counter-clockwise. | ||
/// </summary> | ||
Rotate270 = 3 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.