Пример #1
0
        protected virtual void SaveBookToFile(IRichEditDocumentServer bookServer, string fileName, SaveOptions options)
        {
            var format = DocumentFormat.OpenXml;

            switch (Path.GetExtension(fileName)?.ToLower())
            {
            case ".docx":
                format = DocumentFormat.OpenXml;
                break;

            case ".doc":
                format = DocumentFormat.Doc;
                break;

            case ".txt":
            case ".text":
                format = DocumentFormat.PlainText;
                break;

            case ".rtf":
                format = DocumentFormat.Rtf;
                break;

            case ".html":
            case ".htm":
                format = DocumentFormat.Html;
                break;

            case ".mht":
                format = DocumentFormat.Mht;
                break;

            case ".odt":
                format = DocumentFormat.OpenDocument;
                break;

            case ".epub":
                format = DocumentFormat.ePub;
                break;

            case ".pdf":
                format = DocumentFormat.Undefined;
                break;
            }

            if (format == DocumentFormat.Undefined)
            {
                var pdfOptions = new PdfExportOptions()
                {
                    ConvertImagesToJpeg   = false,
                    ImageQuality          = PdfJpegImageQuality.Highest,
                    PdfACompatibility     = PdfACompatibility.None,
                    ShowPrintDialogOnOpen = false
                };

                using var ps   = new PrintingSystem();
                using var link = new PrintableComponentLink(ps)
                      {
                          Component = bookServer as IPrintable
                      };
                link.CreateDocument();

                ExecuteLocked(() => ps.ExportToPdf(fileName, pdfOptions), (options?.LockFiles ?? false) ? LockObject : null);
            }
            else
            {
                ExecuteLocked(() => bookServer.Document.SaveDocument(fileName, format), (options?.LockFiles ?? false) ? LockObject : null);
            }
        }
Пример #2
0
 public SCBook Save(string fileName, SaveOptions options = null)
 {
     ExecuteSynchronized(options, () => DoSave(fileName, options));
     return(this);
 }