2012-11-09 14 views
9

शुभ दिन!प्रिंट करने के लिए RichTextBox घूर्णन पाठ

मुझे RichTextBox से शॉर्ट कार्ड प्रिंट करने की आवश्यकता है। कार्ड का आकार 10x14 सेमी है।

example image

मैं PageSettings दो तरीके निर्धारित करने की कोशिश की है:

  1. PageSettings.Width = 10

    क्योंकि ग्राहक के प्रिंटर सुविधाओं के हम केवल इस तरह से एक प्रिंटर में कार्ड डाल सकते हैं ; पेजसेटिंग। हाइट = 14.

  2. पेजसेटिंग Width = 14; PageSettings.Height = 10.

और प्रिंट करने योग्य क्षेत्र इस तरह दिखता है:

btnRotate.CheckedChanged += (s, e) => InitPaperSize(); 

private void InitPaperSize() 
    { 
     string name = btnRotate.Checked ? "ShortCard (rotate)" : "ShortCard"; 
     int width = Centimeters(btnRotate.Checked ? 14 : 10); 
     int height = Centimeters(btnRotate.Checked ? 10 : 14); 

     System.Drawing.Printing.PaperSize ps = new System.Drawing.Printing.PaperSize(name, width, height); 
     printDocument.DefaultPageSettings.PaperSize = ps; 
    } 

private int Centimeters(int centimeters) 
    { 
     return (int)((centimeters * 100)/2.54); 
    } 

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;//делим на 100 так как границы указываются в сотых долях дюйма 
     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(); 
    } 

केवल समस्या यह है कि हम है:

enter image description here

यहाँ कोड कैसे मुद्रण जारी किया गया है है कार्ड को क्षैतिज रूप से केवल प्रिंटर में रख सकता है।

+3

प्रिंटर लैंडस्केप और पोर्ट्रेट मोड, पेजसेटिंग में मुद्रण का समर्थन करते हैं। लैंडस्केप संपत्ति। खुद को आउटपुट घूर्णन करने से एक पूरेहेकफ्लोट आसान है। –

+0

मैंने भी इस तरह से प्रयास किया है। लेकिन परिदृश्य केवल प्रिंटिंग सामग्री को घुमाने की अनुमति देता है लेकिन प्रिंट करने योग्य क्षेत्र नहीं। तो प्रिंटर के अंदर कागज का स्थान बदल नहीं है। –

उत्तर

0

मुझे विशेष प्रिंटर के साथ समान समस्याएं आई हैं। ड्राइवर आपके द्वारा सेट की गई कुछ सेटिंग्स को अनदेखा कर सकते हैं।

मेरा समाधान टेक्स्ट से एक छवि बनाना था और अपने डॉक्यूमेंट को कुछ अजीब प्रिंटर ड्राइवर फिट करने की बजाय डिफ़ॉल्ट प्रिंटर सेटिंग का उपयोग करना था।

Here is how you convert your text to image

1

के रूप में किसी को पहले भी कहा, तो आप बस PageSettings.Landscape संपत्ति स्थापित करना चाहिए। आप PrintPageEventArgs.Graphics के ग्राफिक्स संदर्भ का उपयोग कर सीधे आकर्षित कर सकते हैं। फिर आप किसी घुमावदार तत्व या घुमावदार पाठ को आकर्षित कर सकते हैं। This gives a good example। फिर आपको पॉइंटर्स (इंटीपीआरटी) या डिवाइस संदर्भ (गेटएचडीसी) के साथ काम करने की आवश्यकता नहीं है।

+0

इस प्रकार मैं इसके बारे में जाऊंगा: RichTextBox की सामग्री को पकड़ो और इसे 'प्रिंट डॉक्यूमेंट' में जिस तरह से आवश्यक है, उसे "ड्रा" करें। http://msdn.microsoft.com/fr-fr/library/system.drawing.printing.printdocument(v=vs.80).aspx –

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