Hello all,
I am presently having a problem with printing in C#.
The problem is my customer provided me a pre printed paper and I
need to print value into some specific positions. But problem is C# for its
generic autofit to page nature dont let me doing this. Every time it is
decreasing whole page's size and also altering my value position into some
specific ratio. Can anyone tell me how can I come over that problem.
This is my code -
-
//I AM USING PrintDocument COMPONENT
-
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
-
{
-
//panelPrintData IS A PANEL CONTAING MY PRINTING PICTUREBOX,TEXTBOX,COMBO AND OTHERS NEED TO PRINT
-
printDoc(panelPrintData, e);
-
}
-
-
-
public void printDoc(Panel p,PrintPageEventArgs e)
-
{
-
try
-
{
-
foreach (object obj in p.Controls)
-
{
-
if (obj is TextBox)
-
{
-
TextBox txt = (TextBox)obj;
-
e.Graphics.DrawString(txt.Text, new Font("Arial", 10, FontStyle.Regular), Brushes.Black, txt.Left , txt.Top );
-
-
}
-
if (obj is Utility.LSInterfaces.IImagePrintable)
-
{
-
Utility.LSInterfaces.IImagePrintable img = (Utility.LSInterfaces.IImagePrintable)obj;
-
e.Graphics.DrawImage(img.Picture, img.Left , img.Top , img.Width, img.Height);
-
-
}
-
if (obj is LogiSoftUserControl.ResizableComponent.ResizablePictureBox)
-
{
-
LogiSoftUserControl.ResizableComponent.ResizablePictureBox img = (LogiSoftUserControl.ResizableComponent.ResizablePictureBox)obj;
-
e.Graphics.DrawImage(img.Picture, img.Left , img.Top , img.Width, img.Height);
-
-
}
-
if (obj is PictureBox)
-
{
-
PictureBox img = (PictureBox)obj;
-
e.Graphics.DrawImage(img.Image, img.Left , img.Top , img.Width, img.Height);
-
-
}
-
}
-
}
-
-
catch (ArgumentNullException)
-
{ }
-
-
-
}
-
-
-
//THIS IS BUTTON FOR PRINT
-
private void btnPrint_Click(object sender, EventArgs e)
-
{
-
DialogResult r = printDialog1.ShowDialog();
-
if (r == DialogResult.OK)
-
printDocument1.Print();
-
}
-
-
6 10173
Quick thoughts
A) Turn off auto size
B) Pre-format your document to the printable area of the printer so no scaling is required
Quick thoughts
A) Turn off auto size
B) Pre-format your document to the printable area of the printer so no scaling is required
A) Turn off auto size of what ?
B) If you can provide me . Some code of printable area (on my problem) will be helpful.....
Thanks
But problem is C# for its
generic autofit to page nature dont let me doing this.
Turn off "autofit to page"
turn off "autofit to page"
yes, but how to turn off autofit of a page ?
Thanks
Having never used the PrintDocument component I had to look it up at MSDN http://msdn.microsoft.com/en-us/libr...nt(VS.80).aspx
I took their sample and put it in a new project with nothing more than a file browser and a [Print] button.
Setting the e.Graphics.PageScale to 100 seemed to work for me.
I found this property by doing nothing more than typing e.Graphics. then looking at what IntelliSense showed me as available.
I've tested this on SnagIt printer (print to image), PrimoPDF (Print to PDF) and my Samsung CLP-510 - namespace FormPrinting
-
{
-
public partial class Form1 : Form
-
{
-
private Font printFont;
-
private StreamReader streamToPrint;
-
-
public Form1()
-
{
-
InitializeComponent();
-
}
-
-
private void btnPrint_Click(object sender, EventArgs e)
-
{
-
try
-
{
-
streamToPrint = new StreamReader
-
(browseFile1.Text);
-
try
-
{
-
printFont = new Font("Arial", 13);
-
PrintDocument pd = new PrintDocument();
-
pd.PrintPage += new PrintPageEventHandler
-
(this.pd_PrintPage);
-
pd.Print();
-
}
-
finally
-
{
-
streamToPrint.Close();
-
}
-
}
-
catch (Exception ex)
-
{
-
MessageBox.Show(ex.Message);
-
}
-
-
}
-
-
-
// The PrintPage event is raised for each page to be printed.
-
private void pd_PrintPage(object sender, PrintPageEventArgs ev)
-
{
-
-
ev.Graphics.PageScale = 100;// Print at 100% or 1:1 ratio
-
//ev.PageSettings.PrinterSettings.
-
ev.Graphics.DrawImageUnscaled(System.Drawing.Image.FromFile(browseFile1.Text),0,0);
-
ev.HasMorePages = false;
-
return; // Below here nothing runs. It is direct from the MSDN sample
-
-
float linesPerPage = 0;
-
float yPos = 0;
-
int count = 0;
-
float leftMargin = ev.MarginBounds.Left;
-
float topMargin = ev.MarginBounds.Top;
-
string line = null;
-
-
// Calculate the number of lines per page.
-
linesPerPage = ev.MarginBounds.Height /
-
printFont.GetHeight(ev.Graphics);
-
-
// Print each line of the file.
-
while (count < linesPerPage &&
-
((line = streamToPrint.ReadLine()) != null))
-
{
-
yPos = topMargin + (count *
-
printFont.GetHeight(ev.Graphics));
-
ev.Graphics.DrawString(line, printFont, Brushes.Black,
-
leftMargin, yPos, new StringFormat());
-
count++;
-
}
-
-
// If more lines exist, print another page.
-
if (line != null)
-
ev.HasMorePages = true;
-
else
-
ev.HasMorePages = false;
-
}
-
}
-
}
I do have concerns that your placement calculations are off though. - e.Graphics.DrawString(txt.Text, new Font("Arial", 10, FontStyle.Regular), Brushes.Black, txt.Left , txt.Top );
So you take the text of a text box,and paint it onto a panel at the location of your textbox.
I don't see how this takes into account the resolution of the printer.
The textbox location is in pixels from the upper-left corner of the form.
Coming down 100 pixel and right 200 pixels is meaningless without knowing the resolution of the printer.
If the printer is 100dpi then down 100 pixels is down 1 inch.
If the printer is 300dpi then down 100 pixels is down 1/3 inch
Maybe the issue you are running into is the AutoScale of the printing, but rather your drawing on the panel is actually scaled down.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Programatix |
last post by:
Hi,
I am working on the PrintDocument, PrintDialog, PageSetupDialog and
PrintPreviewControl components of Visual Studio .NET 2003. My developement
machine is running Windows XP.
There are...
|
by: Programatix |
last post by:
Hi,
I am working on the PrintDocument, PrintDialog, PageSetupDialog and
PrintPreviewControl components of Visual Studio .NET 2003. My developement
machine is running Windows XP.
There are...
|
by: DCraig |
last post by:
I'm having problems printing to a line printer from both Crystal Reports and
SQL Server reporting services using dotnet. When I try and print a report
from an application with Crystal I get the...
|
by: Stefania Scott |
last post by:
I am trying to print a word document from Access. The code I've
written works well in my computer but does not in the one were it is
needed.
Here the piece of code:
'doc path
strObjectPath =...
|
by: C-Services Holland b.v. |
last post by:
Hi all,
I've run into a problem trying to print from vb.net (2002) in Windows
98. To test it I've setup a single form with a button and the following
code:
'the form has a button called...
|
by: hamil |
last post by:
I am trying to print a graphic file (tif) and also use the PrintPreview
control, the PageSetup control, and the Print dialog control. The code
attached is a concatination of two examples taken out...
|
by: Teemu |
last post by:
I have an application created with VB6 and now I'm converting it to VB 2005.
Conversion is not so simple because printing is so much different.
In my app I have Timer-component, which is creates...
|
by: Sukh |
last post by:
Hi
I am stuck with a problem Can anyone help me out from this...
I am printing a report on pre-printed continue paper using dot-matrix
printer using vb.net.
Data is printing on all the...
|
by: Neo Geshel |
last post by:
Greetings.
BACKGROUND:
My sites are pure XHTML 1.1 with CSS 2.1 for markup. My pages are
delivered as application/xhtml+xml for all non-MS web clients, and as
text/xml for all MS web...
|
by: Brett |
last post by:
I have an ASP.NET page that displays work orders in a GridView. In that
GridView is a checkbox column. When the user clicks a "Print" button, I
create a report, using the .NET Framework printing...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |