XPS 및 TIFF로 이메일 메시지 인쇄

다음은 Aspose.Email.Printing 네임스페이스는 다양한 형식(XPS 또는 TIFF)으로 메일 메시지를 인쇄하고 페이지 레이아웃을 구성하기 위한 풍부한 기능을 제공합니다. 이 문서에서는 이를 설명합니다. Aspose.Email을 사용하여 이메일 메시지를 인쇄하는 여러 옵션이 있습니다:

  1. 메시지 본문만 인쇄.
  2. 메시지 본문 및 헤더 인쇄.
  3. HTML 본문 인쇄.
  4. 페이지 레이아웃 설정.
  5. 프린터에 맞게 TIFF 자동 맞춤.
  6. 출력 TIFF의 대상 DPI 조정.

이러한 작업의 중심 클래스는 MailPrinter. 해당 Print 메서드는 ~를 받아들입니다 MailMessage, 출력 파일 이름 및 PrintFormat 값 (XPS 또는 Tiff).

메시지 본문 인쇄

다음 코드 스니펫은 메시지를 생성하고 헤더 없이 먼저 XPS 파일로, 다음에 TIFF 파일로 인쇄합니다. FormattingFlags 속성 MessageFormattingFlags.None 를 변경하여 본문만 표시합니다.

// Declare message as a MailMessage instance
MailMessage message = new MailMessage();
message.From = "user1@domain.com";
message.To = "user2@domain.com";
message.Subject = "My First Mail";
message.Date = DateTime.Now;
message.Body = "Text is the Mail Message";

// Instantiate an instance of MailPrinter and set the FormattingFlags to None to display only the message body
var printer = new Aspose.Email.Printing.MailPrinter();
printer.FormattingFlags = Aspose.Email.Printing.MessageFormattingFlags.None;

// Print the email to an XPS and TIFF file
printer.Print(message, dataDir + "PrintXPS_out.xps", Aspose.Email.Printing.PrintFormat.XPS);
printer.Print(message, dataDir + "PrintTIFF_out.tiff", Aspose.Email.Printing.PrintFormat.Tiff);

메시지 헤더 및 본문 인쇄

메시지 헤더와 본문을 함께 표시하고 인쇄하려면 FormattingFlags to MessageFormattingFlags.MailInfo.

printer.FormattingFlags = Aspose.Email.Printing.MessageFormattingFlags.MailInfo;

HTML 본문이 있는 메시지 인쇄

HTML 본문이 있는 메시지도 인쇄할 수 있습니다. HTML 콘텐츠를 사용하여 설정합니다. HtmlBody 인쇄 전 속성

// Body of the email message
message.IsBodyHtml = true;
message.HtmlBody = "<html><body><h1>Hello this is html body in Heading 1 format </h1></body></html>";

인쇄용 페이지 레이아웃 설정

MailPrinter 다음 페이지 레이아웃 속성을 설정하기 위한 컨트롤을 제공합니다:

|속성|설명|기본값| | :- | :- | :- | |FormattingFlags|메시지 상세 정보를 표시하거나 숨깁니다.|None [1]| |MarginTop|위쪽 여백을 가져오거나 설정합니다.|0.5| |MarginLeft|왼쪽 여백을 가져오거나 설정합니다.|0.5| |MarginBottom|아래쪽 여백을 가져오거나 설정합니다.|0.5| |MarginRight|오른쪽 여백을 가져오거나 설정합니다.|0.5| |PageUnit|측정 단위를 가져오거나 설정합니다.|Inch [2]| |PageHeight|페이지 높이를 가져오거나 설정합니다.|11.69| |PageWidth|페이지 너비를 가져오거나 설정합니다.|8.27|

  • [1] 두 개의 플래그가 있습니다: MailInfoNone.
  • [2] 페이지 단위는 다음 중 하나일 수 있습니다. Inch, Pixel, Point, Cm, 또는 Millimeter.

아래 코드 조각은 이러한 속성이 어떻게 사용되는지 예시하기 위해 임의의 설정을 사용합니다. 페이지 높이 20cm, 너비 8cm, 여백 2cm로 설정합니다.

// Instantiate an instance of MailPrinter
var printer = new Aspose.Email.Printing.MailPrinter();

// Just for testing, get the default property values
double width = printer.PageWidth;
double height = printer.PageHeight;

// Set page layout for printing
printer.PageUnit = Aspose.Email.Printing.PrinterUnit.Cm;
printer.MarginTop = 2;
printer.MarginBottom = 2;
printer.MarginLeft = 2;
printer.MarginRight = 2;
printer.PageWidth = 8;
printer.PageHeight = 20;

TIFF 자동 맞춤

Aspose.Email.Printing 제공합니다 MessageFormattingFlags.AutoFitWidth 자동으로 TIFF를 프린터에 맞추는 플래그입니다. 다음 코드 조각은 자동 맞춤 사용 방법을 보여줍니다.

string dataDir = RunExamples.GetDataDir_KnowledgeBase();

// Instantiate an instance of MailPrinter
Printing.MailPrinter printer = new Printing.MailPrinter();
printer.FormattingFlags = Printing.MessageFormattingFlags.AutoFitWidth;
MailMessage msg = MailMessage.Load(dataDir + "message3.msg", new MsgLoadOptions());
printer.Print(msg, dataDir + "AutoFit_out.tiff", Printing.PrintFormat.Tiff);

출력 TIFF의 목표 DPI 조정

다음 사용 DpiXDpiY 출력 TIFF의 해상도를 제어하는 속성.

// The path to the File directory and instantiate an instance of MailPrinter
string dataDir = RunExamples.GetDataDir_KnowledgeBase();
Printing.MailPrinter printer = new Printing.MailPrinter();
printer.DpiX = 300;
printer.DpiY = 300;
MailMessage msg = MailMessage.Load(dataDir + "message3.msg", new MsgLoadOptions());
printer.Print(msg, dataDir + "AdjustTargetDPI_out.tiff", Printing.PrintFormat.Tiff);