Exemplo n.º 1
0
        static void Main(string[] args)
        {
            //Common network settings
            ServicePointManager.Expect100Continue = true;
            ServicePointManager.SecurityProtocol  = SecurityProtocolType.Tls12;

            if (!ParseArguments(args))
            {
                Console.WriteLine("ERROR. Incorrect arguments. Do not use spaces in any of the arguments");
                Console.WriteLine("Usage: MarkdownToPDF [user=<github-user> project=<github-project> | input-file=<input-file (.md)>] [author=<author>] output-file=<output-file (.pdf)>");
                Console.WriteLine("Use examples:");
                Console.WriteLine("\ta) Download and convert a GitHub wiki: GitHubWikiToPDF user=simionsoft project=SimionZoo author=SimionZoo output-file=SimionZoo.pdf");
                Console.WriteLine("\tb) Convert a local markdown file: GitHubWikiToPDF input-file=../myLocalFile.md author=SimionZoo output-file=myLocalFile.pdf");
                return;
            }

            if (!Directory.Exists(tempFolder))
            {
                Directory.CreateDirectory(tempFolder);
            }

            //Download the last version of the wiki
            Console.WriteLine("\n#### 1. Downloading the last version of the wiki");
            if (executionMode == ExecutionMode.GitHubWikiToPDF)
            {
                GitHubWikiDownloader downloader = new GitHubWikiDownloader();
                downloader.CloneWikiGitRepo(userName + "/" + projectName, tempFolder);
            }
            else
            {
                Console.WriteLine("Skipped");
            }

            //Convert it to PDF
            Console.WriteLine("\n#### 2. Converting markdown files to a single .pdf file");

            WikiToPDFConverter markDownWikiToPDFConverter = new WikiToPDFConverter();

            markDownWikiToPDFConverter.CreatePDFDocument(projectName, projectDescription, authorName, "Created with MarkdownToPDF (https://github.com/borjafdezgauna/MarkdownToPDF/)");

            markDownWikiToPDFConverter.Convert(markDownInputFolder, inputFile, tempFolder);

            if (!outputFile.EndsWith(".pdf"))
            {
                outputFile += ".pdf";
            }
            markDownWikiToPDFConverter.SavePDFDocument(outputFile);

            if (File.Exists(outputFile))
            {
                Console.WriteLine("Successfully created documentation file as PDF: " + outputFile);
            }
            else
            {
                Console.WriteLine("ERROR: Something went wrong trying to save the PDF file");
            }
        }