2009-05-01 6 views
1

C#을 사용하여 웹 페이지에서 표준 크기의 봉투를 인쇄하려고합니다. 아무도 이런 식으로하는 법을 알고 있습니까? 주소의 시스템에서 데이터를로드하고 전달합니다. 그렇게하기위한 기본 단계가 필요합니다.웹 사이트에서 봉투를 인쇄 하시겠습니까?

+1

서버 또는 클라이언트에 있습니까? –

답변

2

PDF로 끝났습니다. 우리는 .NET 용 무료 PDF 작성 도구 인 PDFSharp을 사용합니다. 여기서는 함수를 사용하여 즉석에서 PDF를 작성한 다음이 페이지를 새 창으로로드합니다. 비슷한 것을하고 싶은 사람을 위해 만든 방법입니다.

protected void DisplayPDFEnvelope() 
    { 
     try 
     { 
      PdfDocument document = new PdfDocument(); 
      PdfPage pdfpage = new PdfPage(); 

      XUnit pdfWidth = new XUnit(4.125, XGraphicsUnit.Inch); 
      XUnit pdfHeight = new XUnit(9.5, XGraphicsUnit.Inch); 
      pdfpage.Height = pdfHeight; 
      pdfpage.Width = pdfWidth; 

      pdfpage.Orientation = PageOrientation.Landscape; 

      XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always); 

      document.AddPage(pdfpage); 

      // Create a font 
      XFont font = new XFont("ARIAL", 1, XFontStyle.Regular, options); 

      // Get an XGraphics object for drawing beneath the existing content 
      XGraphics gfx = XGraphics.FromPdfPage(pdfpage, XGraphicsPdfPageOptions.Append); 

      // This method just returns a formatted address from the DB using \n to 
      // do line breaks, i.e. 'Test Person\nAddress Line1\City, State Zip' 
      string address = GetAddress(); 

      // Get the size (in point) of the text 
      XSize size = gfx.MeasureString(address, font); 

      // Create a graphical path 
      XGraphicsPath path = new XGraphicsPath(); 

      path.AddString(address, font.FontFamily, XFontStyle.Regular, 10, 
       new XPoint(345, 160), XStringFormats.Default); 

      // Create a dimmed pen and brush 
      XPen pen = new XPen(XColor.FromGrayScale(0), 0); // XColor.FromArgb(50, 75, 0, 130), 3); 
      XBrush brush = new XSolidBrush(); // XColor.FromArgb(50, 106, 90, 205)); 

      // Stroke the outline of the path 
      gfx.DrawPath(pen, brush, path); 

      MemoryStream stream = new MemoryStream(); 
      document.Save(stream, false); 

      Page.Response.Clear(); 
      Page.Response.ContentType = "application/pdf"; 
      Page.Response.AppendHeader("Content-Length", stream.Length.ToString()); 
      Page.Response.AppendHeader("Content-Type", "application/pdf"); 
      Page.Response.AppendHeader("Content-Disposition", "inline;filename=envelope.pdf"); 
      Page.Response.BinaryWrite(stream.ToArray()); 
      Page.Response.Flush(); 
      stream.Close(); 
      HttpContext.Current.ApplicationInstance.CompleteRequest(); 
     } 
     catch (Exception ex) 
     { 
      throw ex; 
     } 
    } 
1

은 이론적으로는 CSS를 http://www.w3.org/TR/css-print/를 사용하여 작업을 수행 할 수 있습니다 도움이 될 수 있습니다. 지원해야하는 브라우저의 수에 따라 약간 다르게 작동하므로 많은 어려움을 겪을 수 있습니다.

당신은 사용자로 페이지 크기와 방향에 약간의 문제가있을 가능성이 많은 differant 프린터 나 않을 수 있습니다. 플래시, pdf 또는 실버 라이트 3에서 인쇄하는 것이 쉬운 경로 일 수 있습니다.

+0

+1 to PDF, CSS *로 할 수도 있지만 - PDF가 가장 먼저 선택됩니다. –

+0

이것은 내부 용이므로 IE에서만 사용됩니다 (다른 브라우저 지원에 대해 걱정할 필요가 없습니다). PDF가 좋은 옵션 일 수 있습니다. – Noah

0

this site에서 봉투를 인쇄 할 수 있습니다.

바코드와 모든 것을 추가합니다. 웹에서 인쇄하십시오.

관련 문제