ZEBRA label printing - c#

I need to print labels on my ZEBRA S4M printer.
PrintDocument pd = new PrintDocument { PrinterSettings = new PrinterSettings { PrinterName = "ZDesigner S4M-203dpi ZPL" } };
pd.DefaultPageSettings.Landscape = true;
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
pd.Print();
And when using Portrait landscape - it's alright, but in Landscape mode I have a big space from the left side of label.. How can I print a horizontal text on my labels?
Thanks a lot.
ADDED
I think that this problem is possible because of small PrintingArea property that I can't change. It's size 300x200 and real paper size is about 200x500...

I believe you have two options, either try changing your default paper size, or performing a translate.

Related

Printing to a smartcard printer not working, ideas?

I'm trying to print userdata to a smartcard using a smartcard printer but the result is that i'm getting blank cards out of the printer. I've been stuck on this problem for a day now and there is no(findable) answer on the internet.
With printing to the printer (it's an Datacard SP35 Plus) using no custom papersize and no printdialog. the result is an empty card.
using (PrintDocument pd = new PrintDocument())
{
pd.PrintPage += (object sender, PrintPageEventArgs e) =>
{
Image i = Image.FromFile("E:\\tmp.png");
e.Graphics.DrawImage(i, e.MarginBounds);
};
pd.Print();
}
The image is present and visible and plenty of size.
Furthermore, I came across a post that said that the size of the printdocument has to be set
PaperSize papersize = new PaperSize("Custom", Convert.ToInt32(widthInInch * 100), Convert.ToInt32(heightInInch * 100));
pd.DefaultPageSettings.PaperSize = papersize;
pd.PrinterSettings.DefaultPageSettings.PaperSize = papersize;
But didnt result in a visible print.
I've also tried
e.Graphics.DrawImage(i, 0, 0);
instead of
e.Graphics.DrawImage(i, e.MarginBounds);
but didn't result in a visible print.
The widthInInch is 3.38 and the heightInInch is 2.13(The default size of an CR80 card). This also resulted in an empty card.
When I print to PDF the result is visible and correct(I do not know the whitespace, of course).
Does somebody see the problem or has worked out something similar?
I "fixed" it by rewriting my application to UWP. This uses the new print function and made it work as intended.

In C#, what's the difference of PrinterSettings from a PrintDocument and PrintDialog?

Well, it's a very strange problem, and I already found a black magical solution. I'm curious about the reason.
I'm writing a program which use Brother QL-700 label printer to print labels. I need the labels be printed without showing the printer dialog.
The label printer support different size of label rolls and the default size of label roll is 29mm, while what I need is 62mm. I found that I can set the Page Size by
PrintDocument doc = new PrintDocument();
PaperSize size = new PaperSize() ;
size.Width = 244;//2.44 inch = 62mm
size.Height = 244;
size.RawKind = 256;//RawKind=0 does not work, I don't know why
doc.PrinterSettings.DefaultPageSettings.PaperSize = size;
However, this won't work, the driver of Printer would show a message saying the width does not fit.
But if I change the copy the PrinterSettings from a PrintDialog(), without showing it,
PrintDialog dlg = new PrintDialog();
doc.PrinterSettings = dlg.PrinterSettings;
Then it works.
In conclusion, what I don't understand is why
size.RawKind = 256;
and
PrintDialog dlg = new PrintDialog();
doc.PrinterSettings = dlg.PrinterSettings;
can make the printer work?
The documentation for RawKind does not state that 0 is a valid value. It also states that any value above 118 indicates a custom paper size. Since you are specifying a custom paper size, the value of 256 indicates that the size is custom and that is why it works.

Different print dimensions from different printers by same C# Windows Form Application

The same C# application is printing text in different dimension by different printers. The text printed is same along x-axis but differ along y-axis. I mean in one print, the text is slightly(4-5mm) upwards than other print but same along x-axis i.e. no text is backwards or forward than text of other print. Eg:
"This text is same along x-axis but differ among y-axis"(Print 1)
"This text is same along x-axis but differ among y-axis"(Print 2)
My Page settings are:
private void PaperSettings()
{
PaperSize paperSize = new PaperSize("New Page", 377, 1095);
paperSize.RawKind = (int)PaperKind.Custom;
printDocument1.DefaultPageSettings.PaperSize = paperSize;
Margins margin = new Margins(0, 0, 0, 0);
printDocument1.DefaultPageSettings.Margins = margin;
printDocument1.DefaultPageSettings.Landscape = true;
PrinterSettings printer = new PrinterSettings();
printDocument1.PrinterSettings.PrinterName = printer.PrinterName;
}
On changing the paper width(377) manually, the text is shifted upwards on increasing it and downwards on decreasing it. However the same page settings is not working on different printers*(HP Officejet J3500 printing text slightly downdards than text printed by HP Deskjet 1510).*
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawString(label1Payee.Text, label1Payee.Font, Brushes.Black, label1Payee.Location.X, label1Payee.Location.Y);
e.Graphics.DrawString(labelAmountWords.Text, labelAmountWords.Font, Brushes.Black, labelAmountWords.Location.X, labelAmountWords.Location.Y);
e.Graphics.DrawString(labelDate1.Text, labelDate1.Font, Brushes.Black, labelDate1.Location.X, labelDate1.Location.Y);
e.Graphics.DrawString(labelAmount.Text, labelAmount.Font, Brushes.Black, labelAmount.Location.X, labelAmount.Location.Y);
}
Any Suggestions..Thank you!
Every printer has some margins where the printer does not print. These margins are called printer's HardMargins. Say you want to print something on co-ordinates (0, 0) but my printer prints it on (16, 16). This (HardMarginX, HardMarginY).
Every printer may differ from hard margins. e.g. My HP LaserJet 1020 is (16, 16) but my Canon Pixma ip1300 is (0, 0).
So what you have to do is, get the HardMarginX and HardMarginY, do some math and print where you want to print.
One more thing, if you try to print beyond these margins, document may be clipped. Search for the PrintableArea of the printer over internet and you get the idea.

