-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert default DPI to 203; update PDFtoImage (#51)
- Loading branch information
Showing
22 changed files
with
565 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.