WinUI3 : How to print the current UI to PDF without showing Print UI

Harshithraj1871 1,421 Reputation points
2024-01-29T12:10:11.1566667+00:00

Hi,

I'm working on WinUI3 desktop app in c++. I want to print the current UI (content of an window) to PDF without should any print UI.

I was able to print without showing the UI with Win32 API's (but I had to draw the whole UI myself),

HDC pdfDC = CreateDC(L"WINSPOOL", L"Microsoft Print to PDF", NULL, NULL);
 
if (StartDoc(pdfDC, &di) > 0) {
 
            StartPage(pdfDC);
 
            // Perform printing operations here
}


But I want print the current UI to PDF without showing Print UI with WinUI3/CppWinrt interfaces. Is it possible to do so? I read about PrintDocument class but I did not find any good examples. I found one example in C# for UWP app but there is was not able to print to PDF without showing the UI. Can you help me with how to print the current UI(Content of Window) to PDF without showing the UI? Thank you.

Windows App SDK
Windows App SDK
A set of Microsoft open-source libraries, frameworks, components, and tools to be used in apps to access Windows platform functionality on many versions of Windows. Previously known as Project Reunion.
694 questions
0 comments No comments
{count} votes

Accepted answer
  1. Castorix31 80,906 Reputation points
    2024-01-29T16:14:42.29+00:00

    I was able to print without showing the UI with Win32 API's (but I had to draw the whole UI myself),

    You can use PrintWindow I tested on Windows 10, with PW_RENDERFULLCONTENT flag

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful