예제 #1
0
        private void GenerarPDF_Temporal(tblDocumentoContenido contenido, string TipoDocumento, int _orden)
        {
            RichEditDocumentServer _reServer = new RichEditDocumentServer();
            MemoryStream           _ms       = new MemoryStream();
            string _tempFileName             = string.Format("tmp{0}_{1}_{2}_{3}_{4}.pdf", TipoDocumento,
                                                             contenido.IdEmpresa.ToString("000"),
                                                             _orden.ToString("00"),
                                                             contenido.IdDocumento.ToString("000"),
                                                             contenido.IdSubModulo.ToString("00000000"));

            string _tempFile = string.Format("{0}/{1}", _tempFilePath, _tempFileName);

            if (File.Exists(_tempFile))
            {
                File.Delete(_tempFile);
            }

            FileStream   _fileStream = new FileStream(_tempFile, FileMode.Create);
            MemoryStream _msData     = new MemoryStream(contenido.ContenidoBin.ToArray());

            _reServer.Document.LoadDocument(_msData, DevExpress.XtraRichEdit.DocumentFormat.OpenXml);
            _reServer.ExportToPdf(_ms);
            _reServer.EndUpdate();

            _ms.WriteTo(_fileStream);
            _ms.Close();
            _msData.Close();
            _fileStream.Close();
        }
예제 #2
0
        static void Main(string[] args)
        {
            var dir          = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            var templateFile = Path.Combine(dir, "template.dotx");
            var dataFile     = Path.Combine(dir, "template.json");

            using (var documentServer = new RichEditDocumentServer())
            {
                if (File.Exists(templateFile) && documentServer.LoadFileInDetectionMode(templateFile))
                {
                }
                else
                {
                    throw new Exception("Could not load file");
                }

                documentServer.BeginUpdate();
                try
                {
                    var dataText = File.ReadAllText(dataFile);
                    var template = JsonConvert.DeserializeObject <Template>(dataText);
                    InsertItems(documentServer.Document, template);
                }
                finally
                {
                    documentServer.EndUpdate();
                }

                SaveDocument(dir, documentServer);
            }
        }
예제 #3
0
        private void btn_Print_Click(object sender, EventArgs e)
        {
            #region #serverprint
            RichEditDocumentServer richServer = new RichEditDocumentServer();

            // Specify default formatting
            richServer.Document.DefaultParagraphProperties.Alignment = ParagraphAlignment.Center;

            // Specify page settings
            richServer.Document.Sections[0].Page.Landscape = true;
            richServer.Document.Sections[0].Page.Height    = DevExpress.Office.Utils.Units.InchesToDocumentsF(10.0f);
            richServer.Document.Sections[0].Page.Width     = DevExpress.Office.Utils.Units.InchesToDocumentsF(4.5f);

            // Add document content
            richServer.Document.AppendText("This content is created programmatically\n");
            richServer.Document.Paragraphs.Append();

            //Create a table
            richServer.BeginUpdate();

            Table _table = richServer.Document.Tables.Create(richServer.Document.Selection.Start, 8, 8, AutoFitBehaviorType.FixedColumnWidth);
            _table.BeginUpdate();
            _table.Borders.InsideHorizontalBorder.LineThickness = 1;
            _table.Borders.InsideHorizontalBorder.LineStyle     = TableBorderLineStyle.Double;
            _table.Borders.InsideVerticalBorder.LineThickness   = 1;
            _table.Borders.InsideVerticalBorder.LineStyle       = TableBorderLineStyle.Double;
            _table.TableAlignment = TableRowAlignment.Center;

            _table.ForEachCell((cell, rowIndex, columnIndex) =>
            {
                richServer.Document.InsertText(cell.Range.Start, String.Format("{0}*{1} is {2}",
                                                                               rowIndex + 2, columnIndex + 2, (rowIndex + 2) * (columnIndex + 2)));
            });
            _table.EndUpdate();

            richServer.EndUpdate();

            // Invoke the Print Preview dialog
            using (PrintingSystem printingSystem = new PrintingSystem())
            {
                using (PrintableComponentLink link = new PrintableComponentLink(printingSystem))
                {
                    link.Component = richServer;
                    link.CreateDocument();
                    link.ShowPreviewDialog();
                }
            }
            #endregion #serverprint
        }
예제 #4
0
 static void InsertBookmark(RichEditDocumentServer server)
 {
     #region #InsertBookmark
     server.LoadDocument("Documents\\Grimm.docx", DocumentFormat.OpenXml);
     server.BeginUpdate();
     Document         document = server.Document;
     DocumentPosition pos      = document.Range.Start;
     document.Bookmarks.Create(server.Document.CreateRange(pos, 0), "Top");
     //Insert the hyperlink anchored to the created bookmark:
     DocumentPosition pos1 = document.CreatePosition((server.Document.Range.End).ToInt() + 25);
     document.Hyperlinks.Create(server.Document.InsertText(pos1, "get to the top"));
     document.Hyperlinks[0].Anchor = "Top";
     server.EndUpdate();
     #endregion #InsertBookmark
 }
예제 #5
0
        private void btn_PrintFromServer_Click(object sender, EventArgs e)
        {
            RichEditDocumentServer srv = new RichEditDocumentServer();

            srv.LoadDocument("Grimm.docx", DocumentFormat.OpenXml);
            // Insert a field displaying the current date/time into the document header.
            srv.BeginUpdate();
            SubDocument _header = srv.Document.Sections[0].BeginUpdateHeader();

            _header.Fields.Create(_header.Range.Start, "DATE \\@ \"dddd, MMMM dd, yyyy  HH:mm:ss\" \\MERGEFORMAT");
            _header.Paragraphs[0].Alignment = ParagraphAlignment.Right;
            srv.Document.Sections[0].EndUpdateHeader(_header);
            // Specify page margins, orientation, etc.
            SetPrintOptions(srv);
            srv.EndUpdate();
            // Display field values instead of code.
            srv.Options.MailMerge.ViewMergedData = true;
            // Create a printable link to print a document.
            PrintViaLink(srv);
        }
예제 #6
0
        private void GenerarPDF_Temporal(byte[] ContenidoBin, string _tempFileName)
        {
            RichEditDocumentServer _reServer = new RichEditDocumentServer();
            MemoryStream           _ms       = new MemoryStream();

            string _tempFile = string.Format("{0}/{1}", _tempFilePath, _tempFileName);

            if (File.Exists(_tempFile))
            {
                File.Delete(_tempFile);
            }

            FileStream   _fileStream = new FileStream(_tempFile, FileMode.Create);
            MemoryStream _msData     = new MemoryStream(ContenidoBin.ToArray());

            _reServer.Document.LoadDocument(_msData, DevExpress.XtraRichEdit.DocumentFormat.OpenXml);
            _reServer.ExportToPdf(_ms);
            _reServer.EndUpdate();

            _ms.WriteTo(_fileStream);
            _ms.Close();
            _msData.Close();
            _fileStream.Close();
        }