2012-11-13 7 views
6

RichTextBox의 내용을 인쇄하려고 시도했지만 프린터로 인쇄 할 때 너무 많은 버그가 있습니다. 그러나 XPS- 파일 (Windows의 XPS- 프린터를 통해)로 인쇄 할 때이 파일을 프린터로 인쇄하면 모두 정상입니다.XPS 파일로 인쇄 한 다음 프린터로 인쇄하십시오.

프로그래밍으로 이러한 모든 작업을 수행 할 수 있습니까?

여기 내 인쇄 방법 :

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 파일에 리치 텍스트 상자를 인쇄하는 프로세스에 대해 알지 못해서 xps 파일에 "인쇄"하는 과정이 이미있는 것 같습니다. 내 scenaria에서는 ms office를 사용하지 않고 dokument를 인쇄해야하므로 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 AND "ReachFramework"에 대한 참조를 추가해야 할 일이 코드에 대한 그 기억 :

은 내가 프린터에 직접 XPS 파일을 전송하는 데 사용하는 코드입니다. 내가 인쇄 잡을 접근 할 수 없었던 이유를 기억하는 것을 신경 쓰는 것보다 더 오래 걸렸습니다.

대부분의 프린터가이 기능을 지원해야합니다. 일반적인 것들과 우리 스토리지 부서의 이상한 "바코드 프린터"에서도 작동합니다.

관련 문제