简体   繁体   English

将 Word Docx 转换为混合 PDF

[英]Convert Word Docx to Hybrid PDF

How to know whether PDF Exported is HYBRID PDF???怎么知道PDF出口的是不是HYBRID PDF???

Please give me proper solution regarding Hybrid pdf.请给我有关混合 pdf 的正确解决方案。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using Syncfusion.DocIO;
using Syncfusion.DocIO.DLS;
using Syncfusion.DocToPDFConverter;
using Syncfusion.Pdf;
using Syncfusion.Mvc.Pdf;
using Syncfusion.OfficeChartToImageConverter;

namespace EJ2MVCSampleBrowser.Controllers.DocIO
{
    public partial class DocIOController : Controller
    {
        #region doc to PDF
        public ActionResult DOCtoPDF(string button, string renderingMode, string renderingMode1, string renderingMode2, string renderingMode3, string renderingMode4, string renderingMode5, string renderingMode6, string autoTag, string preserveFormFields, string exportBookmarks, string embeddingFont, HttpPostedFileBase file)
        {
            if (button == null)
                return View();
            //Get input Word document.
            WordDocument document = GetInputWordocument(file);
            if (document != null)
            {
                string output = file == null ? "DoctoPDF" : Path.GetFileNameWithoutExtension(file.FileName);
                //Initialize chart to image converter for converting charts in Word to PDF conversion
                document.ChartToImageConverter = new ChartToImageConverter();
                document.ChartToImageConverter.ScalingMode = Syncfusion.OfficeChart.ScalingMode.Normal;

                DocToPDFConverter converter = new DocToPDFConverter();
                //Enable Direct PDF rendering mode for faster conversion.
                if (renderingMode == "DirectPDF")
                    converter.Settings.EnableFastRendering = true;
                if (renderingMode1 == "PreserveStructureTags")
                    converter.Settings.AutoTag = true;
                if (renderingMode2 == "PreserveFormFields")
                    converter.Settings.PreserveFormFields = true;
                converter.Settings.ExportBookmarks = renderingMode3 == "PreserveWordHeadingsToPDFBookmarks"
                                                       ? Syncfusion.DocIO.ExportBookmarkType.Headings
                                                     : Syncfusion.DocIO.ExportBookmarkType.Bookmarks;
                if (renderingMode4 == "EnablesCompleteFont")
                    converter.Settings.EmbedCompleteFonts = true;
                if (renderingMode5 == "EnablesSubsetFont")
                    converter.Settings.EmbedFonts = true;
                if (renderingMode6 == "ShowRevisions")
                    document.RevisionOptions.ShowMarkup = RevisionType.Deletions | RevisionType.Formatting | RevisionType.Insertions;
                //Convert word document into PDF document
                PdfDocument pdfDoc = converter.ConvertToPDF(document);
                try
                {
                    return pdfDoc.ExportAsActionResult(output + ".pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save);
                }
                catch (Exception)
                { }
                finally
                {

                }
            }

            return View();
        }
        /// <summary>
        /// Gets the Word document from default template document or uploaded document.
        /// </summary>
        /// <param name="file">HttpPostedFileBase contains the uploaded file data.</param>
        /// <returns>Returns the Word document instance.</returns>
        private WordDocument GetInputWordocument(HttpPostedFileBase file)
        {
            if (file != null)
            {
                var extension = Path.GetExtension(file.FileName).ToLower();

                if (extension == ".doc" || extension == ".docx" || extension == ".dot" || extension == ".dotx" || extension == ".dotm" || extension == ".docm"
                   || extension == ".xml" || extension == ".rtf")
                    return new WordDocument(file.InputStream, FormatType.Automatic);
                else
                    ViewBag.Message = string.Format("Please choose Word format document to convert to PDF");
            }
            else
            {
                string filePath = ResolveApplicationDataPath("DoctoPDF.docx", "Data\\DocIO");
                return new WordDocument(filePath);
            }
            return null;
        }
        #endregion doc to PDF
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM