Exemplo n.º 1
0
        public HttpResponseMessage MailMerge([FromBody] ExportData exportData)
        {
            Byte[]       data   = Convert.FromBase64String(exportData.documentData.Split(',')[1]);
            MemoryStream stream = new MemoryStream();

            stream.Write(data, 0, data.Length);
            stream.Position = 0;
            try
            {
                Syncfusion.DocIO.DLS.WordDocument document = new Syncfusion.DocIO.DLS.WordDocument(stream, Syncfusion.DocIO.FormatType.Docx);
                document.MailMerge.RemoveEmptyGroup      = true;
                document.MailMerge.RemoveEmptyParagraphs = true;
                document.MailMerge.ClearFields           = true;
                document.MailMerge.Execute(CustomerDataModel.GetAllRecords());
                document.Save(stream, Syncfusion.DocIO.FormatType.Docx);
            }
            catch (Exception)
            { }
            string          sfdtText     = "";
            EJ2WordDocument worddocument = EJ2WordDocument.Load(stream, Syncfusion.EJ2.DocumentEditor.FormatType.Docx);

            sfdtText = Newtonsoft.Json.JsonConvert.SerializeObject(worddocument);
            worddocument.Dispose();
            return(new HttpResponseMessage()
            {
                Content = new StringContent(sfdtText)
            });
        }
Exemplo n.º 2
0
        public void SaveSFDT(int id)
        {
            DTO_CUS_DOC_File item = BS_CUS_DOC_File.get_CUS_DOC_File(db, PartnerID, id, true);

            if (item == null)
            {
                return;
            }

            string path = System.Web.HttpContext.Current.Server.MapPath("~");

            item.ModifiedDate = DateTime.Now;
            string version = ".V" + item.ModifiedDate.ToString("yyMMdd-HHmmss");

            int    index  = item.Path.LastIndexOf(".V") == -1 ? item.Path.LastIndexOf(".") : item.Path.LastIndexOf(".V");
            string fileID = item.Path.Substring(0, index);

            string newFilePath = fileID + version + ".docx";
            string pdfFIlePath = fileID + version + ".pdf";

            System.Web.HttpPostedFile         file     = System.Web.HttpContext.Current.Request.Files[0];
            Syncfusion.DocIO.DLS.WordDocument document = new Syncfusion.DocIO.DLS.WordDocument(file.InputStream);

            document.Save(path + newFilePath);
            document.Close();

            convertWordToPDF(path + newFilePath, path + pdfFIlePath);

            item.ModifiedBy = Username;


            item.Code      = pdfFIlePath;
            item.Path      = newFilePath;
            item.Extension = "docx";
            item.FileSize  = new System.IO.FileInfo(path + newFilePath).Length;

            Put(id, item);
        }
        private List <string> ConvertToImages(FileStream fs, List <string> returnStrings, Syncfusion.DocIO.FormatType type)
        {
            DocIO.WordDocument wd = new DocIO.WordDocument(fs, type);
            //Instantiation of DocIORenderer for Word to PDF conversion
            DocIORenderer render = new DocIORenderer();
            //Converts Word document into PDF document
            PdfDocument pdfDocument = render.ConvertToPDF(wd);

            //Releases all resources used by the Word document and DocIO Renderer objects
            render.Dispose();
            wd.Dispose();
            //Saves the PDF file
            MemoryStream outputStream = new MemoryStream();

            pdfDocument.Save(outputStream);
            outputStream.Position = 0;
            //Closes the instance of PDF document object
            pdfDocument.Close();

            PdfRenderer pdfExportImage = new PdfRenderer();

            //Loads the PDF document
            pdfExportImage.Load(outputStream);

            //Exports the PDF document pages into images
            Bitmap[] bitmapimage = pdfExportImage.ExportAsImage(0, pdfExportImage.PageCount - 1);
            foreach (Bitmap bitmap in bitmapimage)
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                    returnStrings.Add("data:image/png;base64," + Convert.ToBase64String(ms.ToArray()));
                }
            }
            return(returnStrings);
        }
        public RadDocument ImportDocx(string filename)
        {
            RadDocument document = null;
            Syncfusion.DocIO.DLS.WordDocument document1 = new Syncfusion.DocIO.DLS.WordDocument();
            document1.Open(filename, FormatType.Doc);
            document1.Save(filename + "x", FormatType.Docx);

            Telerik.WinControls.RichTextBox.FormatProviders.
                IDocumentFormatProvider provider = 
                new Telerik.WinControls.RichTextBox.FileFormats.OpenXml.Docx.DocxFormatProvider();

            using (FileStream stream = new FileStream(filename + "x", FileMode.Open))
            {
                document = provider.Import(stream);
            }
            return document;
        }
