收录查询

一段写的很严格的程序[来源于FengYuan的BLOG]

文章来源于:http://blogs.msdn.com/fyuan/archive/2005/09/16/469076.aspx

Printing to Microsoft XPS Document Writer without showing File Save Dialog Box

Somehow commenting was not working on my blog, so a reader send me an email on how to print to XPS Document Writer in a server environment without popping up file save dialog box.

Printing to file is supported by GDI through the DOCINFO structure passed to StartDoc call. Here is a sample code:

void UILessXPSGeneration(const TCHAR * fileName)

{

    HDC hDC = CreateDC(NULL, L"Microsoft XPS Document Writer", NULL, NULL);

 

    DOCINFO docinfo;

 

    memset(&docinfo, 0, sizeof(docinfo));

 

    docinfo.cbSize = sizeof(docinfo);

    docinfo.lpszOutput = fileName;

 

    int result;

   

    result = StartDoc(hDC, & docinfo);

    result = StartPage(hDC);

 

    const TCHAR * message = L"Hello XPS";

 

    result = TextOut(hDC, 100, 100, message, (int) _tcslen(message));

 

    result = EndPage(hDC);

    result = EndDoc(hDC);

}

 

调用方式:UILessXPSGeneration(L"c:\\temp\\file1.zip");

显示结果:Here is the XPS FixedPage generated:

<FixedPage Width="816" Height="1056" xmlns="http://schemas.microsoft.com/xps/2005/06" xml:lang="en-US">

      <Path Data="F1 M 16,16 L 80.8,16 80.8,32 16,32 z" Fill="#ffffffff" />

      <Glyphs Fill="#ff000000" FontUri="/font_0.TTF" FontRenderingEmSize="14.3217"

            StyleSimulations="None" OriginX="16" OriginY="28.8"

            Indices="43,71;72,55;79;79;82,55;3;59;51,66;54"

            UnicodeString="Hello XPS" />

</FixedPage>

posted @ 2006-06-12 21:56  ->  阅读(429)  评论(0)    收藏  举报