locked
Microsoft API that would let me automatically generate/print my PDFs RRS feed

  • Question

  • I want to know if there is any sort of Microsoft API that would let me automatically generate/print my PDFs?

    I would like for my C++ code to call an API that would let me automatically generate/print my PDFs to a specific file and location (which I will pass as a parameter to the API method). How can I specify the output file name and location without user interaction?

    Would it be possible to do this using Microsoft sdk?

    Thank You.


    • Edited by MichelCunha Tuesday, February 9, 2016 8:27 PM add more info
    Tuesday, February 9, 2016 8:23 PM

Answers

  • Hi Chris,

    Thank you for your help and for your explanations.
    So if i understand you correctly, I should be able to print to the PDF printer Windows 10 with my Visual Studio 2010 C++ as you has explained earlier?

    MCunha


    Yes. You are asking the same question over again, and the answer hasn't changed.
    • Proposed as answer by Hart Wang Tuesday, February 23, 2016 7:31 AM
    • Marked as answer by Hart Wang Wednesday, February 24, 2016 1:27 AM
    Thursday, February 11, 2016 11:29 PM

All replies

  • I don't know of a Microsoft API that will provide that.  There are a few 3rd party ones.  (I recently used iTextSharp for a C# application -- presumably that one would work if you were willing to go C++/CLI).
    Tuesday, February 9, 2016 9:19 PM
  • Another approach is to use automation to drive Microsoft Word to print the PDF's.
    Tuesday, February 9, 2016 9:28 PM
  • For Windows 10+ where there is a PDF printer available, you can certainly generate PDFs. You can use it as the printer, set the Output member in the job information structure to a filename (or leave NULL to have it prompt the user), and render your content to the printer for GDI; for XPS, you can set the IStream used for output to a stream whose backing is the file you want to output.  The specifics of how you'd want to open the printer vary depending on whether you want to do Xps or GDI printing with native APIs or WinRT/Universal apis either in a WinRT/Universal app or through the ABI.  The latter are easier to use with XAML based content.

    For Windows 8.1 or greater, you can render PDFs to images and therefore to printers using the classes in the Windows.Data.Pdf namespace either directly within an app or through the ABI.


    WinSDK Support Team Blog: http://blogs.msdn.com/b/winsdk/

    Tuesday, February 9, 2016 9:32 PM
  • Hi Chris,

    To do GDI printing with native API's (or WinRT/Universal) which version of Microsoft Visual Studio C++ (and Win SDK) I will need?

    Currently my code is in Microsoft Visual Studio C++ 2010 (unmanaged code), however I have no objection to migrate to Visual Studio 2015

    Do you have sample code examples I could look and learn from it (set the Output member in the job information structure to a filename (or leave NULL to have it prompt the user), and render your content to the printer for GDI) ?

    Thank You


    Thursday, February 11, 2016 4:12 PM
  • Hi Chris,

    To do GDI printing with native API's (or WinRT/Universal) which version of Microsoft Visual Studio C++ (and Win SDK) I will need?

    All versions of Visual Studio C++ can do GDI printing.



    Do you have sample code examples I could look and learn from it (set the Output member in the job information structure to a filename (or leave NULL to have it prompt the user), and render your content to the printer for GDI) ?


    Sounds like you have never done GDI printing before.

    Here is a good introduction.

    Thursday, February 11, 2016 4:25 PM
  • Hi Chris,

    Thank you for your help and for your explanations.
    So if i understand you correctly, I should be able to print to the PDF printer Windows 10 with my Visual Studio 2010 C++ as you has explained earlier?

    MCunha

    Thursday, February 11, 2016 10:45 PM
  • Hi Chris,

    Thank you for your help and for your explanations.
    So if i understand you correctly, I should be able to print to the PDF printer Windows 10 with my Visual Studio 2010 C++ as you has explained earlier?

    MCunha


    Yes. You are asking the same question over again, and the answer hasn't changed.
    • Proposed as answer by Hart Wang Tuesday, February 23, 2016 7:31 AM
    • Marked as answer by Hart Wang Wednesday, February 24, 2016 1:27 AM
    Thursday, February 11, 2016 11:29 PM
  • Hi Chris,

    I not able to succeed using your suggestion.
    Maybe I didn't phrase my question well :(
    Let me rephrase my question :
    I would like for my C++ code to call an API that would let me automatically generate/print PDFs from my HTML documents to a specific file and location (which I will pass as a parameter to the API method). How can I specify the output file name and location without user interaction?

    Currently I'm printring directly to the "Microsoft Print to PDF" using the following code :

    //sets the printer name of the default printer for the current user on the local computer.
    SetDefaultPrinter(_T("Microsoft Print to PDF"));
    //Print command - without prompting the user.
    m_pWndHtml->ExecWB(OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER, &parameter, NULL);

    Note that m_pWndHtml is CHtmlView object. 

    However this will prompt user for location+filename. 
    I would like to programmatically control this from C++ to not prompt for the PDF filename but save to a specific filename in some folder that I provide.
    Would it be possible to accomplish that??

    Unless it would be possible to specify the name of the file before calling m_pWndHtml->ExecWB?

    Once again thank you for your help.

    MCunha.





    • Edited by MichelCunha Monday, February 15, 2016 2:27 PM
    Friday, February 12, 2016 10:31 PM
  • Hi,

    According to your description. I think you may print directly to the "Microsoft Print to PDF" using your code.

    Now you want to automatically save specific filename that you provide. I suggest you should post new case so that some people can quickly find your problem.

    About the new problem, you can refer to the link how to set PDF filename automatically.

    Best Regards,

    Hart

    Tuesday, February 23, 2016 7:55 AM