Reputation: 107
I am printing a document and trying to change the size of paper but it's not working.
While i add paper size it prints the document in default dimentions. my paper size is not working.
namespace WC_manager
{
public partial class tagprint : Form
{
Zen.Barcode.Code39BarcodeDraw objCode = Zen.Barcode.BarcodeDrawFactory.Code39WithChecksum;
int tagNo = 0;
PrinterSettings ps = new PrinterSettings();
public tagprint()
{
InitializeComponent();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void printBtn_Click(object sender, EventArgs e)
{
if(tagNo != 0)
{
pictureBox1.Image = objCode.Draw(Convert.ToString(tagNo), 100);
var doc = new PrintDocument();
doc.PrintPage += new PrintPageEventHandler(ProvideContent);
doc.PrinterSettings.PrinterName = "Adobe PDF";
doc.DefaultPageSettings.PaperSize = new PaperSize("Custom",10,10);
doc.Print();
}
else
{
MessageBox.Show("Enter Valid Tag no");
}
}
private void tagTxtFld_TextChanged(object sender, EventArgs e)
{
tagNo = Convert.ToInt32(tagTxtFld.Text);
}
public void ProvideContent(object sender, PrintPageEventArgs e)
{
Graphics graphics = e.Graphics;
Font font = new Font("Courier New", 10);
float fontHeight = font.GetHeight();
graphics.DrawImage(objCode.Draw(Convert.ToString(tagNo), 20), 0, 2, 30, 30);
}
}
}
Upvotes: 1
Views: 3246
Reputation: 107
I was facing this issue just because I was taking the output in pdf format so that is why it was setting the by default page size. when chane the printer name. I got the output.
Upvotes: 1
Reputation: 70652
You are not specifying reasonable paper size dimensions:
doc.DefaultPageSettings.PaperSize = new PaperSize("Custom",10,10);
The second and third parameters are the width and height of the paper, respectively. But importantly, the units for these values is hundredths of an inch, always.
So you have asked the printer driver to print a page that is only 1/10th of an inch wide and high.
When I try this with my installed PDF driver, it ignores the size provided, and prints to a page that is standard Letter size (i.e. 8.5 x 11 inches).
If this is what you actually meant, then you need to use a printer that will accept paper of that size. You may find it difficult to do so.
But, more likely you intended some other size. For example, if you are trying to print on a page that is 10 inches square, you would need to pass 1000
for each of those values. Alternatively, if you are trying to print on a page that is 10 centimeters square, you would need to pass 394
for each value (and accept the fact that that's actually just a little bit more than 10 cm).
Bottom line: pass valid values for the paper width and height, and it will work. 10 hundredths of an inch is not a valid value for either of those parameters.
Upvotes: 0