Skip to content

Instantly share code, notes, and snippets.

@iblazhko
Last active November 3, 2023 05:35
Show Gist options
  • Select an option

  • Save iblazhko/84cf748314f2492cc24fda9b8ee97fe8 to your computer and use it in GitHub Desktop.

Select an option

Save iblazhko/84cf748314f2492cc24fda9b8ee97fe8 to your computer and use it in GitHub Desktop.
ZPL -> EPL -> PDF conversion in .NET using Neodynamic SDK
using System.Text;
using Neodynamic.SDK.EPLPrinter;
using Neodynamic.SDK.ZPLPrinter;
using EplRenderOutputFormat = Neodynamic.SDK.EPLPrinter.RenderOutputFormat;
using EplRenderOutputRotation = Neodynamic.SDK.EPLPrinter.RenderOutputRotation;
using ZplRenderOutputFormat = Neodynamic.SDK.ZPLPrinter.RenderOutputFormat;
using ZplRenderOutputRotation = Neodynamic.SDK.ZPLPrinter.RenderOutputRotation;
var zplLicenseOwner = "LICENSE OWNER";
var zplLicenseKey = "LICENSE KEY";
var eplLicenseOwner = "LICENSE OWNER";
var eplLicenseKey = "LICENSE KEY";
var zplText =
"""
^XA
^LRN
^MNY
^MFN,N
^LH10,12
^MCY
^POI
^PW812
^CI27
^FO284,524^BY3^BCN,107,N,N,N,A^FV420RG194E^FS
^FO66,792^BY3^BCN,208,N,N,N,A^FV1Z251V576894439040^FS
^FO20,431^CVY^BD3^FH_^FD068826RG194E[)>_1E01_1D961Z94439040_1DUPSN_1D251V57_1D305_1D_1D1/1_1D5_1DN_1D_1DTHATCHAM_1D_1E_04^FS
^FO15,7^A0N,20,24^FVROSLYN CARTER^FS
^FO15,27^A0N,20,24^FV01698534450^FS
^FO15,47^A0N,20,24^FVANTIBODY ANALYTICS^FS
^FO15,67^A0N,20,24^FVBRAIDHURST INDUSTRIAL ESTATE^FS
^FO15,87^A0N,20,24^FVMOTHERWELL ML13ST^FS
^FO15,142^A0N,28,32^FVSHIP TO: ^FS
^FO61,166^A0N,28,32^FVRACHEL POVEY^FS
^FO61,194^A0N,28,32^FV1635797000^FS
^FO61,222^A0N,28,32^FVINTEGRA BIOSCIENCES LTD^FS
^FO61,251^A0N,28,32^FVUNIT 2 RIVERMEAD^FS
^FO61,279^A0N,45,44^FVTHATCHAM RG194EP^FS
^FO446,9^A0N,30,34^FV5 KG^FS
^FO683,9^A0N,28,32^FV1 OF 1^FS
^FO508,51^A0N,22,26^FVSHP#: 251V 57TQ FD7^FS
^FO508,73^A0N,22,26^FVSHP WT: 5 KG^FS
^FO269,436^A0N,80,70^FVGBR 808 4-00^FS
^FO10,1031^A0N,22,26^FVBILLING: P/P^FS
^FO591,1035^A0N,60,64^FVEDI^FS
^FO10,1163^A0N,22,26^FVReference No.1: 4402361^FS
^FO175,1203^A0N,14,20^FVXOL 23.10.17 NV45 44.0A 10/2023*^FS
^FO9,670^A0N,56,58^FVUPS STANDARD^FS
^FO9,731^A0N,26,30^FVTRACKING #: 1Z 251 V57 68 9443 9040^FS
^FO689,650^GB124,125,124,B,0^FS
^FO0,648^GB811,14,14,B,0^FS
^FO0,423^GB812,4,4,B,0^FS
^FO244,423^GB4,225,4,B,0^FS
^FO0,774^GB812,5,5,B,0^FS
^FO0,1013^GB812,14,14,B,0^FS
^FO629,1147
^GFA,00969,00969,019,FFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000
FFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000
FFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000
FFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000
F0000000000001F8000000000000F000000000
F0000000000001F8000000000000F000000000
F0000000003F81F83FC000000000F000000000
F0000000003F81F83FC000000000F000000000
F000000000FFF9F9FFF000000000F000000000
F000000000FFF9F9FFF000000000F000000000
F000000000FFFFFFFFFC00000000F000000000
F000000000FFFFFFFFFC00000000F000000000
F000000000F07FFFF0FC00000000F000000000
F000000000F07FFFF0FC00000000F000000000
F000000000FC1FFFC3F000000000F000000000
F000000000FC1FFFC3F000000000F000000000
F000000000FFFFFFFFF000000000F000000000
F000000000FFFFFFFFF000000000F000000000
F0000000003FFFFFFFC000000000F000000000
F0000000003FFFFFFFC000000000F000000000
FFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000
FFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000
FFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000
F00000000001FFFFF00000000000F000000000
F00000000001FFFFF00000000000F000000000
F00000000003FFF9FC0000000000F000000000
F00000000003FFF9FC0000000000F000000000
F0000000003FE1F87FC000000000F000000000
F0000000003FE1F87FC000000000F000000000
F000000000FF81F83FF000000000F000000000
F000000000FF81F83FF000000000F000000000
F000000000FE01F803F000000000F000000000
F000000000FE01F803F000000000F000000000
F000000000F001F800F000000000F000000000
F000000000F001F800F000000000F000000000
F0000000000001F8000000000000F000000000
F0000000000001F8000000000000F0FFDC1C00
FFFFFFFFFFFFFFFFFFFFFFFFFFFFF0FFDC1C00
FFFFFFFFFFFFFFFFFFFFFFFFFFFFF00C1E3C00
FFFFFFFFFFFFFFFFFFFFFFFFFFFFF00C1E3C00
FFFFFFFFFFFFFFFFFFFFFFFFFFFFF00C1A2C00
FFFFFFFFFFFFFFFFFFFFFFFFFFFFF00C1B6C00
FFFFFFFFFFFFFFFFFFFFFFFFFFFFF00C1B6C00
0000000000000000000000000000000C1B6C00
0000000000000000000000000000000C19CC00
0000000000000000000000000000000C19CC00
0000000000000000000000000000000C19CC00
0000000000000000000000000000000C188C00
00000000000000000000000000000000000000
00000000000000000000000000000000000000
00000000000000000000000000000000000000
^DN
^XZ
""";
var zplBytes = Encoding.ASCII.GetBytes(zplText);
Console.WriteLine("ZPL (Base64):");
Console.WriteLine("==========");
Console.WriteLine(Convert.ToBase64String(zplBytes));
// ZPL -> PDF
using var zplToPdfPrinter = new ZPLPrinter(zplLicenseOwner, zplLicenseKey)
{
RenderOutputFormat = ZplRenderOutputFormat.PDF,
RenderOutputRotation = ZplRenderOutputRotation.None
};
var pdfFromZplBytes = zplToPdfPrinter.ProcessCommands(zplBytes).First();
Console.WriteLine("");
Console.WriteLine("");
Console.WriteLine("PDF from ZPL (Base64):");
Console.WriteLine("==========");
Console.WriteLine(Convert.ToBase64String(pdfFromZplBytes));
// ZPL -> EPL
using var zplToEplPrinter = new ZPLPrinter(zplLicenseOwner, zplLicenseKey)
{
RenderOutputFormat = ZplRenderOutputFormat.EPL,
RenderOutputRotation = ZplRenderOutputRotation.None
};
var eplImageBytes = zplToEplPrinter.ProcessCommands(zplBytes);
var eplBytes = eplImageBytes
.SelectMany(x =>
{
using var eplStream = new MemoryStream();
eplStream.Write(new[] { (byte)'\n', (byte)'N', (byte)'\n' });
eplStream.Write(x);
eplStream.Write(new[] { (byte)'\n', (byte)'P', (byte)'\n' });
return eplStream.ToArray();
})
.ToArray();
Console.WriteLine("");
Console.WriteLine("");
Console.WriteLine("EPL (Base64):");
Console.WriteLine("==========");
Console.WriteLine(Convert.ToBase64String(eplBytes));
// EPL -> PDF
using var eplToPdfPrinter = new EPLPrinter(eplLicenseOwner, eplLicenseKey)
{
RenderOutputFormat = EplRenderOutputFormat.PDF,
RenderOutputRotation = EplRenderOutputRotation.None
};
var pdfFromEplBytes = eplToPdfPrinter.ProcessCommands(eplBytes).First();
Console.WriteLine("");
Console.WriteLine("");
Console.WriteLine("PDF from EPL (Base64):");
Console.WriteLine("==========");
Console.WriteLine(Convert.ToBase64String(pdfFromEplBytes));
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Neodynamic.SDK.EPLPrinter" Version="2.0.0" />
<PackageReference Include="Neodynamic.SDK.ZPLPrinter" Version="5.0.23.829" />
<PackageReference Include="SkiaSharp" Version="2.88.6" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.88.6" Condition="$([MSBuild]::IsOSPlatform('Linux'))" />
<PackageReference Include="SkiaSharp.NativeAssets.MacOS" Version="2.88.6" Condition="$([MSBuild]::IsOSPlatform('OSX'))" />
<PackageReference Include="SkiaSharp.NativeAssets.Windows" Version="2.88.6" Condition="$([MSBuild]::IsOSPlatform('Windows'))" />
</ItemGroup>
</Project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment