473,394 Members | 1,371 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

how to access printer and print data in c#?

i dont know why there is an error in my code..in the code "app.ActiveDocument.PrintOutOld"...there's an error 'no overload for method..' ..anyone can help me..please?..thanks!


// Create an Application object
Expand|Select|Wrap|Line Numbers
  1.                     Word.ApplicationClass ac = new Word.ApplicationClass();
  2.                     Word._Application app = ac.Application;
  3.  
  4.                     // I'm setting all of the alerts to be off as I am trying to get
  5.                     // this to print in the background
  6.                     app.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone;
  7.  
  8.                     // Open the document to print...
  9.                     object filename = @"L:\RESEARCH\thesis9999\print.dotx";
  10.                     object missingValue = Type.Missing;
  11.  
  12.                     // Using OpenOld so as to be compatible with other versions of Word
  13.                     Word.Document document = app.Documents.OpenOld(ref filename,
  14.                     ref missingValue, ref missingValue,
  15.                     ref missingValue, ref missingValue, ref missingValue,
  16.                     ref missingValue, ref missingValue, ref missingValue, ref missingValue);
  17.  
  18.                     // Set the active printer
  19.                     //app.ActivePrinter = "HP Deskjet D2600 series";
  20.                     app.ActivePrinter = "USB001";
  21.                     object myTrue = true; // Print in background
  22.                     object myFalse = false;
  23.  
  24.                     //Using PrintOutOld to be version independent
  25.                     app.ActiveDocument.PrintOutOld(ref myTrue,
  26.                             ref myFalse, ref missingValue, ref missingValue, ref missingValue,
  27.                             missingValue, ref missingValue,
  28.                             ref missingValue, ref missingValue, ref missingValue, ref myFalse,
  29.                             ref missingValue, ref missingValue);
  30.  
  31.  
  32.                     app.Documents.Close(ref missingValue, ref missingValue, ref missingValue);
  33.  
  34.                     // Make sure all of the documents are gone from the queue
  35.                     while (app.BackgroundPrintingStatus > 0)
  36.                     {
  37.                         System.Threading.Thread.Sleep(250);
  38.                     }
  39.  
  40.                     app.Quit(ref missingValue, ref missingValue, ref missingValue);
Oct 13 '11 #1
2 4094
From MSDN: http://msdn.microsoft.com/en-us/libr...(v=vs.71).aspx

The example code replaces the existing event handlers. The form is printed when printButton is clicked.

Expand|Select|Wrap|Line Numbers
  1. [System.Runtime.InteropServices.DllImport("gdi32.dll")]
  2. public static extern long BitBlt (IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop);
  3. private Bitmap memoryImage;
  4. private void CaptureScreen()
  5. {
  6.    Graphics mygraphics = this.CreateGraphics();
  7.    Size s = this.Size;
  8.    memoryImage = new Bitmap(s.Width, s.Height, mygraphics);
  9.    Graphics memoryGraphics = Graphics.FromImage(memoryImage);
  10.    IntPtr dc1 = mygraphics.GetHdc();
  11.    IntPtr dc2 = memoryGraphics.GetHdc();
  12.    BitBlt(dc2, 0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height, dc1, 0, 0, 13369376);
  13.    mygraphics.ReleaseHdc(dc1);
  14.    memoryGraphics.ReleaseHdc(dc2);
  15. }
  16. private void printDocument1_PrintPage(System.Object sender, System.Drawing.Printing.PrintPageEventArgs e)
  17. {
  18.    e.Graphics.DrawImage(memoryImage, 0, 0);
  19. }
  20. private void printButton_Click(System.Object sender, System.EventArgs e)
  21. {
  22.    CaptureScreen();
  23.    printDocument1.Print();
  24. }
Compiling the Code

This example requires:

A PrintDocument component named printDocument1 with a PrintPage event handler.
A Button named printButton with a Click event handler.

http://msdn.microsoft.com/en-us/libr...(v=vs.71).aspx
Oct 16 '11 #2
thanks!!!...God bless!!!
Oct 17 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Rob | last post by:
I'm having a problem with the printer for a program I've created. I have to recreate a data table on a page to be printed. Earlier today it worked fine; however, I am now having an odd problem:...
0
by: Patrick | last post by:
Hi all, I've installed the latest MDAC and Jet service packs on Windows 2000. On Linux I've the latest MySQL and MyODBC3.51. Using the ODBC Administrator I've set up a connection, ran the test...
0
by: RDI | last post by:
I need to watch a certain print spooler and if a print job appears, extract the print data to a PRN file on the hard disk and delete it from the spooler. Can VB.Net do this? If so, can someone...
6
by: notregister | last post by:
hi, i have been trying to send a printer-ready data to an unknown printer to print. the reason why the printer is unknown is that i do no wish installed any printer driver. so at the end my...
2
by: Mitul | last post by:
Hello friends, I am getting stuck at a point in my project. I would like to give functionality of print data from site. but there is a problem is that if there are lots of data which takes...
2
by: David Dawson | last post by:
I have no experience using MS Access to interface with MySQL. I have a tiny MySQL database that might need to have Access connect with it over the internet and grab data/update etc. Is this...
7
by: DanZaMan | last post by:
Just a query about how clever access is, I'm using access 97. When using a "split" database with a separate front-end and with the data file on a separate server on the network how does access...
1
hariharanmca
by: hariharanmca | last post by:
any know how to Print data through Store Procedure to the printer Directly
1
by: mehdi1727 | last post by:
How Print Data Grid View in C#.Net??????????
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
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...
0
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
0
BarryA
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...
1
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...
0
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.