C# printing page height according to the content

I'm doing some printing work in c# and got a small problem. I'm working with a thermal receipt printer. I want to set the height of the page according to the content of it. Which means, when I have fewer items, the page should be smaller and when I have long list of items, the page should grow accordingly.
I tried to set it with PrintPageEventArgs but this didn't result in satisfied result. How can this be done?
Thanks
Just take care of the width. Printer will cut the paper after the last printed element on the last page.
Just for the record. I had the same issue.
At the end what i had done is:
Int Line= starting position (in pixels)
For each line I want to print -> g.DrawString("text",font,xx,margin,line);
and then just before print
ps.Height = Line;
pd.Print();
pd is -> PrintDocument pd = new PrintDocument();
ps is -> PaperSize ps = new PaperSize("",my_width,1));
`enter code here` pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
pd.PrintController = new StandardPrintController();
pd.DefaultPageSettings.Margins.Left = 0;
pd.DefaultPageSettings.Margins.Right = 0;
pd.DefaultPageSettings.Margins.Top = 0;
pd.DefaultPageSettings.Margins.Bottom = 0;
pd.DefaultPageSettings.PaperSize = ps;

Issue printing image as expected

I have an image that I'm trying to print to legal size. However, there are a few challenges to this.
The image will vary in size. This is because I'm using a control that has limited print options but can export to an image.
I want to maximize the print area on the page. Smallest margin possible
The user needs to be able to select a printer and set options
Here's the code I'm using:
PrintDocument pd = new PrintDocument();
pd.PrintPage += (sender, args) =>
{
Image i = Image.FromFile(Globals.TempDirectory + #"\temp.jpg");
Point p = new Point(100, 100);
Margins margins = new Margins(50, 50, 50, 50);
pd.DefaultPageSettings.Margins = margins;
args.Graphics.DrawImage(i, p);
};
pd.Print();
I've been having trouble with this because I can't set margins and can't seem to get the print out right. I want it to print in legal but when I print the image, it's not rotated properly and it just prints to a default printer. I'm up for anything to get this to work.
Printing in C# sucks
try a
printdialog()
to allow the user to select a printer and settings. once you get that to work the rest of it might click for you.
Edit: Showing you where and how to use it.
PrintDialog pDialog = new PrintDialog();
if (pDialog.ShowDialog() == DialogResult.OK)
{
pd.PrinterSettings = pDialog.PrinterSettings;
pd.Print();
}

Categories

Resources