Visual Studio:将 C# 代码导出为 PDF 文件并保留格式 + 颜色?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17370405/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Visual Studio: Export C# Code into a PDF file and keep the formatting + colors?
提问by Avinor
I was wondering if there is any export function inside Visual Studio Ultimate (2010)to get a chosen tab(by default a single class) of C# codeexported into a PDFfile, so you can share that PDF file and show someone the code, with the formatting and colors of Visual Studio? I'm sending the PDF with sample code for an application, that's how I came to this question.
我想知道里面是否有任何导出功能Visual Studio Ultimate (2010)可以将选择的tab(默认为单个class)C# code导出到PDF文件中,以便您可以共享该 PDF 文件并向某人展示代码,以及 Visual Studio 的格式和颜色?我正在发送带有应用程序示例代码的 PDF,这就是我遇到这个问题的方式。
I know that I could copy the code into Word in a textbox, that works fine and keeps colors + formatting. I am just interested if there is an option in Visual Studio too? It's not important, just want to know. ;-)
我知道我可以将代码复制到文本框中的 Word 中,这可以正常工作并保持颜色 + 格式。我只是对 Visual Studio 中是否也有选项感兴趣?这不重要,只是想知道。;-)
采纳答案by Captain Skyhawk
回答by Maxime
First, you need a PDF printertool like:
首先,您需要一个PDF 打印机工具,例如:
- Foxit Reader(PDF Reader and printer)
- CutePDF(PDF printer only)
I'm using Visual Studio 2013 but colors were not printing.
我正在使用 Visual Studio 2013,但没有打印颜色。
If you are using Visual Studio 2010-2012, you might want to check the following extension from Microsoft: Color Printing
如果您使用的是Visual Studio 2010-2012,您可能需要检查以下来自 Microsoft 的扩展:Color Printing
If you are using Visual Studio 2013, you can check this extension from Microsoft which includes color printing: Productivity Power Tools 2013
如果您使用的是Visual Studio 2013,您可以从 Microsoft 查看此扩展,其中包括彩色打印:Productivity Power Tools 2013
If you are using Visual Studio 2015, you can check this extension from Microsoft which includes color printing: Productivity Power Tools 2015
如果您使用的是Visual Studio 2015,则可以从 Microsoft 查看此扩展,其中包括彩色打印:Productivity Power Tools 2015
回答by Joginder S Nahil
You can use VscodePrint extension. Google 'VScodePrint' and try it. You can print or exports to PDF any part of a Solution.
您可以使用 VscodePrint 扩展。谷歌“VScodePrint”并尝试一下。您可以打印或导出解决方案的任何部分。
回答by MrVimes
I wanted to do this myself so google brought me here. Then I had a mini brainwave and remembered "Microsoft Print to PDF" which is built in as an option in the print menu. I tried it and it worked!
我想自己做这件事,所以谷歌把我带到了这里。然后我有了一个小小的脑波,想起了“Microsoft Print to PDF”,它是作为打印菜单中的一个选项内置的。我试过了,它奏效了!
So just go File->Print, then choose Microsoft Print to PDFas the printer, then choose where to save your printout.
所以只需转到文件->打印,然后选择Microsoft Print to PDF作为打印机,然后选择保存打印输出的位置。
(P.s. my code is awful. This file is from an old app I wrote lazily and intend to overhaul)
(Ps我的代码很糟糕。这个文件来自我懒惰写的一个旧应用程序,打算大修)

