コード例 #1
0
ファイル: PdfCommand.cs プロジェクト: xuan2261/docfx
        public void Exec(SubCommandRunningContext context)
        {
            EnvironmentContext.SetBaseDirectory(Path.GetFullPath(string.IsNullOrEmpty(_config.BaseDirectory) ? Directory.GetCurrentDirectory() : _config.BaseDirectory));
            // TODO: remove BaseDirectory from Config, it may cause potential issue when abused
            var baseDirectory   = EnvironmentContext.BaseDirectory;
            var outputFolder    = Path.GetFullPath(Path.Combine(string.IsNullOrEmpty(_config.OutputFolder) ? baseDirectory : _config.OutputFolder, _config.Destination ?? string.Empty));
            var rawOutputFolder = string.IsNullOrEmpty(_config.RawOutputFolder) ? Path.Combine(outputFolder, "_raw") : _config.RawOutputFolder;
            var options         = new PdfOptions
            {
                BasePath      = _config.BasePath,
                CssFilePath   = _config.CssFilePath,
                DestDirectory = outputFolder,
                Host          = _config.Host,
                Locale        = _config.Locale,
                NeedGeneratePdfExternalLink = _config.GeneratesExternalLink,
                GenerateAppendices          = _config.GeneratesAppendices,
                PdfConvertParallelism       = _config.MaxParallelism == null || _config.MaxParallelism <= 0 ? Environment.ProcessorCount : _config.MaxParallelism.Value,
                PdfDocsetName            = _config.Name ?? Path.GetFileName(EnvironmentContext.BaseDirectory),
                SourceDirectory          = Path.Combine(rawOutputFolder, _config.Destination ?? string.Empty),
                ExcludeTocs              = _config.ExcludedTocs?.ToArray(),
                KeepRawFiles             = _config.KeepRawFiles,
                ExcludeDefaultToc        = _config.ExcludeDefaultToc,
                LoadErrorHandling        = _config.LoadErrorHandling,
                FilePath                 = _wkhtmltopdfFilePath,
                AdditionalPdfCommandArgs = _config.Wkhtmltopdf?.AdditionalArguments,
                TocTitle                 = _config.TocTitle,
                OutlineOption            = _config.OutlineOption,
                CoverPageTitle           = _config.CoverPageTitle,
                NoInputStreamArgs        = _config.NoInputStreamArgs,
            };

            // 1. call BuildCommand to generate html files first
            // Output build command exec result to temp folder
            _innerBuildCommand.Config.OutputFolder = rawOutputFolder;

            _innerBuildCommand.Exec(context);

            // 2. call html2pdf converter
            var converter = new ConvertWrapper(options);

            try
            {
                using (new LoggerPhaseScope("PDF", LogLevel.Info))
                {
                    Logger.LogInfo("Start generating PDF files...");
                    converter.Convert();
                }
            }
            catch (IOException ioe)
            {
                throw new DocfxException(ioe.Message, ioe);
            }

            // 3. Should we delete generated files according to manifest
        }
コード例 #2
0
        public void Exec(SubCommandRunningContext context)
        {
            EnvironmentContext.SetBaseDirectory(Path.GetFullPath(string.IsNullOrEmpty(_config.BaseDirectory) ? Directory.GetCurrentDirectory() : _config.BaseDirectory));
            // TODO: remove BaseDirectory from Config, it may cause potential issue when abused
            var baseDirectory            = EnvironmentContext.BaseDirectory;
            var intermediateOutputFolder = Path.Combine(baseDirectory, "obj");
            var outputFolder             = Path.GetFullPath(Path.Combine(string.IsNullOrEmpty(_config.OutputFolder) ? baseDirectory : _config.OutputFolder, _config.Destination ?? string.Empty));

            var options = new PdfOptions
            {
                BasePath      = _config.BasePath,
                CssFilePath   = _config.CssFilePath,
                DestDirectory = outputFolder,
                Host          = _config.Host,
                Locale        = _config.Locale,
                NeedGeneratePdfExternalLink = _config.GeneratesExternalLink,
                GenerateAppendices          = _config.GeneratesAppendices,
                PdfConvertParallelism       = _config.MaxParallelism == null || _config.MaxParallelism <= 0 ? Environment.ProcessorCount : _config.MaxParallelism.Value,
                PdfDocsetName   = _config.Name ?? Path.GetFileName(EnvironmentContext.BaseDirectory),
                SourceDirectory = outputFolder,
                ExcludeTocs     = _config.ExcludedTocs?.ToArray(),
            };

            // 1. call BuildCommand to generate html files first
            _innerBuildCommand.Exec(context);

            // 2. call html2pdf converter
            var converter = new ConvertWrapper(options);

            try
            {
                using (new LoggerPhaseScope("PDF", LogLevel.Info))
                {
                    Logger.LogInfo("Start generating PDF files...");
                    converter.Convert();
                }
            }
            catch (IOException ioe)
            {
                throw new DocfxException(ioe.Message, ioe);
            }

            // 3. Should we delete generated files according to manifest
        }