将解决方案转换为PDF或DOC文件。

4
这可能看起来是个奇怪的问题,但我需要将我的代码转换成PDF格式,以便我可以提交。很遗憾,学校系统要求将代码作为PDF格式的CD提交。我可以打开解决方案中的每个类并复制粘贴它们,但作为程序员,我很懒,想知道Visual Studio是否有此功能?或者是否有其他方法?
编辑:一个第三方程序,可以遍历文件夹中的所有文件,打开文件并复制其内容到PDF文件中,也可以 - 它不必在Visual Studio内部实现。

3
如果你的学校要求这样做,那么肯定已经有人解决了将所有解决方案代码文件转换为PDF的问题了吧? - Mitch Wheat
http://superuser.com/questions/389318/looking-for-software-that-will-batch-convert-a-folder-tree-containing-chm-files - Mitch Wheat
Mitch,这正是我所想的,也是我来到这里的原因。因为我相信同样的事情,一定有适合此需求的工具存在。学校也没有为我们提供这方面的工具。 - Peter Rasmussen
通常学校不喜欢收到大量的代码来检查。如果你手工转成PDF的任务太多,你确定你写了太多的代码了吗?(我过去经常这样做) - Rup
我认为“太多”这种情况不存在。我们的代码大约有10,000行,这是我们的最终项目。我不认为老师们会把它全部阅读完——我们已经为他们写了一些文档,但他们也想要代码——可悲的是,这是学校的规定而不是他们的要求。我早就知道了,我应该只创建一个“Hello world”控制台应用程序的 ;) - Peter Rasmussen
1个回答

1

等待太久了,这是我想出来的:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace GetFileContents
{
    class Program
    {
        static string types = ".js,.cshtml,.cs,.less,.css";
        private static string text = "";
        static void Main(string[] args)
        {
            //This folder wraps the whole thing.
            string folderPath = @"C:\randomFolderWhereProjectIs\";

            string s = IterateIt(Directory.GetDirectories(folderPath).ToList());
            //Save to file or whatever I just used the text visualiser in Visual Studio
        }

        private static string IterateIt(List<string> l)
        {

            foreach (var path in l)
            {
                var files = Directory.GetFiles(path).Select(c => new FileInfo(c)).Where(c => types.Split(',').Contains(c.Extension));

                foreach (var fileInfo in files)
                {
                    text += fileInfo.Name + "\r\n";
                    using (StreamReader reader = fileInfo.OpenText())
                    {
                        text += reader.ReadToEnd() + "\r\n";
                    }
                }
                text = IterateIt(Directory.GetDirectories(path).ToList());
            }
            return text;
        }


    }
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接