2012-11-13 15 views
6

पर प्रिंट करें मैंने RichTextBox की सामग्री मुद्रित करने का प्रयास किया है और यदि मैं प्रिंटर पर प्रिंट करता हूं तो बहुत सारे बग हैं। लेकिन जब मैं एक्सपीएस-फाइल (विंडोज़ में एक्सपीएस-प्रिंटर के माध्यम से) पर प्रिंट कर रहा हूं और फिर प्रिंटर पर इस फाइल को प्रिंट कर रहा हूं तो सब ठीक है।एक्सपीएस-फाइल में प्रिंट करें और फिर इसे प्रिंटर

तो क्या मैं इन सभी चीजों को प्रोग्रामेटिक रूप से कर सकता हूं?

यहाँ मेरी मुद्रण विधि है:

public int PrintRotate(bool rotate, PrintPageEventArgs e, int charFrom, int charTo) 
    { 
     //Calculate the area to render and print 
     RECT rectToPrint; 
     rectToPrint.Top = (int)(e.MarginBounds.Top * anInch); 
     rectToPrint.Bottom = (int)(e.MarginBounds.Bottom * anInch); 
     rectToPrint.Left = (int)(e.MarginBounds.Left * anInch); 
     rectToPrint.Right = (int)(e.MarginBounds.Right * anInch); 

     //Calculate the size of the page 
     RECT rectPage; 
     rectPage.Top = (int)(e.PageBounds.Top * anInch); 
     rectPage.Bottom = (int)(e.PageBounds.Bottom * anInch); 
     rectPage.Left = (int)(e.PageBounds.Left * anInch); 
     rectPage.Right = (int)(e.PageBounds.Right * anInch); 

     IntPtr hdc = e.Graphics.GetHdc(); 

     FORMATRANGE fmtRange; 
     fmtRange.chrg.cpMax = charTo;    //Indicate character from to character to 
     fmtRange.chrg.cpMin = charFrom; 
     fmtRange.hdc = hdc;     //Use the same DC for measuring and rendering 
     fmtRange.hdcTarget = hdc;    //Point at printer hDC 
     fmtRange.rc = rectToPrint;    //Indicate the area on page to print 
     fmtRange.rcPage = rectPage;   //Indicate size of page 


     SetGraphicsMode(fmtRange.hdc, GM_ADVANCED); 

     XFORM par = new XFORM(); 

     par = new XFORM(); 
     par.eM11 = 1; 
     par.eM12 = 0; 
     par.eM21 = 0; 
     par.eM22 = 1; 
     par.eDx = -e.PageSettings.Margins.Left/100 * e.PageSettings.PrinterResolution.X; 
     par.eDy = -e.PageSettings.Margins.Top/100 * e.PageSettings.PrinterResolution.Y; 
     ModifyWorldTransform(fmtRange.hdc, ref par, MWT_LEFTMULTIPLY); 

     IntPtr res = IntPtr.Zero; 

     IntPtr wparam = IntPtr.Zero; 
     wparam = new IntPtr(1); 

     //Get the pointer to the FORMATRANGE structure in memory 
     IntPtr lparam = IntPtr.Zero; 
     lparam = Marshal.AllocCoTaskMem(Marshal.SizeOf(fmtRange)); 
     Marshal.StructureToPtr(fmtRange, lparam, false); 

     //Send the rendered data for printing 
     res = SendMessage(Handle, EM_FORMATRANGE, wparam, lparam); 

     //Free the block of memory allocated 
     Marshal.FreeCoTaskMem(lparam); 

     //Release the device context handle obtained by a previous call 
     e.Graphics.ReleaseHdc(hdc); 

     //Return last + 1 character printer 
     return res.ToInt32(); 
    } 
+1

क्या आपको कभी इसके लिए समाधान मिला? मैं वही काम करना चाहता हूं। –

+0

दुर्भाग्य से नहीं। इस काम के लिए अब मेरे लिए कम प्राथमिकता है। –

+0

मुझे भी इसका समाधान चाहिए। – Jeff

उत्तर

1

मैं इस तरह एक समस्या थी गया है, और एक .XPS फ़ाइल बनाने और फिर प्रिंटर है कि भेज दिया।

आपके प्रश्न से, ऐसा लगता है कि आपके पास पहले से ही xps फ़ाइल में "प्रिंटिंग" की प्रक्रिया है, जो अच्छा है क्योंकि मुझे एक्सपीएस फ़ाइल में समृद्ध टेक्स्ट बॉक्स को प्रिंट करने की प्रक्रिया के बारे में कुछ भी नहीं पता है। मेरे दृश्यों में मुझे एमएस कार्यालय का उपयोग किए बिना एक डॉक्यूमेंट प्रिंट करने की ज़रूरत थी, इसलिए मैंने एक्सपीएस फ़ाइल बनाने, इसे कोड में संपादित करने और फिर प्रिंटर को भेजने के लिए समाप्त कर दिया।

LocalPrintServer localPrintServer = new LocalPrintServer(); 
var queue = localPrintServer.GetPrintQueue("NameOfPrinter"); 
PrintSystemJobInfo xpsPrintJob = queue.AddJob("name of print job", "my/xps/path.xps",false); 

इसके अलावा, आप System.Printing और "ReachFramework" के लिए संदर्भ जोड़ने की जरूरत है काम करने के लिए याद रखें कि यह कोड के लिए:

इस कोड मैं प्रिंटर के लिए सीधे XPS फ़ाइल भेजने के लिए इस्तेमाल करते हैं। मुझे यह जानने के लिए लंबे समय तक लगा कि मैं प्रिंटबॉज तक क्यों नहीं पहुंच पा रहा हूं।

अधिकांश प्रिंटर को मेरे अनुभव में इसका समर्थन करना चाहिए। आम लोग और यह हमारे भंडारण विभाग में अजीब "बारकोड-प्रिंटर" पर भी काम करता है।

संबंधित मुद्दे