Exemplo n.º 5
0
        public string GetPreview([FromBody] FileManagerDirectoryContent args)
        {
            string baseFolder = this.basePath + "\\wwwroot\\Files";

            try
            {
                String fullPath    = baseFolder + args.Path;
                string extension   = Path.GetExtension(fullPath);
                Stream imageStream = null;
                if (extension == Constants.Pdf)
                {
                    try
                    {
                        FileStream  fileStream     = new FileStream(fullPath, FileMode.Open, FileAccess.Read);
                        PdfRenderer pdfExportImage = new PdfRenderer();
                        //Loads the PDF document
                        pdfExportImage.Load(fileStream);
                        //Exports the PDF document pages into images
                        Bitmap[] bitmapimage = pdfExportImage.ExportAsImage(0, 0);
                        imageStream = new MemoryStream();
                        bitmapimage[0].Save(imageStream, System.Drawing.Imaging.ImageFormat.Png);
                        imageStream.Position = 0;
                        pdfExportImage.Dispose();
                        fileStream.Close();
                    }
                    catch
                    {
                        imageStream = null;
                    }
                }
                else if (extension == Constants.Docx || extension == Constants.Rtf || extension == Constants.Doc || extension == Constants.Txt)
                {
                    try
                    {
                        FileStream fileStream = new FileStream(fullPath, FileMode.Open, FileAccess.Read);
                        //Loads file stream into Word document
                        DocIO.WordDocument document = new DocIO.WordDocument(fileStream, GetDocIOFormatType(extension));
                        fileStream.Dispose();
                        //Instantiation of DocIORenderer for Word to PDF conversion
                        DocIORenderer render = new DocIORenderer();
                        //Converts Word document into PDF document
                        PdfDocument pdfDocument = render.ConvertToPDF(document);
                        //Releases all resources used by the Word document and DocIO Renderer objects
                        render.Dispose();
                        document.Dispose();
                        //Saves the PDF file
                        MemoryStream outputStream = new MemoryStream();
                        pdfDocument.Save(outputStream);
                        outputStream.Position = 0;
                        //Closes the instance of PDF document object
                        pdfDocument.Close();

                        PdfRenderer pdfExportImage = new PdfRenderer();
                        //Loads the PDF document
                        pdfExportImage.Load(outputStream);
                        //Exports the PDF document pages into images
                        Bitmap[] bitmapimage = pdfExportImage.ExportAsImage(0, 0);
                        imageStream = new MemoryStream();
                        bitmapimage[0].Save(imageStream, System.Drawing.Imaging.ImageFormat.Png);
                        imageStream.Position = 0;

                        fileStream.Close();
                    }
                    catch
                    {
                        imageStream = null;
                    }
                }
                else if (extension == Constants.Pptx)
                {
                    try
                    {
                        IPresentation presentation = Presentation.Open(fullPath);
                        //Initialize PresentationRenderer for image conversion
                        presentation.PresentationRenderer = new PresentationRenderer();
                        //Convert the first slide to image
                        imageStream = presentation.Slides[0].ConvertToImage(ExportImageFormat.Png);
                        presentation.Dispose();
                    }
                    catch
                    {
                        imageStream = null;
                    }
                }
                if (imageStream != null)
                {
                    byte[] bytes = new byte[imageStream.Length];
                    imageStream.Read(bytes);
                    string base64 = Convert.ToBase64String(bytes);
                    return("data:image/png;base64, " + base64);
                }
                else
                {
                    return("Error");
                }
            }
            catch
            {
                return("Error");
            }
        }