Share via

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

Harshithraj1871 1,756 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 development | Windows App SDK
0 comments No comments

Answer accepted by question author

  1. Castorix31 91,871 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

    Was this answer helpful?

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.