Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to PDFtoImage 4.1.0 #61

Merged
merged 3 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Update to PDFtoImage 4.1.0
  • Loading branch information
sungaila committed Jul 24, 2024
commit 3e771cd1189332f632a71ec29155b1b0b6875943
90 changes: 27 additions & 63 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
subject-path: src/PDFtoImage/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 @@ -273,8 +238,7 @@ jobs:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
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 }}
.\.sonar\scanner\dotnet-sonarscanner begin /k:"sungaila_PDFtoImage" /o:"sungaila" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml
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
11 changes: 4 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 @@ -79,6 +79,7 @@ jobs:
needs: publish
runs-on: ubuntu-latest

true
# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
permissions:
pages: write # to deploy to Pages
Expand All @@ -87,10 +88,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
2 changes: 1 addition & 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 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
Loading