3using System.Threading.Tasks;
65 ContentType =
string.Empty;
78 switch (ContentType.ToLower())
85 FileExtension =
string.Empty;
120 public Task<ContentResponse>
DecodeAsync(
string ContentType,
byte[] Data,
System.Text.Encoding Encoding,
121 KeyValuePair<string, string>[] Fields, Uri BaseUri,
ICodecProgress Progress)
126 return Task.FromResult(
new ContentResponse(
new Exception(
"Not a valid PDF document.")));
134 public static bool IsPdf(
byte[] Data)
136 if (Data is
null || Data.Length < 12)
139 string Header =
System.Text.Encoding.ASCII.GetString(Data, 0, 10);
140 if (!Header.TrimStart().StartsWith(
"%PDF-"))
143 string Footer =
System.Text.Encoding.ASCII.GetString(
144 Data, Data.Length - 10, 10);
146 if (!Footer.TrimEnd().EndsWith(
"%%EOF"))
183 params
string[] AcceptedContentTypes)
188 return Task.FromResult(
new ContentResponse(
new ArgumentException(
"Unable to encode as PDF document.", nameof(Object))));
Contains information about a response to a content request.
Static class managing encoding and decoding of internet content.
static bool IsAccepted(string ContentType, params string[] AcceptedContentTypes)
Checks if a given content type is acceptable.
Encoder and Decoder of Binary PDF Documents.
const string DefaultFileExtension
pdf
bool Encodes(object Object, out Grade Grade, params string[] AcceptedContentTypes)
If the encoder encodes a given object.
string[] ContentTypes
Supported content types.
static bool IsPdf(byte[] Data)
Checks if a Binary BLOB is a PDF document.
string[] FileExtensions
Supported file extensions.
bool TryGetFileExtension(string ContentType, out string FileExtension)
Tries to get the file extension of an item, given its Content-Type.
bool Decodes(string ContentType, out Grade Grade)
If the decoder decodes an object with a given content type.
static readonly string[] PdfContentTypes
Binary content types.
Task< ContentResponse > EncodeAsync(object Object, System.Text.Encoding Encoding, ICodecProgress Progress, params string[] AcceptedContentTypes)
Encodes an object.
const string DefaultContentType
application/pdf
bool TryGetContentType(string FileExtension, out string ContentType)
Tries to get the content type of an item, given its file extension.
Task< ContentResponse > DecodeAsync(string ContentType, byte[] Data, System.Text.Encoding Encoding, KeyValuePair< string, string >[] Fields, Uri BaseUri, ICodecProgress Progress)
Decodes an object.
static readonly string[] PdfFileExtensions
Binary content types.
Interface for reporting progress about an encoding or decoding.
Basic interface for Internet Content decoders. A class implementing this interface and having a defau...
Basic interface for Internet Content encoders. A class implementing this interface and having a defau...