如何在Windows 10上打印为PDF

The Windows 10 logo.

On Windows 10, you can print a document to PDF from any application, thanks to the built-in Print to PDF feature. You no longer have to use the old XPS Printer or install a third-party application.

在Windows 10上,借助内置的“打印为PDF”功能,您可以从任何应用程序将文档打印为PDF。 您不再需要使用旧的XPS打印机或安装第三方应用程序。

To get started, open the document you want to print to a PDF file. Find and open the Print dialog box in the application. Where this is located will vary by program, but you can usually go to File > Print, or just click a printer icon.

首先,将您要打印的文档打开为PDF文件。 在应用程序中查找并打开“打印”对话框。 该文件所在的位置会因程序而异,但是通常可以转到“文件”>“打印”,或者单击打印机图标。

Click "File," and then select "Print" in the program you're using to open the print dialog box.

When the “Print” window opens, click “Microsoft Print to PDF” in the “Select Printer” section. Then, click “Print” at the bottom of the window.

当“打印”窗口打开时,在“选择打印机”部分中单击“ Microsoft打印为PDF”。 然后,单击窗口底部的“打印”。

Click "Microsoft Print to PDF," and then click "Print."

When the “Save Print Output As” window appears, type a filename, and then select the location in which you want to save the file (such as Documents or Desktop). When you’re done, click “Save.”

当出现“将打印输出另存为”窗口时,键入文件名,然后选择要保存文件的位置(例如“文档”或“桌面”)。 完成后,点击“保存”。

The "Save Print Output As" window.

The printed document will be saved as a PDF file in the location you chose. If you double-click the file you just created, you should see it the way it would appear if you printed a hard copy.

打印的文档将保存为PDF文件,位于您选择的位置。 如果双击刚刚创建的文件,则应该以打印硬拷贝时出现的样子看到它。

A PDF document printed to PDF.

From there, you can copy your file, back it up, or save it for later reference.

从那里,您可以复制,备份或保存文件以供以后参考。

翻译自: https://www.howtogeek.com/666835/how-to-print-to-pdf-on-windows-10/

要在Windows下使用C++进行静默打印PDF文件,可以使用Adobe Acrobat Reader的COM组件进行操作。以下是一些示例代码: ```c++ #include <windows.h> #include <iostream> #include <atlbase.h> #include <atlcom.h> #include <atlstr.h> int main(int argc, char* argv[]) { // 初始化COM库 CoInitialize(NULL); // 创建Acrobat Reader应用程序对象 CComPtr<IDispatch> pAcrobat; HRESULT hr = pAcrobat.CoCreateInstance(CLSID_AcroExch_App, NULL, CLSCTX_LOCAL_SERVER); if (FAILED(hr)) { std::cerr << "Failed to create Acrobat Reader application object" << std::endl; return 1; } // 获取Acrobat Reader AVDoc对象 CComPtr<IDispatch> pAVDoc; hr = pAcrobat.InvokeMethod(L"GetActiveDoc", &pAVDoc); if (FAILED(hr) || !pAVDoc) { std::cerr << "Failed to get AVDoc object" << std::endl; return 1; } // 打开PDF文件 CString fileName = _T("C:\\test.pdf"); CComVariant fileVariant = fileName; CComVariant bstrEmpty(L""); CComVariant bstrEmpty2(L""); CComPtr<IDispatch> pAVDoc2; hr = pAVDoc.InvokeMethod(L"Open", &fileVariant, &bstrEmpty, &bstrEmpty2, &pAVDoc2); if (FAILED(hr)) { std::cerr << "Failed to open PDF file" << std::endl; return 1; } // 获取AVDoc的PDDoc对象 CComPtr<IDispatch> pPDDoc; hr = pAVDoc2.InvokeMethod(L"GetPDDoc", &pPDDoc); if (FAILED(hr) || !pPDDoc) { std::cerr << "Failed to get PDDoc object" << std::endl; return 1; } // 获取PDDoc的PrintParams对象 CComPtr<IDispatch> pPrintParams; hr = pPDDoc.InvokeMethod(L"GetPrintParams", &pPrintParams); if (FAILED(hr) || !pPrintParams) { std::cerr << "Failed to get PrintParams object" << std::endl; return 1; } // 设置打印参数 CComVariant bstrPrinterName(L"Microsoft Print to PDF"); CComVariant bstrPaperSize(L"A4"); CComVariant bstrPaperSource(L"Auto"); CComVariant bstrDuplex(L"Simplex"); CComVariant bstrOutputBin(L"Auto"); CComVariant bstrPageRange(L"All"); CComVariant bstrPrintPages(L"OddPagesOnly"); CComVariant bstrPrintAsImage(VARIANT_TRUE); hr = pPrintParams.InvokeMethod(L"SetPrinterName", &bstrPrinterName); hr = pPrintParams.InvokeMethod(L"SetPaperSize", &bstrPaperSize); hr = pPrintParams.InvokeMethod(L"SetPaperSource", &bstrPaperSource); hr = pPrintParams.InvokeMethod(L"SetDuplex", &bstrDuplex); hr = pPrintParams.InvokeMethod(L"SetOutputBin", &bstrOutputBin); hr = pPrintParams.InvokeMethod(L"SetPageRange", &bstrPageRange); hr = pPrintParams.InvokeMethod(L"SetPrintPages", &bstrPrintPages); hr = pPrintParams.InvokeMethod(L"SetPrintAsImage", &bstrPrintAsImage); // 执行打印操作 CComVariant bstrFilePath(L"C:\\test.pdf"); CComVariant bstrEmpty3(L""); CComVariant bstrEmpty4(L""); CComVariant bstrEmpty5(L""); CComVariant bstrEmpty6(L""); CComVariant bstrEmpty7(L""); CComVariant bstrEmpty8(L""); CComVariant bstrEmpty9(L""); CComVariant bstrEmpty10(L""); CComVariant bstrEmpty11(L""); CComVariant bstrEmpty12(L""); CComVariant bstrEmpty13(L""); CComVariant bstrEmpty14(L""); hr = pAVDoc2.InvokeMethod(L"PrintPagesSilent", &bstrEmpty3, &bstrEmpty4, &bstrEmpty5, &bstrEmpty6, &bstrEmpty7, &bstrEmpty8, &bstrEmpty9, &bstrEmpty10, &bstrEmpty11, &bstrEmpty12, &bstrEmpty13, &bstrEmpty14); // 关闭PDF文件 hr = pAVDoc2.InvokeMethod(L"Close", &bstrEmpty); // 释放COM资源 pPrintParams.Release(); pPDDoc.Release(); pAVDoc2.Release(); pAVDoc.Release(); pAcrobat.Release(); CoUninitialize(); return 0; } ``` 在上面的示例代码中,我们使用了Acrobat Reader的COM组件来打印PDF文件。首先,我们创建Acrobat Reader应用程序对象,然后获取AVDoc对象并打开PDF文件。接下来,我们获取PDDoc的PrintParams对象,设置打印参数,最后执行打印操作。在打印操作完成后,我们关闭PDF文件并释放COM资源。 需要注意的是,这个代码示例假设你已经安装了Adobe Acrobat Reader软件,并且使用了默认的Microsoft Print to PDF打印机进行打印。如果你使用了其他打印机或者PDF阅读器,你需要相应地修改代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值