diff --git a/src/BinaryKits.Zpl.Viewer/Helpers/UnitsHelper.cs b/src/BinaryKits.Zpl.Viewer/Helpers/UnitsHelper.cs new file mode 100644 index 00000000..9d1db722 --- /dev/null +++ b/src/BinaryKits.Zpl.Viewer/Helpers/UnitsHelper.cs @@ -0,0 +1,12 @@ +using System; + +namespace BinaryKits.Zpl.Viewer.Helpers +{ + static internal class UnitsHelper + { + static internal int ConvertMillimetersToNearestInch(double labelWidth) + { + return Convert.ToInt32(labelWidth / 25.4); + } + } +} diff --git a/src/BinaryKits.Zpl.Viewer/ZplElementDrawer.cs b/src/BinaryKits.Zpl.Viewer/ZplElementDrawer.cs index 70f2c5d8..f1642c7f 100644 --- a/src/BinaryKits.Zpl.Viewer/ZplElementDrawer.cs +++ b/src/BinaryKits.Zpl.Viewer/ZplElementDrawer.cs @@ -1,5 +1,6 @@ using BinaryKits.Zpl.Label.Elements; using BinaryKits.Zpl.Viewer.ElementDrawers; +using BinaryKits.Zpl.Viewer.Helpers; using SkiaSharp; using System; using System.Collections.Generic; @@ -10,6 +11,10 @@ namespace BinaryKits.Zpl.Viewer { public class ZplElementDrawer { + private const int PdfDpi = 72; + private const float ZplDpi = 203.2f; + private const float PdfScaleFactor = PdfDpi / ZplDpi; + private readonly DrawerOptions _drawerOptions; private readonly IPrinterStorage _printerStorage; private readonly IElementDrawer[] _elementDrawers; @@ -110,7 +115,13 @@ public List DrawMulti( // - When drawing PDF we need the Bitmap as well to fix inverted coloring Stream pdfStream = new MemoryStream(); using var document = SKDocument.CreatePdf(pdfStream); - using var pdfCanvas = document.BeginPage(labelImageWidth, labelImageHeight); + + using var pdfCanvas = document.BeginPage( + UnitsHelper.ConvertMillimetersToNearestInch(labelWidth) * PdfDpi, + UnitsHelper.ConvertMillimetersToNearestInch(labelHeight) * PdfDpi); + + pdfCanvas.Scale(PdfScaleFactor, PdfScaleFactor); + if (this._drawerOptions.PdfOutput == true) { skCanvas.AddCanvas(pdfCanvas);