Skip to content

Instantly share code, notes, and snippets.

@karronoli
Last active May 9, 2017 02:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karronoli/5f3c02da84f20c3432700511d5b6aee7 to your computer and use it in GitHub Desktop.
Save karronoli/5f3c02da84f20c3432700511d5b6aee7 to your computer and use it in GitHub Desktop.
Example by using TinySato
# Adjust example
$dpi = 203;
$inch2mm = 25.4;
$dot2mm = $inch2mm / $dpi;
$mm2dot = 1 / $dot2mm;
[int]$height = [math]::Round(50.0 * $mm2dot);
[int]$width = [math]::Round(88.0 * $mm2dot);
[int]$sub_width = [math]::Round(85.0 * $mm2dot);
[int]$sub_height = [math]::Round(50.0 * $mm2dot);
Add-Type -Path .\TinySato.dll;
$sato = New-Object -TypeName TinySato.Printer -ArgumentList "T408v";
$sato.SetGapSizeBetweenLabels([math]::Round(2.0 * $mm2dot));
$sato.SetPaperSize($height, $width);
$sato.SetStartPosition([math]::Round(1.0 * $mm2dot), 0);
for ( $y = 1; $y -lt 50; ++$y )
{
$sato.MoveToX([Math]::Round(5.0 * $mm2dot));
$sato.MoveToY([Math]::Round($y * $mm2dot));
$w = if ($y % 10 -eq 0) { 2 } else { 1 }
$l = if ($y % 10 -eq 0) { [Math]::Round(2.0 * $mm2dot) } else { [Math]::Round(1.0 * $mm2dot) }
$sato.Add([string]::Format("FW{0:D2}H{1}", $w, $l));
}
for ( $x = 1; $x -lt 85; ++$x )
{
$sato.MoveToX([Math]::Round($x * $mm2dot));
$sato.MoveToY([Math]::Round(5.0 * $mm2dot));
$w = if ($x % 10 -eq 0) { 2 } else { 1 }
$l = if ($x % 10 -eq 0) { [Math]::Round(2.0 * $mm2dot) } else { [Math]::Round(1.0 * $mm2dot) }
$sato.Add([string]::Format("FW{0:D2}V{1}", $w , $l));
}
$font = New-Object System.Drawing.Font -ArgumentList "Consolas", 30;
$bitmap = New-Object System.Drawing.Bitmap -ArgumentList $sub_width, $sub_height;
$g = [System.Drawing.Graphics]::FromImage($bitmap);
$sf = New-Object System.Drawing.StringFormat;
$box = New-Object System.Drawing.Rectangle -ArgumentList 0, 0, $bitmap.Width, $bitmap.Height;
$g.FillRectangle([System.Drawing.Brushes]::White, $box);
$pf = New-Object System.Drawing.PointF -ArgumentList 80, 80;
$pwd = pwd;
$logo = [System.Drawing.Image]::FromFile([system.io.path]::combine($pwd.ProviderPath, "logo.png"));
$g.DrawImage($logo, $pf)
$sf.Alignment = [System.Drawing.StringAlignment]::Near;
$sf.LineAlignment = [System.Drawing.StringAlignment]::Far;
$g.DrawString("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", $font, [System.Drawing.Brushes]::Black, [system.drawing.rectanglef]$box, $sf);
$sato.MoveToX([math]::Round(5.3 * $mm2dot));
$sato.MoveToY(1);
$sato.Graphic.AddGraphic($bitmap);
$sato.MoveToX([math]::Round(10.0 * $mm2dot));
$sato.MoveToY([math]::Round(10.0 * $mm2dot));
$sato.Barcode.AddCODE128(1, [math]::Round(5.0 * $mm2dot), "HELLO");
$sato.Send(1);
$sato.Dispose();
[CmdletBinding()]
Param(
[int]$count,
[string]$printer = "T408v"
)
Add-Type -AssemblyName System.Drawing
$dpi = 203;
$inch2mm = 25.4;
$dot2mm = $inch2mm / $dpi;
$mm2dot = 1 / $dot2mm;
[int]$height = [math]::Round(213.0 * $mm2dot);
[int]$width = [math]::Round(109.0 * $mm2dot);
Add-Type -Path .\TinySato.dll;
$sato = New-Object -TypeName TinySato.Printer -ArgumentList $printer;
$sato.SetPaperSize($height, $width);
$bitmap = New-Object System.Drawing.Bitmap -ArgumentList $width, $height;
$g = [System.Drawing.Graphics]::FromImage($bitmap);
$sf = New-Object System.Drawing.StringFormat;
$box = New-Object System.Drawing.Rectangle -ArgumentList 0, 0, $bitmap.Width, $bitmap.Height;
$g.FillRectangle([System.Drawing.Brushes]::White, $box);
for ( $i = 0; $i -lt $count; ++$i )
{
"Processing... count:" + $i
$sato.MoveToX(1);
$sato.MoveToY(1);
$sato.Graphic.AddGraphic($bitmap);
$sato.MoveToX(60.0 * $mm2dot);
$sato.MoveToY(80.0 * $mm2dot);
$sato.Add("L0101");
$sato.Add("OB" + $i);
$sato.SetPageNumber(1);
$sato.AddStream();
}
$sent = $sato.Send();
"Sent Length:" + $sent
$sato.Dispose();
Add-Type -AssemblyName System.Drawing
$dpi = 203;
$inch2mm = 25.4;
$dot2mm = $inch2mm / $dpi;
$mm2dot = 1 / $dot2mm;
# PD-A 85mm x 50mm
[int]$height = [math]::Round(50.0 * $mm2dot);
[int]$width = [math]::Round(88.0 * $mm2dot);
[int]$sub_width = [math]::Round(85.0 * $mm2dot);
[int]$sub_height = [math]::Round(50.0 * $mm2dot);
Add-Type -Path .\TinySato.dll;
$sato = New-Object -TypeName TinySato.Printer -ArgumentList "T408v";
$sato.SetGapSizeBetweenLabels([math]::Round(2.0 * $mm2dot));
$sato.SetPaperSize($height, $width);
$sato.SetStartPosition(0, 0);
$bitmap = New-Object System.Drawing.Bitmap -ArgumentList $sub_width, $sub_height;
$g = [System.Drawing.Graphics]::FromImage($bitmap);
$box = New-Object System.Drawing.Rectangle -ArgumentList 0, 0, $bitmap.Width, $bitmap.Height;
$g.FillRectangle([System.Drawing.Brushes]::White, $box);
$pwd = pwd;
$logo = [System.Drawing.Image]::FromFile([system.io.path]::combine($pwd.ProviderPath, "image.png"));
$g.DrawImage($logo, 0, 0, $sub_width, $sub_height)
$sato.MoveToX([math]::Round(1.0 * $mm2dot));
$sato.MoveToY(1);
$sato.Graphic.AddGraphic($bitmap);
$sato.Send(1);
$sato.Dispose();
[CmdletBinding()]
Param(
[string]$str,
[int]$size
)
Add-Type -AssemblyName System.Drawing
$dpi = 203;
$inch2mm = 25.4;
$dot2mm = $inch2mm / $dpi;
$mm2dot = 1 / $dot2mm;
[int]$height = [math]::Round(20.0 * $mm2dot);
[int]$width = [math]::Round(53.0 * $mm2dot);
Add-Type -Path .\TinySato.dll;
$sato = New-Object -TypeName TinySato.Printer -ArgumentList "T408v";
$sato.SetPaperSize($height, $width);
$font = New-Object System.Drawing.Font -ArgumentList "Consolas", $size;
$bitmap = New-Object System.Drawing.Bitmap -ArgumentList $width, $height;
$g = [System.Drawing.Graphics]::FromImage($bitmap);
$sf = New-Object System.Drawing.StringFormat;
$box = New-Object System.Drawing.Rectangle -ArgumentList 0, 0, $bitmap.Width, $bitmap.Height;
$g.FillRectangle([System.Drawing.Brushes]::White, $box);
$sf.Alignment = [System.Drawing.StringAlignment]::Center;
$sf.LineAlignment = [System.Drawing.StringAlignment]::Center;
$g.DrawString($str, $font, [System.Drawing.Brushes]::Black, [system.drawing.rectanglef]$box, $sf);
$sato.MoveToX(1);
$sato.MoveToY(1);
$sato.Graphic.AddGraphic($bitmap);
$sato.SetPageNumber(1);
$sato.Send();
$sato.Dispose();
[CmdletBinding()]
Param(
[string]$name = "名前",
[string]$furigana = "なまえ",
[string]$romaji = "Namae",
[int]$size
)
Add-Type -AssemblyName System.Drawing
$dpi = 203;
$inch2mm = 25.4;
$dot2mm = $inch2mm / $dpi;
$mm2dot = 1 / $dot2mm;
[int]$height = [math]::Round(50.0 * $mm2dot);
[int]$width = [math]::Round(88.0 * $mm2dot);
[int]$sub_width = [math]::Round(85.0 * $mm2dot);
[int]$sub_height = [math]::Round(50.0 * $mm2dot);
Add-Type -Path .\TinySato.dll;
$sato = New-Object -TypeName TinySato.Printer -ArgumentList "T408v";
$sato.SetGapSizeBetweenLabels([math]::Round(2.0 * $mm2dot));
$sato.SetPaperSize($height, $width);
$sato.SetStartPosition([math]::Round(1.0 * $mm2dot), 0);
$font = New-Object System.Drawing.Font -ArgumentList "Segoe UI Symbol", $size;
$bitmap = New-Object System.Drawing.Bitmap -ArgumentList $sub_width, $sub_height;
$g = [System.Drawing.Graphics]::FromImage($bitmap);
$sf = New-Object System.Drawing.StringFormat;
$box = New-Object System.Drawing.Rectangle -ArgumentList 0, 0, $bitmap.Width, $bitmap.Height;
$g.FillRectangle([System.Drawing.Brushes]::White, $box);
$pf = New-Object System.Drawing.PointF -ArgumentList 100, 20;
$pwd = pwd;
$logo = [System.Drawing.Image]::FromFile([system.io.path]::combine($pwd.ProviderPath, "logo.png"));
$g.DrawImage($logo, 350, 20, ($logo.Width * 0.8), ($logo.Height * 0.8))
$sf.Alignment = [System.Drawing.StringAlignment]::Near;
$sf.Alignment = [System.Drawing.StringAlignment]::Center;
$sf.LineAlignment = [System.Drawing.StringAlignment]::Near;
$g.DrawString($furigana, (New-Object System.Drawing.Font -ArgumentList "Consolas", ($size / 2)), [System.Drawing.Brushes]::Black, (New-Object System.Drawing.RectangleF -ArgumentList 20, 120, $bitmap.Width, $bitmap.Height), $sf);
$g.DrawString($name, $font, [System.Drawing.Brushes]::Black, (New-Object System.Drawing.RectangleF -ArgumentList 0, 150, $bitmap.Width, $bitmap.Height), $sf);
$g.DrawString($romaji, (New-Object System.Drawing.Font -ArgumentList "Consolas", ($size * 0.7)), [System.Drawing.Brushes]::Black, (New-Object System.Drawing.RectangleF -ArgumentList 0, 240, $bitmap.Width, $bitmap.Height), $sf);
$sato.MoveToX([math]::Round(2 * $mm2dot));
$sato.MoveToY([math]::Round(5.0 * $mm2dot));
$sato.Graphic.AddGraphic($bitmap);
$sato.Send(1);
$sato.Dispose();
[CmdletBinding()]
Param(
[string]$body,
[string]$barcode
)
Add-Type -AssemblyName System.Drawing
$dpi = 203;
$inch2mm = 25.4;
$dot2mm = $inch2mm / $dpi;
$mm2dot = 1 / $dot2mm;
[int]$height = [math]::Round(20.0 * $mm2dot);
[int]$width = [math]::Round(53.0 * $mm2dot);
[int]$sub_height = [math]::Round(20.0 * $mm2dot);
[int]$sub_width = [math]::Round(40.0 * $mm2dot);
[int]$sub_width = $width
Add-Type -Path .\TinySato.dll;
$sato = New-Object -TypeName TinySato.Printer -ArgumentList "T408v";
$sato.SetPaperSize($height, $width);
$font = New-Object System.Drawing.Font -ArgumentList "Consolas", 23;
$bitmap = New-Object System.Drawing.Bitmap -ArgumentList $sub_width, $sub_height;
$g = [System.Drawing.Graphics]::FromImage($bitmap);
$sf = New-Object System.Drawing.StringFormat;
$box = New-Object System.Drawing.Rectangle -ArgumentList 0, 0, $bitmap.Width, $bitmap.Height;
$g.FillRectangle([System.Drawing.Brushes]::White, $box);
$pwd = pwd;
$logo = [System.Drawing.Image]::FromFile([system.io.path]::combine($pwd.ProviderPath, "logo.png"));
$pf = New-Object System.Drawing.PointF -ArgumentList 32, 32;
$g.DrawImage($logo, 8, 12, 25 * $mm2dot, 5 * $mm2dot)
$sf.Alignment = [System.Drawing.StringAlignment]::Near;
$sf.LineAlignment = [System.Drawing.StringAlignment]::Center;
$textbox1 = New-Object System.Drawing.RectangleF -ArgumentList 0, 5, $bitmap.Width, $bitmap.Height;
$g.DrawString($body, $font, [System.Drawing.Brushes]::Black, $textbox1, $sf);
$font2 = New-Object System.Drawing.Font -ArgumentList "Consolas", 12;
$textbox2 = New-Object System.Drawing.RectangleF -ArgumentList 285, 6, 160, 40;
$g.DrawString($barcode, $font2, [System.Drawing.Brushes]::Black, $textbox2, $sf);
$sato.MoveToX(3 * $mm2dot);
$sato.MoveToY(1);
$sato.Graphic.AddGraphic($bitmap);
$sato.MoveToX(42.0 * $mm2dot);
$sato.MoveToY(6.0 * $mm2dot);
$sato.Add("2D30,M,02,1,0");
$sato.Add([string]::format("DS2,{0}", $barcode));
$sato.SetPageNumber(1);
$sato.Send();
$sato.Dispose();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment