diff --git a/src/Console/Program.cs b/src/Console/Program.cs index 819f5f79..349d142d 100644 --- a/src/Console/Program.cs +++ b/src/Console/Program.cs @@ -15,7 +15,7 @@ static int Main(string[] args) try { - ParseArguments(args, out string? inputPath, out string? outputPath, out int dpi); + ParseArguments(args, out string? inputPath, out string? outputPath, out int page, out int dpi); if (inputPath == null) throw new InvalidOperationException("There is no PDF file path."); @@ -33,21 +33,21 @@ static int Main(string[] args) switch (Path.GetExtension(outputPath).ToLower()) { case ".bmp": - Conversion.SaveBmp(outputPath, inputStream, dpi: dpi); + Conversion.SaveBmp(outputPath, inputStream, page: page - 1, dpi: dpi); break; case ".png": - Conversion.SavePng(outputPath, inputStream, dpi: dpi); + Conversion.SavePng(outputPath, inputStream, page: page - 1, dpi: dpi); break; case ".gif": - Conversion.SaveGif(outputPath, inputStream, dpi: dpi); + Conversion.SaveGif(outputPath, inputStream, page: page - 1, dpi: dpi); break; case ".jpg": case ".jpeg": - Conversion.SaveJpeg(outputPath, inputStream, dpi: dpi); + Conversion.SaveJpeg(outputPath, inputStream, page: page - 1, dpi: dpi); break; case ".tif": case ".tiff": - Conversion.SaveTiff(outputPath, inputStream, dpi: dpi); + Conversion.SaveTiff(outputPath, inputStream, page: page - 1, dpi: dpi); break; default: throw new InvalidOperationException("Only the following file extensions are supported: bmp, png, gif, jpg/jpeg and tif/tiff."); @@ -64,7 +64,7 @@ static int Main(string[] args) return 0; } - private static void ParseArguments(string[] args, out string? inputPath, out string? outputPath, out int dpi) + private static void ParseArguments(string[] args, out string? inputPath, out string? outputPath, out int page, out int dpi) { if (args == null) throw new ArgumentNullException(nameof(args)); @@ -99,17 +99,34 @@ private static void ParseArguments(string[] args, out string? inputPath, out str outputPath = outputPath.Trim('\"'); - dpi = 300; + page = 1; if (args.Length >= 3) { outputPath = args[2]; } else + { + System.Console.Write("Enter PDF page number: "); + + if (!int.TryParse(System.Console.ReadLine(), out page) || page <= 0) + { + page = 1; + System.Console.WriteLine($"PDF page number defaulting to {page}."); + } + } + + dpi = 300; + + if (args.Length >= 4) + { + outputPath = args[3]; + } + else { System.Console.Write("Enter the target resolution in DPI: "); - if (!int.TryParse(System.Console.ReadLine(), out dpi)) + if (!int.TryParse(System.Console.ReadLine(), out dpi) || dpi <= 0) { dpi = 300; System.Console.WriteLine($"Target DPI defaulting to {dpi}."); diff --git a/src/PDFtoImage/PDFtoImage.csproj b/src/PDFtoImage/PDFtoImage.csproj index c92b7c47..0bb414fd 100644 --- a/src/PDFtoImage/PDFtoImage.csproj +++ b/src/PDFtoImage/PDFtoImage.csproj @@ -12,7 +12,7 @@ - 1.0.0 + 1.0.1 David Sungaila false @@ -21,7 +21,7 @@ https://github.com/sungaila/PDFtoImage https://raw.githubusercontent.com/sungaila/PDFtoImage/master/etc/Icon_128.png A .NET library to render PDF files into images. - Initial release + Fixed an issue that caused the OS architecture to be evaluated instead of the process architecture. PDF Bitmap Image Convert Conversion C# PDFium https://github.com/sungaila/PDFtoImage.git git diff --git a/src/PDFtoImage/PdfiumViewer/NativeMethods.cs b/src/PDFtoImage/PdfiumViewer/NativeMethods.cs index dddde5fe..2f5f638d 100644 --- a/src/PDFtoImage/PdfiumViewer/NativeMethods.cs +++ b/src/PDFtoImage/PdfiumViewer/NativeMethods.cs @@ -25,7 +25,7 @@ private static bool LoadNativeLibrary(string path) #if NETCOREAPP3_0_OR_GREATER if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { - _pdfiumLibPath = Path.Combine(_pdfiumLibPath, (RuntimeInformation.OSArchitecture) switch + _pdfiumLibPath = Path.Combine(_pdfiumLibPath, (RuntimeInformation.ProcessArchitecture) switch { Architecture.X86 => "win-x86", Architecture.X64 => "win-x64", @@ -36,7 +36,7 @@ private static bool LoadNativeLibrary(string path) } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { - _pdfiumLibPath = Path.Combine(_pdfiumLibPath, (RuntimeInformation.OSArchitecture) switch + _pdfiumLibPath = Path.Combine(_pdfiumLibPath, (RuntimeInformation.ProcessArchitecture) switch { Architecture.X64 => "linux-x64", _ => throw new PlatformNotSupportedException("Only x86-64 is supported on Linux.") @@ -46,7 +46,7 @@ private static bool LoadNativeLibrary(string path) } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { - _pdfiumLibPath = Path.Combine(_pdfiumLibPath, (RuntimeInformation.OSArchitecture) switch + _pdfiumLibPath = Path.Combine(_pdfiumLibPath, (RuntimeInformation.ProcessArchitecture) switch { Architecture.X64 => "osx-x64", Architecture.Arm64 => "osx-arm64", diff --git a/src/Tests/Tests.csproj b/src/Tests/Tests.csproj index 01fadc5d..20ccb9b1 100644 --- a/src/Tests/Tests.csproj +++ b/src/Tests/Tests.csproj @@ -439,8 +439,8 @@ - - - + + + \ No newline at end of file