static void PrintDocument(RichEditDocumentServer wordProcessor) { #region #PrintDocument wordProcessor.Document.AppendDocumentContent("Documents\\Grimm.docx", DocumentFormat.OpenXml); wordProcessor.Print(); #endregion #PrintDocument }
public bool Print(string filePath, PrinterSettings printerSettings) { if (!base.CanPrint(filePath)) { return(false); } using (RichEditDocumentServer richServer = new RichEditDocumentServer()) { richServer.LoadDocument(filePath); richServer.Print(printerSettings); } return(true); }
private void PrtContent(string strText) { RichEditDocumentServer server = new RichEditDocumentServer(); //server.LoadDocument(strFileName, DocumentFormat.Html); server.BeginUpdate(); server.Document.HtmlText = strText; server.Document.Unit = DocumentUnit.Point; foreach (Section section in server.Document.Sections) { //section.Page.PaperKind = PaperKind.Custom; section.Page.Landscape = false; section.Page.Width = 200; section.Margins.Left = 1f; section.Margins.Right = 1f; section.Margins.Top = 0f; section.Margins.Bottom = 0f; } server.Document.DefaultParagraphProperties.Alignment = ParagraphAlignment.Center; PrintableComponentLink link = new PrintableComponentLink(); PrintingSystem ps = new PrintingSystem(); ps.Links.Add(link); link.Component = server; link.PrintingSystem.ShowMarginsWarning = false; link.PrintingSystem.ShowPrintStatusDialog = false; link.CreateDocument(); //PrinterSettings pSet = new PrinterSettings(); //pSet.Copies = 2; //pSet.PrinterName = strDefaultPrintName; //ps.PreviewFormEx.Show(); //link.ShowPreview(); SetRichTextValue(DateTime.Now.ToString("o") + "###Print Count = 1###"); server.Print(); //ps.PreviewFormEx.Show(); //link.ShowPreview(); //link.Print(); //ps.Print(); }
private void simpleAction1_Execute_1(object sender, SimpleActionExecuteEventArgs e) { MauIn mauIn = (MauIn)View.CurrentObject; NguoiDung nguoiDung = mauIn.Session.GetObjectByKey <NguoiDung>(SecuritySystem.CurrentUserId); //Name of files FileData chungNhan = mauIn.fileMau; string fileName = chungNhan.FileName; string fileNameTemp = @"TempFile\" + fileName; string fileNameSave = @"SaveFile\" + fileName; //Names of fields in files //if (nguoiDung.thanhVien.TenNguoiDung != null) ; string tenNguoiDung = nguoiDung.thanhVien.TenNguoiDung != null? nguoiDung.thanhVien.TenNguoiDung:""; DateTime _ngaySinh = (DateTime)nguoiDung.thanhVien.ngaySinh; string ngaySinh = _ngaySinh.ToString("dd-MM-yyyy") != null?_ngaySinh.ToString("dd-MM-yyyy") : "";//Edit format of DateTime string gioiTinh = nguoiDung.thanhVien.ToString() != null?nguoiDung.thanhVien.ToString() : ""; string MSSV = nguoiDung.thanhVien.MSSV != null ? nguoiDung.thanhVien.MSSV : ""; string khoa = nguoiDung.thanhVien.khoaString != null ? nguoiDung.thanhVien.khoaString : ""; string SDT = nguoiDung.thanhVien.SDT != null ? nguoiDung.thanhVien.SDT : ""; string email = nguoiDung.thanhVien.email != null ? nguoiDung.thanhVien.email : ""; string diaChi = nguoiDung.thanhVien.diaChi != null ? nguoiDung.thanhVien.diaChi : ""; //int soLanIn = nguoiDung.soLanIn; using (RichEditDocumentServer srv = new RichEditDocumentServer()) { if (srv.LoadDocument(fileNameTemp, DocumentFormat.OpenXml)) { Document doc = srv.Document; //tenNguoiDung DocumentRange[] ranges = doc.FindAll("<tenNguoiDung>", SearchOptions.None); for (int i = 0; i < ranges.Length; i++) { doc.Replace(ranges[i], tenNguoiDung); } //ngaySinh DocumentRange[] range1s = doc.FindAll("<ngaySinh>", SearchOptions.None); for (int i = 0; i < range1s.Length; i++) { doc.Replace(range1s[i], ngaySinh); } //gioiTinh DocumentRange[] range2s = doc.FindAll("<gioiTinh>", SearchOptions.None); for (int i = 0; i < range2s.Length; i++) { doc.Replace(range2s[i], gioiTinh); } //MSSV DocumentRange[] range3s = doc.FindAll("<MSSV>", SearchOptions.None); for (int i = 0; i < range3s.Length; i++) { doc.Replace(range3s[i], MSSV); } //khoa DocumentRange[] range4s = doc.FindAll("<khoa>", SearchOptions.None); for (int i = 0; i < range4s.Length; i++) { doc.Replace(range4s[i], khoa); } //SDT DocumentRange[] range5s = doc.FindAll("<SDT>", SearchOptions.None); for (int i = 0; i < range5s.Length; i++) { doc.Replace(range5s[i], SDT); } //email DocumentRange[] range6s = doc.FindAll("<email>", SearchOptions.None); for (int i = 0; i < range6s.Length; i++) { doc.Replace(range6s[i], email); } //diaChi DocumentRange[] range7s = doc.FindAll("<diaChi>", SearchOptions.None); for (int i = 0; i < range7s.Length; i++) { doc.Replace(range7s[i], diaChi); } } srv.SaveDocument(fileNameSave, DocumentFormat.OpenXml); //srv.Document.Sections[0].Page.Landscape = true; //DevExpress.XtraPrinting.PrintableComponentLink link = new DevExpress.XtraPrinting.PrintableComponentLink(new DevExpress.XtraPrinting.PrintingSystem()); if (nguoiDung.soLanIn > 0) { srv.Print(); nguoiDung.soLanIn--; MessageBox.Show("You have " + nguoiDung.soLanIn.ToString() + " more time(s) to PRINT"); nguoiDung.Save();// lưu lại giá trị } else { MessageBox.Show("Your print time has run out!"); } //FileStream fsOut = File.Open("FileOut.pdf", FileMode.Create); //srv.ExportToPdf(fsOut); //fsOut.Close(); } //RichEditDocumentServer srv1 = new RichEditDocumentServer(); //srv1.LoadDocument(fileNameTemp, DocumentFormat.OpenXml); //DevExpress.XtraPrinting.PdfExportOptions options = new DevExpress.XtraPrinting.PdfExportOptions(); //options.Compressed = false; //options.ImageQuality = DevExpress.XtraPrinting.PdfJpegImageQuality.Highest; //FileStream pdfFileStream = new FileStream("Document_PDF.pdf", FileMode.Create); //srv1.ExportToPdf(pdfFileStream, options); //System.Diagnostics.Process.Start("Document_PDF.pdf"); //System.Diagnostics.Process.Start(fileNameSave); //FileAttachmentsWindowsFormsModule.GetFileDataManager(Application).Open(chungNhan);//Open FileData //PreviewPrint previewPrintWindow = new PreviewPrint(); //previewPrintWindow.ShowDialog(); }