diff --git a/Nuget/pdfium_x64.dll b/Nuget/pdfium_x64.dll index 8969400..86377cc 100644 Binary files a/Nuget/pdfium_x64.dll and b/Nuget/pdfium_x64.dll differ diff --git a/Nuget/pdfium_x86.dll b/Nuget/pdfium_x86.dll index c7aff3a..b0457fe 100644 Binary files a/Nuget/pdfium_x86.dll and b/Nuget/pdfium_x86.dll differ diff --git a/PDFiumSharp.sln b/PDFiumSharp.sln index f00c14f..1b8a83f 100644 --- a/PDFiumSharp.sln +++ b/PDFiumSharp.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 VisualStudioVersion = 15.0.26228.12 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PDFiumSharp", "PDFiumSharp\PDFiumSharp.csproj", "{782D0C5A-2A13-480C-AF88-6DADC726566E}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PDFiumSharp", "PDFiumSharp\PDFiumSharp.csproj", "{782D0C5A-2A13-480C-AF88-6DADC726566E}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PDFiumSharp.GdiPlus", "PDFiumSharp.GdiPlus\PDFiumSharp.GdiPlus.csproj", "{2D52FEFF-2445-4446-A4A0-65DCEBD639AA}" EndProject @@ -80,4 +80,7 @@ Global {C07538E4-238C-42AC-BC19-8AFA66BD6BC2} = {488D350A-7DF4-4E38-9398-409C89A2A9E6} {AE8ED031-D549-449C-9273-5F0369BF7E56} = {488D350A-7DF4-4E38-9398-409C89A2A9E6} EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {CF9ACF66-BB1D-4F64-9F8F-80249BC60195} + EndGlobalSection EndGlobal diff --git a/PDFiumSharp/PDFium.cs b/PDFiumSharp/PDFium.cs index ba0a551..76b164d 100644 --- a/PDFiumSharp/PDFium.cs +++ b/PDFiumSharp/PDFium.cs @@ -88,17 +88,19 @@ public static FPDF_DOCUMENT FPDF_LoadDocument(byte[] data, int index = 0, int co return FPDF_LoadMemDocument(ref data[index], count, password); } - /// - /// Loads a PDF document from '' bytes read from a stream. - /// - /// - /// The number of bytes to read from the . - /// If the value is equal to or smaller than 0, the stream is read to the end. - /// - public static FPDF_DOCUMENT FPDF_LoadDocument(Stream stream, int count = 0, string password = null) - { - return FPDF_LoadCustomDocument(FPDF_FILEREAD.FromStream(stream, count), password); - } + /// + /// Loads a PDF document from '' bytes read from a stream. + /// + /// + /// + /// The number of bytes to read from the . + /// If the value is equal to or smaller than 0, the stream is read to the end. + /// + /// + public static FPDF_DOCUMENT FPDF_LoadDocument(Stream stream, FPDF_FILEREAD fileRead, int count = 0, string password = null) + { + return FPDF_LoadCustomDocument(fileRead, password); + } //public static string FPDF_VIEWERREF_GetName(FPDF_DOCUMENT document, string key) //{ diff --git a/PDFiumSharp/PDFium.tt b/PDFiumSharp/PDFium.tt index eb7f6f3..46239f9 100644 --- a/PDFiumSharp/PDFium.tt +++ b/PDFiumSharp/PDFium.tt @@ -807,7 +807,7 @@ foreach (var import in Imports) if (returnType == "void") { // --------------------------------------------------------- Code End ----------------------------------------------------- #> - if (RuntimeInformation.ProcessArchitecture == Architecture.X64) + if (RuntimeInformation.ProcessArchitecture == Architecture.X64 || (RuntimeInformation.ProcessArchitecture == Architecture.X86 && IntPtr.Size == 8)) lock(_lock) { PlatformInvoke.<#=name#>_x64(<#=args#>); } else if (RuntimeInformation.ProcessArchitecture == Architecture.X86) lock(_lock) { PlatformInvoke.<#=name#>_x86(<#=args#>); } @@ -818,7 +818,7 @@ foreach (var import in Imports) else { // --------------------------------------------------------- Code End ----------------------------------------------------- #> - if (RuntimeInformation.ProcessArchitecture == Architecture.X64) + if (RuntimeInformation.ProcessArchitecture == Architecture.X64 || (RuntimeInformation.ProcessArchitecture == Architecture.X86 && IntPtr.Size == 8)) lock(_lock) { return PlatformInvoke.<#=name#>_x64(<#=args#>); } else if (RuntimeInformation.ProcessArchitecture == Architecture.X86) lock(_lock) { return PlatformInvoke.<#=name#>_x86(<#=args#>); } diff --git a/PDFiumSharp/PdfDocument.cs b/PDFiumSharp/PdfDocument.cs index 0e13c64..2190fb0 100644 --- a/PDFiumSharp/PdfDocument.cs +++ b/PDFiumSharp/PdfDocument.cs @@ -23,7 +23,7 @@ public sealed class PdfDocument : NativeWrapper public PdfDestinationCollection Destinations { get; } - /// + /// /// Gets the PDF file version. File version: 14 for 1.4, 15 for 1.5, ... /// public int FileVersion { get { PDFium.FPDF_GetFileVersion(Handle, out int fileVersion); return fileVersion; } } @@ -91,16 +91,19 @@ public PdfDocument(string fileName, string password = null) public PdfDocument(byte[] data, int index = 0, int count = -1, string password = null) : this(PDFium.FPDF_LoadDocument(data, index, count, password)) { } - /// - /// Loads a from '' bytes read from a . - /// must be called in order to free unmanaged resources. - /// - /// - /// The number of bytes to read from the . - /// If the value is equal to or smaller than 0, the stream is read to the end. - /// - public PdfDocument(Stream stream, int count = 0, string password = null) - : this(PDFium.FPDF_LoadDocument(stream, count, password)) { } + /// + /// Loads a from '' bytes read from a . + /// must be called in order to free unmanaged resources. + /// + /// + /// + /// + /// The number of bytes to read from the . + /// If the value is equal to or smaller than 0, the stream is read to the end. + /// + /// + public PdfDocument(Stream stream, FPDF_FILEREAD fileRead, int count = 0, string password = null) + : this(PDFium.FPDF_LoadDocument(stream, fileRead, count, password)) { } /// /// Closes the and frees unmanaged resources. diff --git a/PDFiumSharp/PdfPage.cs b/PDFiumSharp/PdfPage.cs index f4f1f00..94350ea 100644 --- a/PDFiumSharp/PdfPage.cs +++ b/PDFiumSharp/PdfPage.cs @@ -50,10 +50,15 @@ public PageOrientations Orientation set => PDFium.FPDFPage_SetRotation(Handle, value); } - /// - /// Gets the zero-based index of the page in the - /// - public int Index { get; internal set; } = -1; + /// + /// Get the transparency of the page + /// + public bool HasTransparency => PDFium.FPDFPage_HasTransparency(Handle); + + /// + /// Gets the zero-based index of the page in the + /// + public int Index { get; internal set; } = -1; /// /// Gets the which contains the page. @@ -116,7 +121,9 @@ public void Render(PDFiumBitmap renderTarget, PageOrientations orientation = Pag public FlattenResults Flatten(FlattenFlags flags) => PDFium.FPDFPage_Flatten(Handle, flags); - protected override void Dispose(FPDF_PAGE handle) + public void Dispose() => ((IDisposable)this).Dispose(); + + protected override void Dispose(FPDF_PAGE handle) { PDFium.FPDF_ClosePage(handle); } diff --git a/PDFiumSharp/Types/FPDF_COLOR.cs b/PDFiumSharp/Types/FPDF_COLOR.cs index 13c1b03..8144951 100644 --- a/PDFiumSharp/Types/FPDF_COLOR.cs +++ b/PDFiumSharp/Types/FPDF_COLOR.cs @@ -25,7 +25,7 @@ public struct FPDF_COLOR readonly uint _argb; public byte A => _a; - public byte R => _b; + public byte R => _r; public byte G => _g; public byte B => _b; public int ARGB => unchecked((int)_argb); diff --git a/Samples/Test.Console/Program.cs b/Samples/Test.Console/Program.cs index 1391655..f695f82 100644 --- a/Samples/Test.Console/Program.cs +++ b/Samples/Test.Console/Program.cs @@ -16,14 +16,16 @@ static void Main(string[] args) { int i = 0; foreach (var page in doc.Pages) - { - using (var bitmap = new PDFiumBitmap((int)page.Width, (int)page.Height, true)) - using (var stream = new FileStream($"{i++}.bmp", FileMode.Create)) - { - page.Render(bitmap); - bitmap.Save(stream); - } - } + using (page) + { + using (var bitmap = new PDFiumBitmap((int)page.Width, (int)page.Height, true)) + using (var stream = new FileStream($"{i++}.bmp", FileMode.Create)) + { + page.Render(bitmap); + bitmap.Save(stream); + } + } + } Console.ReadKey(); }