Skip to content

Commit

Permalink
Update to PDFtoImage 4.1.0 (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
sungaila authored Jul 24, 2024
1 parent b43128f commit e832d1c
Show file tree
Hide file tree
Showing 40 changed files with 773 additions and 867 deletions.
86 changes: 25 additions & 61 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,50 +55,29 @@ jobs:
uses: actions/checkout@main
with:
fetch-depth: 0
- name: Setup MSBuild
uses: microsoft/setup-msbuild@main
with:
msbuild-architecture: x64
- name: Setup .NET 6
uses: actions/setup-dotnet@main
with:
dotnet-version: 6.x
- name: Setup .NET 7
- name: Setup .NET
uses: actions/setup-dotnet@main
with:
dotnet-version: 7.x
- name: Setup .NET 8
uses: actions/setup-dotnet@main
with:
dotnet-version: 8.x
- name: Setup .NET workload android
run: dotnet workload install android
dotnet-version: |
6.x
7.x
8.x
- name: Setup .NET workload maui-android
run: dotnet workload install maui-android
- name: Setup .NET workload wasm-tools
run: dotnet workload install wasm-tools
- name: Setup JDK 17
uses: actions/setup-java@main
with:
java-version: 17
java-package: jdk
distribution: 'zulu'
- name: Setup Android SDK 29
run: C:\Android\android-sdk\cmdline-tools\latest\bin\sdkmanager "platforms;android-29"
- name: Setup Windows 11 SDK (10.0.26100.0)
uses: GuillaumeFalourd/setup-windows10-sdk-action@main
with:
sdk-version: 26100
- name: Restore
run: msbuild PDFtoZPL.Build.slnf /t:restore
run: dotnet restore PDFtoZPL.Build.slnf
- name: Build
run: msbuild PDFtoZPL.Build.slnf /p:Configuration=${{ github.event_name != 'workflow_dispatch' && 'Debug' || inputs.build_configuration }} /p:VersionSuffix=ci /p:RestorePackages=false
run: dotnet build PDFtoZPL.Build.slnf -c ${{ github.event_name != 'workflow_dispatch' && 'Debug' || inputs.build_configuration }} -p:VersionSuffix=ci --no-restore
- name: Pack
run: msbuild PDFtoZPL/PDFtoZPL.csproj /t:pack /p:Configuration=${{ github.event_name != 'workflow_dispatch' && 'Debug' || inputs.build_configuration }} /p:VersionSuffix=ci /p:RestorePackages=false
run: dotnet pack PDFtoZPL/PDFtoZPL.csproj -c ${{ github.event_name != 'workflow_dispatch' && 'Debug' || inputs.build_configuration }} -p:VersionSuffix=ci --no-restore
- name: Generate artifact attestation
uses: actions/attest-build-provenance@main
with:
subject-path: PDFtoZPL/bin/${{ github.event_name != 'workflow_dispatch' && 'Debug' || inputs.build_configuration }}/*.nupkg
- name: Publish libraries
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@main
with:
name: Library assemblies
path: |
Expand Down Expand Up @@ -133,18 +112,13 @@ jobs:
runs-on: ${{ matrix.os }}
if: success() && (github.event_name != 'workflow_dispatch' && true || inputs.run_tests) == true
steps:
- name: Setup .NET 6
uses: actions/setup-dotnet@main
with:
dotnet-version: 6.x
- name: Setup .NET 7
uses: actions/setup-dotnet@main
with:
dotnet-version: 7.x
- name: Setup .NET 8
- name: Setup .NET
uses: actions/setup-dotnet@main
with:
dotnet-version: 8.x
dotnet-version: |
6.x
7.x
8.x
- name: Download test assemblies
uses: actions/download-artifact@main
with:
Expand Down Expand Up @@ -194,7 +168,7 @@ jobs:
merge-multiple: true
path: artifacts
- name: Publish test results
uses: EnricoMi/publish-unit-test-result-action@v2.16.1
uses: EnricoMi/publish-unit-test-result-action@master
with:
files: artifacts/**/*.trx
check_name: Test results
Expand All @@ -220,22 +194,15 @@ jobs:
uses: actions/checkout@main
with:
fetch-depth: 0
- name: Setup MSBuild
uses: microsoft/setup-msbuild@main
with:
msbuild-architecture: x64
- name: Setup .NET 6
uses: actions/setup-dotnet@main
with:
dotnet-version: 6.x
- name: Setup .NET 7
uses: actions/setup-dotnet@main
with:
dotnet-version: 7.x
- name: Setup .NET 8
- name: Setup .NET
uses: actions/setup-dotnet@main
with:
dotnet-version: 8.x
dotnet-version: |
6.x
7.x
8.x
- name: Setup .NET workload maui-android
run: dotnet workload install maui-android
- name: Setup dotnet-coverage
run: dotnet tool install --global dotnet-coverage
- name: Setup .NET workload android
Expand All @@ -246,8 +213,6 @@ jobs:
java-version: 17
java-package: jdk
distribution: 'zulu'
- name: Setup Android SDK 29
run: C:\Android\android-sdk\cmdline-tools\latest\bin\sdkmanager "platforms;android-29"
- name: Cache SonarCloud packages
uses: actions/cache@main
with:
Expand All @@ -274,7 +239,6 @@ jobs:
shell: powershell
run: |
.\.sonar\scanner\dotnet-sonarscanner begin /k:"sungaila_PDFtoZPL" /o:"sungaila" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml
dotnet restore PDFtoZPL.SonarCloud.slnf
msbuild PDFtoZPL.SonarCloud.slnf /p:Configuration=${{ github.event_name != 'workflow_dispatch' && 'Debug' || inputs.build_configuration }}
dotnet build PDFtoZPL.SonarCloud.slnf -c ${{ github.event_name != 'workflow_dispatch' && 'Debug' || inputs.build_configuration }}
dotnet-coverage collect "dotnet test PDFtoZPL.SonarCloud.slnf --verbosity detailed" -f xml -o "coverage.xml"
.\.sonar\scanner\dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
6 changes: 3 additions & 3 deletions .github/workflows/githubpages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ jobs:
uses: actions/checkout@main
with:
fetch-depth: 0
- name: Setup .NET 8
- name: Setup .NET
uses: actions/setup-dotnet@main
with:
dotnet-version: 8.x
- name: Setup .NET workload android
run: dotnet workload install android
- name: Setup .NET workload maui-android
run: dotnet workload install maui-android
- name: Setup .NET workload wasm-tools
run: dotnet workload install wasm-tools
- name: Update relative paths
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/githubpages_staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ jobs:
uses: actions/checkout@main
with:
fetch-depth: 0
- name: Setup .NET 8
- name: Setup .NET
uses: actions/setup-dotnet@main
with:
dotnet-version: 8.x
- name: Setup .NET workload android
run: dotnet workload install android
- name: Setup .NET workload maui-android
run: dotnet workload install maui-android
- name: Setup .NET workload wasm-tools
run: dotnet workload install wasm-tools
- name: Update relative paths
Expand Down Expand Up @@ -78,6 +78,10 @@ jobs:
name: Deploy
needs: publish
runs-on: ubuntu-latest

concurrency:
group: "pages-staging"
cancel-in-progress: true

# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
permissions:
Expand All @@ -87,10 +91,6 @@ jobs:
environment:
name: github-pages-staging
url: ${{ steps.deployment.outputs.page_url }}

concurrency:
group: "pages"
cancel-in-progress: true

steps:
- name: Deploy to GitHub Pages
Expand Down
3 changes: 2 additions & 1 deletion Console/Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<AssemblyName>PDFtoZPL.Console</AssemblyName>
<RootNamespace>PDFtoZPL.Console</RootNamespace>
<StartupObject>PDFtoZPL.Console.Program</StartupObject>
<Version>5.1.0</Version>
<Version>5.2.0</Version>
<Configurations>Debug;Release;ReleaseSigned</Configurations>
</PropertyGroup>

Expand All @@ -16,6 +16,7 @@
<Nullable>enable</Nullable>
<Features>strict</Features>
<WarningsAsErrors>nullable</WarningsAsErrors>
<NoWarn>CS0618</NoWarn>
</PropertyGroup>

<!-- References -->
Expand Down
3 changes: 1 addition & 2 deletions Console/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.IO;
using System.Reflection;
using static PDFtoZPL.Conversion;

namespace PDFtoZPL.Console
{
Expand Down Expand Up @@ -36,7 +35,7 @@ public static int Main(string[] args)
{
".pdf" =>
#if NET6_0_OR_GREATER
OperatingSystem.IsWindows() || OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()
OperatingSystem.IsWindows() || OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()
#else
true
#endif
Expand Down
99 changes: 99 additions & 0 deletions PDFtoZPL/Conversion.Deprecated.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
using SkiaSharp;
using System;
using System.IO;
using System.Runtime.Versioning;

namespace PDFtoZPL
{
/// <summary>
/// Provides methods to convert PDFs and <see cref="SKBitmap"/>s into ZPL code.
/// </summary>
#if NET8_0_OR_GREATER
#pragma warning disable CA1510 // Use ArgumentNullException throw helper
#endif
public static partial class Conversion
{
/// <summary>
/// Converts a single page of a given PDF into ZPL code.
/// </summary>
/// <param name="pdfAsBase64String">The PDF encoded as Base64.</param>
/// <param name="password">The password for opening the PDF. Use <see langword="null"/> if no password is needed.</param>
/// <param name="page">The specific page to be converted.</param>
/// <param name="pdfOptions">Additional options for PDF rendering.</param>
/// <param name="zplOptions">Additional options for the ZPL output.</param>
/// <returns>The converted PDF page as ZPL code.</returns>
#if NET6_0_OR_GREATER
[SupportedOSPlatform("Windows")]
[SupportedOSPlatform("Linux")]
[SupportedOSPlatform("macOS")]
[SupportedOSPlatform("Android31.0")]
[Obsolete("This method is deprecated and will be removed in a future release. Use SaveJpeg with a System.Index instead.")]
#endif
public static string ConvertPdfPage(string pdfAsBase64String, string? password = null, int page = 0, PdfOptions pdfOptions = default, ZplOptions zplOptions = default)
{
if (pdfAsBase64String == null)
throw new ArgumentNullException(nameof(pdfAsBase64String));

return ConvertPdfPage(Convert.FromBase64String(pdfAsBase64String), password, page, pdfOptions, zplOptions);
}

/// <summary>
/// Converts a single page of a given PDF into ZPL code.
/// </summary>
/// <param name="pdfAsByteArray">The PDF as a byte array.</param>
/// <param name="password">The password for opening the PDF. Use <see langword="null"/> if no password is needed.</param>
/// <param name="page">The specific page to be converted.</param>
/// <param name="pdfOptions">Additional options for PDF rendering.</param>
/// <param name="zplOptions">Additional options for the ZPL output.</param>
/// <returns>The converted PDF page as ZPL code.</returns>
#if NET6_0_OR_GREATER
[SupportedOSPlatform("Windows")]
[SupportedOSPlatform("Linux")]
[SupportedOSPlatform("macOS")]
[SupportedOSPlatform("Android31.0")]
[Obsolete("This method is deprecated and will be removed in a future release. Use SaveJpeg with a System.Index instead.")]
#endif
public static string ConvertPdfPage(byte[] pdfAsByteArray, string? password = null, int page = 0, PdfOptions pdfOptions = default, ZplOptions zplOptions = default)
{
if (pdfAsByteArray == null)
throw new ArgumentNullException(nameof(pdfAsByteArray));

// Base64 string -> byte[] -> MemoryStream
using var pdfStream = new MemoryStream(pdfAsByteArray, false);

return ConvertPdfPage(pdfStream, false, password, page, pdfOptions, zplOptions);
}

/// <summary>
/// Converts a single page of a given PDF into ZPL code.
/// </summary>
/// <param name="pdfStream">The PDF as a stream.</param>
/// <param name="leaveOpen"><see langword="true"/> to leave the <paramref name="pdfStream"/> open after the PDF document is loaded; otherwise, <see langword="false"/>.</param>
/// <param name="password">The password for opening the PDF. Use <see langword="null"/> if no password is needed.</param>
/// <param name="page">The specific page to be converted.</param>
/// <param name="pdfOptions">Additional options for PDF rendering.</param>
/// <param name="zplOptions">Additional options for the ZPL output.</param>
/// <returns>The converted PDF page as ZPL code.</returns>
#if NET6_0_OR_GREATER
[SupportedOSPlatform("Windows")]
[SupportedOSPlatform("Linux")]
[SupportedOSPlatform("macOS")]
[SupportedOSPlatform("Android31.0")]
[Obsolete("This method is deprecated and will be removed in a future release. Use SaveJpeg with a System.Index instead.")]
#endif
public static string ConvertPdfPage(Stream pdfStream, bool leaveOpen = false, string? password = null, int page = 0, PdfOptions pdfOptions = default, ZplOptions zplOptions = default)
{
if (pdfStream == null)
throw new ArgumentNullException(nameof(pdfStream));

if (pdfOptions == default)
pdfOptions = new PdfOptions();

// Stream ->PdfiumViewer.PdfDocument -> Image
var pdfBitmap = PDFtoImage.Conversion.ToImage(pdfStream, leaveOpen, password, page, pdfOptions);

// Bitmap -> ZPL code
return ConvertBitmap(pdfBitmap, zplOptions);
}
}
}
Loading

0 comments on commit e832d1c

Please sign in to comment.