Skip to content

Commit

Permalink
Revert default DPI to 203; update PDFtoImage
Browse files Browse the repository at this point in the history
  • Loading branch information
sungaila committed Mar 14, 2024
1 parent e2db3e6 commit 925197d
Show file tree
Hide file tree
Showing 21 changed files with 564 additions and 104 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ body:
attributes:
label: PDFtoZPL version
description: Which version of PDFtoZPL is affected?
value: 5.0.0
value: 5.0.1
validations:
required: true
- type: dropdown
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>4.1.0</Version>
<Version>5.0.1</Version>
<Configurations>Debug;Release;ReleaseSigned</Configurations>
</PropertyGroup>

Expand Down
21 changes: 10 additions & 11 deletions PDFtoZPL/Conversion.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using PDFtoImage;
using SkiaSharp;
using SkiaSharp;
using System;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -34,7 +33,7 @@ public static class Conversion
[SupportedOSPlatform("macOS")]
[SupportedOSPlatform("Android31.0")]
#endif
public static string ConvertPdfPage(string pdfAsBase64String, string? password = null, int page = 0, RenderOptions pdfOptions = default, ZplOptions zplOptions = default)
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));
Expand All @@ -57,7 +56,7 @@ public static string ConvertPdfPage(string pdfAsBase64String, string? password =
[SupportedOSPlatform("macOS")]
[SupportedOSPlatform("Android31.0")]
#endif
public static string ConvertPdfPage(byte[] pdfAsByteArray, string? password = null, int page = 0, RenderOptions pdfOptions = default, ZplOptions zplOptions = default)
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));
Expand All @@ -84,7 +83,7 @@ public static string ConvertPdfPage(byte[] pdfAsByteArray, string? password = nu
[SupportedOSPlatform("macOS")]
[SupportedOSPlatform("Android31.0")]
#endif
public static string ConvertPdfPage(Stream pdfStream, bool leaveOpen = false, string? password = null, int page = 0, RenderOptions pdfOptions = default, ZplOptions zplOptions = default)
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));
Expand All @@ -110,7 +109,7 @@ public static string ConvertPdfPage(Stream pdfStream, bool leaveOpen = false, st
[SupportedOSPlatform("macOS")]
[SupportedOSPlatform("Android31.0")]
#endif
public static IEnumerable<string> ConvertPdf(string pdfAsBase64String, string? password = null, RenderOptions pdfOptions = default, ZplOptions zplOptions = default)
public static IEnumerable<string> ConvertPdf(string pdfAsBase64String, string? password = null, PdfOptions pdfOptions = default, ZplOptions zplOptions = default)

Check warning on line 112 in PDFtoZPL/Conversion.cs

View workflow job for this annotation

GitHub Actions / SonarCloud

Split this method into two, one handling parameters check and the other handling the iterator. (https://rules.sonarsource.com/csharp/RSPEC-4456)
{
if (pdfAsBase64String == null)
throw new ArgumentNullException(nameof(pdfAsBase64String));
Expand All @@ -135,7 +134,7 @@ public static IEnumerable<string> ConvertPdf(string pdfAsBase64String, string? p
[SupportedOSPlatform("macOS")]
[SupportedOSPlatform("Android31.0")]
#endif
public static IEnumerable<string> ConvertPdf(byte[] pdfAsByteArray, string? password = null, RenderOptions pdfOptions = default, ZplOptions zplOptions = default)
public static IEnumerable<string> ConvertPdf(byte[] pdfAsByteArray, string? password = null, PdfOptions pdfOptions = default, ZplOptions zplOptions = default)

Check warning on line 137 in PDFtoZPL/Conversion.cs

View workflow job for this annotation

GitHub Actions / SonarCloud

Split this method into two, one handling parameters check and the other handling the iterator. (https://rules.sonarsource.com/csharp/RSPEC-4456)
{
if (pdfAsByteArray == null)
throw new ArgumentNullException(nameof(pdfAsByteArray));
Expand Down Expand Up @@ -164,7 +163,7 @@ public static IEnumerable<string> ConvertPdf(byte[] pdfAsByteArray, string? pass
[SupportedOSPlatform("macOS")]
[SupportedOSPlatform("Android31.0")]
#endif
public static IEnumerable<string> ConvertPdf(Stream pdfStream, bool leaveOpen = false, string? password = null, RenderOptions pdfOptions = default, ZplOptions zplOptions = default)
public static IEnumerable<string> ConvertPdf(Stream pdfStream, bool leaveOpen = false, string? password = null, PdfOptions pdfOptions = default, ZplOptions zplOptions = default)
{
if (pdfStream == null)
throw new ArgumentNullException(nameof(pdfStream));
Expand Down Expand Up @@ -193,7 +192,7 @@ public static IEnumerable<string> ConvertPdf(Stream pdfStream, bool leaveOpen =
[SupportedOSPlatform("macOS")]
[SupportedOSPlatform("Android31.0")]
#endif
public static async IAsyncEnumerable<string> ConvertPdfAsync(string pdfAsBase64String, string? password = null, RenderOptions pdfOptions = default, ZplOptions zplOptions = default, [EnumeratorCancellation] CancellationToken cancellationToken = default)
public static async IAsyncEnumerable<string> ConvertPdfAsync(string pdfAsBase64String, string? password = null, PdfOptions pdfOptions = default, ZplOptions zplOptions = default, [EnumeratorCancellation] CancellationToken cancellationToken = default)
{
if (pdfAsBase64String == null)
throw new ArgumentNullException(nameof(pdfAsBase64String));
Expand All @@ -219,7 +218,7 @@ await foreach (var zplCode in ConvertPdfAsync(Convert.FromBase64String(pdfAsBase
[SupportedOSPlatform("macOS")]
[SupportedOSPlatform("Android31.0")]
#endif
public static async IAsyncEnumerable<string> ConvertPdfAsync(byte[] pdfAsByteArray, string? password = null, RenderOptions pdfOptions = default, ZplOptions zplOptions = default, [EnumeratorCancellation] CancellationToken cancellationToken = default)
public static async IAsyncEnumerable<string> ConvertPdfAsync(byte[] pdfAsByteArray, string? password = null, PdfOptions pdfOptions = default, ZplOptions zplOptions = default, [EnumeratorCancellation] CancellationToken cancellationToken = default)
{
if (pdfAsByteArray == null)
throw new ArgumentNullException(nameof(pdfAsByteArray));
Expand Down Expand Up @@ -249,7 +248,7 @@ await foreach (var zplCode in ConvertPdfAsync(pdfStream, false, password, pdfOpt
[SupportedOSPlatform("macOS")]
[SupportedOSPlatform("Android31.0")]
#endif
public static async IAsyncEnumerable<string> ConvertPdfAsync(Stream pdfStream, bool leaveOpen = false, string? password = null, RenderOptions pdfOptions = default, ZplOptions zplOptions = default, [EnumeratorCancellation] CancellationToken cancellationToken = default)
public static async IAsyncEnumerable<string> ConvertPdfAsync(Stream pdfStream, bool leaveOpen = false, string? password = null, PdfOptions pdfOptions = default, ZplOptions zplOptions = default, [EnumeratorCancellation] CancellationToken cancellationToken = default)
{
if (pdfStream == null)
throw new ArgumentNullException(nameof(pdfStream));
Expand Down
33 changes: 33 additions & 0 deletions PDFtoZPL/IZplOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
namespace PDFtoZPL
{
/// <summary>
/// Contains all relevant information to render a PDF page into an image.
/// </summary>
public interface IZplOptions
{
/// <summary>
/// The encoding used for embedding the bitmap.
/// </summary>
BitmapEncodingKind EncodingKind { get; init; }

/// <summary>
/// If <see langword="true"/> then only the ^GF part of the ZPL code is returned. Otherwise it returns ^XA^GF^FS^XZ.
/// </summary>
bool GraphicFieldOnly { get; init; }

/// <summary>
/// If <see langword="true"/> then the returned ZPL sets the label length to the height of the image, using the ^LL command. Otherwise it returns ^XA^GF^FS^XZ.
/// </summary>
bool SetLabelLength { get; init; }

/// <summary>
/// The threshold below which a pixel is considered black. Lower values mean darker, higher mean lighter.
/// </summary>
byte Threshold { get; init; }

/// <summary>
/// The dithering algorithm used when downsampling to a 1-bit monochrome image.
/// </summary>
DitheringKind DitheringKind { get; init; }
}
}
10 changes: 5 additions & 5 deletions PDFtoZPL/PDFtoZPL.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<!-- NuGet -->
<PropertyGroup>
<VersionPrefix>5.0.0</VersionPrefix>
<VersionPrefix>5.0.1</VersionPrefix>
<VersionSuffix></VersionSuffix>
<Authors>David Sungaila</Authors>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
Expand All @@ -21,9 +21,9 @@
<PackageProjectUrl>https://github.com/sungaila/PDFtoZPL</PackageProjectUrl>
<PackageIconUrl>https://raw.githubusercontent.com/sungaila/PDFtoZPL/master/Icon_128.png</PackageIconUrl>
<Description>A .NET library to convert PDF files (and bitmaps) into Zebra Programming Language code.</Description>
<PackageReleaseNotes>- Added optional parameter Bounds.
- Added optional parameter UseTiling.
- RenderOptions and ZplOptions introduced for most API calls. This is a breaking change.</PackageReleaseNotes>
<PackageReleaseNotes>- Revert from 300 to 203 as default DPI. This is a breaking change.
- Replace PDFtoImage.RenderOptions with PDFtoZPL.PdfOptions. This is a breaking change.
- Fixed interactions between parameters Bounds and Width/Height.</PackageReleaseNotes>
<PackageTags>PDF ZPL Zebra Bitmap Convert Conversion C# PDFium MAUI wasm WebAssembly</PackageTags>
<RepositoryUrl>https://github.com/sungaila/PDFtoZPL.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
Expand Down Expand Up @@ -68,7 +68,7 @@

<!-- SourceLink build steps and NuGet packages -->
<ItemGroup>
<PackageReference Include="PDFtoImage" Version="4.0.0" PrivateAssets="analyzers" />
<PackageReference Include="PDFtoImage" Version="4.0.1" PrivateAssets="analyzers" />
<PackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="3.3.4" PrivateAssets="all" />
<PackageReference Include="SharpZipLib" Version="1.4.2" PrivateAssets="analyzers" />
</ItemGroup>
Expand Down
56 changes: 56 additions & 0 deletions PDFtoZPL/PdfOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using PDFtoImage;
using SkiaSharp;
using System.Drawing;

namespace PDFtoZPL
{
/// <summary>
/// Contains all relevant information to render a PDF page into an image.
/// </summary>
/// <param name="Dpi">The DPI scaling to use for rasterization of the PDF.</param>
/// <param name="Width">The width of the desired page. Use <see langword="null"/> if the original width should be used.</param>
/// <param name="Height">The height of the desired page. Use <see langword="null"/> if the original height should be used.</param>
/// <param name="WithAnnotations">Specifies whether annotations be rendered.</param>
/// <param name="WithFormFill">Specifies whether form filling will be rendered.</param>
/// <param name="WithAspectRatio">Specifies that <paramref name="Width"/> or <paramref name="Height"/> should be adjusted for aspect ratio (either one must be <see langword="null"/>).</param>
/// <param name="Rotation">Specifies the rotation at 90 degree intervals.</param>
/// <param name="AntiAliasing">Specifies which parts of the PDF should be anti-aliasing for rendering.</param>
/// <param name="BackgroundColor">Specifies the background color. Defaults to <see cref="SKColors.White"/>.</param>
/// <param name="Bounds">Specifies the bounds for the page relative to <see cref="PDFtoImage.Conversion.GetPageSizes(string,string)"/>. This can be used for clipping (bounds inside of page) or additional margins (bounds outside of page).</param>
/// <param name="UseTiling">Specifies that the PDF should be rendered as several segments and merged into the final image. This can help in cases where the output image is too large, causing corrupted images (e.g. missing text) or crashes.</param>
public readonly record struct PdfOptions(
int Dpi = 203,

Check warning on line 22 in PDFtoZPL/PdfOptions.cs

View workflow job for this annotation

GitHub Actions / SonarCloud

This method signature overlaps the one defined on line 37, the default parameter value can only be used with named arguments. (https://rules.sonarsource.com/csharp/RSPEC-3427)
int? Width = null,
int? Height = null,
bool WithAnnotations = false,
bool WithFormFill = false,
bool WithAspectRatio = false,
PdfRotation Rotation = PdfRotation.Rotate0,
PdfAntiAliasing AntiAliasing = PdfAntiAliasing.All,
SKColor? BackgroundColor = null,
RectangleF? Bounds = null,
bool UseTiling = false)
{
/// <summary>
/// Constructs <see cref="PdfOptions"/> with default values.
/// </summary>
public PdfOptions() : this(203, null, null, false, false, false, PdfRotation.Rotate0, PdfAntiAliasing.All, null, null, false) { }

/// <summary>
/// Implicit conversion to <see cref="PDFtoImage.RenderOptions"/>.
/// </summary>
/// <param name="pdfOptions">The options to convert.</param>
public static implicit operator RenderOptions(PdfOptions pdfOptions) => new(
pdfOptions.Dpi,
pdfOptions.Width,
pdfOptions.Height,
pdfOptions.WithAnnotations,
pdfOptions.WithFormFill,
pdfOptions.WithAspectRatio,
pdfOptions.Rotation,
pdfOptions.AntiAliasing,
pdfOptions.BackgroundColor,
pdfOptions.Bounds,
pdfOptions.UseTiling);
}
}
49 changes: 43 additions & 6 deletions PDFtoZPL/PublicAPI/monoandroid10.0/PublicAPI.Shipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,50 @@ PDFtoZPL.ZplOptions.SetLabelLength.get -> bool
PDFtoZPL.ZplOptions.SetLabelLength.init -> void
PDFtoZPL.ZplOptions.Threshold.get -> byte
PDFtoZPL.ZplOptions.Threshold.init -> void
PDFtoZPL.IZplOptions
PDFtoZPL.IZplOptions.DitheringKind.get -> PDFtoZPL.DitheringKind
PDFtoZPL.IZplOptions.DitheringKind.init -> void
PDFtoZPL.IZplOptions.EncodingKind.get -> PDFtoZPL.BitmapEncodingKind
PDFtoZPL.IZplOptions.EncodingKind.init -> void
PDFtoZPL.IZplOptions.GraphicFieldOnly.get -> bool
PDFtoZPL.IZplOptions.GraphicFieldOnly.init -> void
PDFtoZPL.IZplOptions.SetLabelLength.get -> bool
PDFtoZPL.IZplOptions.SetLabelLength.init -> void
PDFtoZPL.IZplOptions.Threshold.get -> byte
PDFtoZPL.IZplOptions.Threshold.init -> void
PDFtoZPL.PdfOptions
PDFtoZPL.PdfOptions.AntiAliasing.get -> PDFtoImage.PdfAntiAliasing
PDFtoZPL.PdfOptions.AntiAliasing.init -> void
PDFtoZPL.PdfOptions.BackgroundColor.get -> SkiaSharp.SKColor?
PDFtoZPL.PdfOptions.BackgroundColor.init -> void
PDFtoZPL.PdfOptions.Bounds.get -> System.Drawing.RectangleF?
PDFtoZPL.PdfOptions.Bounds.init -> void
PDFtoZPL.PdfOptions.Dpi.get -> int
PDFtoZPL.PdfOptions.Dpi.init -> void
PDFtoZPL.PdfOptions.Height.get -> int?
PDFtoZPL.PdfOptions.Height.init -> void
PDFtoZPL.PdfOptions.PdfOptions() -> void
PDFtoZPL.PdfOptions.Rotation.get -> PDFtoImage.PdfRotation
PDFtoZPL.PdfOptions.Rotation.init -> void
PDFtoZPL.PdfOptions.Width.get -> int?
PDFtoZPL.PdfOptions.Width.init -> void
PDFtoZPL.PdfOptions.WithAnnotations.get -> bool
PDFtoZPL.PdfOptions.WithAnnotations.init -> void
PDFtoZPL.PdfOptions.WithAspectRatio.get -> bool
PDFtoZPL.PdfOptions.WithAspectRatio.init -> void
PDFtoZPL.PdfOptions.WithFormFill.get -> bool
PDFtoZPL.PdfOptions.WithFormFill.init -> void
PDFtoZPL.PdfOptions.UseTiling.get -> bool
PDFtoZPL.PdfOptions.UseTiling.init -> void
PDFtoZPL.PdfOptions.PdfOptions(int Dpi = 203, int? Width = null, int? Height = null, bool WithAnnotations = false, bool WithFormFill = false, bool WithAspectRatio = false, PDFtoImage.PdfRotation Rotation = PDFtoImage.PdfRotation.Rotate0, PDFtoImage.PdfAntiAliasing AntiAliasing = PDFtoImage.PdfAntiAliasing.All, SkiaSharp.SKColor? BackgroundColor = null, System.Drawing.RectangleF? Bounds = null, bool UseTiling = false) -> void
static PDFtoZPL.PdfOptions.implicit operator PDFtoImage.RenderOptions(PDFtoZPL.PdfOptions pdfOptions) -> PDFtoImage.RenderOptions
static PDFtoZPL.Conversion.ConvertBitmap(byte[]! bitmapAsByteArray, PDFtoZPL.ZplOptions zplOptions = default(PDFtoZPL.ZplOptions)) -> string!
static PDFtoZPL.Conversion.ConvertBitmap(SkiaSharp.SKBitmap! bitmap, PDFtoZPL.ZplOptions zplOptions = default(PDFtoZPL.ZplOptions)) -> string!
static PDFtoZPL.Conversion.ConvertBitmap(string! bitmapPath, PDFtoZPL.ZplOptions zplOptions = default(PDFtoZPL.ZplOptions)) -> string!
static PDFtoZPL.Conversion.ConvertBitmap(System.IO.Stream! bitmapAsStream, bool leaveOpen = false, PDFtoZPL.ZplOptions zplOptions = default(PDFtoZPL.ZplOptions)) -> string!
static PDFtoZPL.Conversion.ConvertPdf(byte[]! pdfAsByteArray, string? password = null, PDFtoImage.RenderOptions pdfOptions = default(PDFtoImage.RenderOptions), PDFtoZPL.ZplOptions zplOptions = default(PDFtoZPL.ZplOptions)) -> System.Collections.Generic.IEnumerable<string!>!
static PDFtoZPL.Conversion.ConvertPdf(string! pdfAsBase64String, string? password = null, PDFtoImage.RenderOptions pdfOptions = default(PDFtoImage.RenderOptions), PDFtoZPL.ZplOptions zplOptions = default(PDFtoZPL.ZplOptions)) -> System.Collections.Generic.IEnumerable<string!>!
static PDFtoZPL.Conversion.ConvertPdf(System.IO.Stream! pdfStream, bool leaveOpen = false, string? password = null, PDFtoImage.RenderOptions pdfOptions = default(PDFtoImage.RenderOptions), PDFtoZPL.ZplOptions zplOptions = default(PDFtoZPL.ZplOptions)) -> System.Collections.Generic.IEnumerable<string!>!
static PDFtoZPL.Conversion.ConvertPdfPage(byte[]! pdfAsByteArray, string? password = null, int page = 0, PDFtoImage.RenderOptions pdfOptions = default(PDFtoImage.RenderOptions), PDFtoZPL.ZplOptions zplOptions = default(PDFtoZPL.ZplOptions)) -> string!
static PDFtoZPL.Conversion.ConvertPdfPage(string! pdfAsBase64String, string? password = null, int page = 0, PDFtoImage.RenderOptions pdfOptions = default(PDFtoImage.RenderOptions), PDFtoZPL.ZplOptions zplOptions = default(PDFtoZPL.ZplOptions)) -> string!
static PDFtoZPL.Conversion.ConvertPdfPage(System.IO.Stream! pdfStream, bool leaveOpen = false, string? password = null, int page = 0, PDFtoImage.RenderOptions pdfOptions = default(PDFtoImage.RenderOptions), PDFtoZPL.ZplOptions zplOptions = default(PDFtoZPL.ZplOptions)) -> string!
static PDFtoZPL.Conversion.ConvertPdf(byte[]! pdfAsByteArray, string? password = null, PDFtoZPL.PdfOptions pdfOptions = default(PDFtoZPL.PdfOptions), PDFtoZPL.ZplOptions zplOptions = default(PDFtoZPL.ZplOptions)) -> System.Collections.Generic.IEnumerable<string!>!
static PDFtoZPL.Conversion.ConvertPdf(string! pdfAsBase64String, string? password = null, PDFtoZPL.PdfOptions pdfOptions = default(PDFtoZPL.PdfOptions), PDFtoZPL.ZplOptions zplOptions = default(PDFtoZPL.ZplOptions)) -> System.Collections.Generic.IEnumerable<string!>!
static PDFtoZPL.Conversion.ConvertPdf(System.IO.Stream! pdfStream, bool leaveOpen = false, string? password = null, PDFtoZPL.PdfOptions pdfOptions = default(PDFtoZPL.PdfOptions), PDFtoZPL.ZplOptions zplOptions = default(PDFtoZPL.ZplOptions)) -> System.Collections.Generic.IEnumerable<string!>!
static PDFtoZPL.Conversion.ConvertPdfPage(byte[]! pdfAsByteArray, string? password = null, int page = 0, PDFtoZPL.PdfOptions pdfOptions = default(PDFtoZPL.PdfOptions), PDFtoZPL.ZplOptions zplOptions = default(PDFtoZPL.ZplOptions)) -> string!
static PDFtoZPL.Conversion.ConvertPdfPage(string! pdfAsBase64String, string? password = null, int page = 0, PDFtoZPL.PdfOptions pdfOptions = default(PDFtoZPL.PdfOptions), PDFtoZPL.ZplOptions zplOptions = default(PDFtoZPL.ZplOptions)) -> string!
static PDFtoZPL.Conversion.ConvertPdfPage(System.IO.Stream! pdfStream, bool leaveOpen = false, string? password = null, int page = 0, PDFtoZPL.PdfOptions pdfOptions = default(PDFtoZPL.PdfOptions), PDFtoZPL.ZplOptions zplOptions = default(PDFtoZPL.ZplOptions)) -> string!

0 comments on commit 925197d

Please sign in to comment.