Exemplo n.º 1
0
        private void Print_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                PdfDocument doc = new PdfDocument();
                doc.LoadFromFile(CommUtil.GetDocPath("test.pdf"));
                PrintDialog dialogPrint = new PrintDialog();
                dialogPrint.AllowPrintToFile            = true;
                dialogPrint.AllowSomePages              = true;
                dialogPrint.PrinterSettings.MinimumPage = 1;
                dialogPrint.PrinterSettings.MaximumPage = doc.Pages.Count;
                dialogPrint.PrinterSettings.FromPage    = 1;
                dialogPrint.PrinterSettings.ToPage      = doc.Pages.Count;

                if (dialogPrint.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    //设置打印的起始页码
                    doc.PrintFromPage = dialogPrint.PrinterSettings.FromPage;

                    //设置打印的终止页码
                    doc.PrintToPage = dialogPrint.PrinterSettings.ToPage;

                    //选择打印机
                    doc.PrinterName = dialogPrint.PrinterSettings.PrinterName;

                    PrintDocument printDoc = doc.PrintDocument;
                    dialogPrint.Document = printDoc;
                    printDoc.Print();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("打印异常");
            }
        }
Exemplo n.º 2
0
 private void ExcelToPdf()
 {
     Dispatcher.Invoke(new Action(() =>
     {
         using (Workbook workbook = new Workbook())
         {
             workbook.LoadFromFile(CommUtil.GetDocPath("test.xlsx"));
             workbook.SaveToFile(CommUtil.GetDocPath("test.pdf"), Spire.Xls.FileFormat.PDF);
             //Worksheet sheet = workbook.Worksheets[0];
             //sheet.SaveToPdf(@"e:\test.pdf");
             //Console.WriteLine("转换执行完成了");
             ////获取第一张工作表
             //Worksheet sheet = workbook.Worksheets[0];
             ////设置打印区域(设置你想要转换的单元格范围)
             //sheet.PageSetup.PrintArea = "A1:K48";
             ////将指定范围内的单元格保存为PDF
             //sheet.SaveToPdf(@"e:\test.pdf");
             //文档输出
             //Console.WriteLine("转换完成了");
             if (SaveToPath != "" && SaveToPath != null)
             {
                 File.Copy(CommUtil.GetDocPath("test.pdf"), SaveToPath, true);
             }
         }
         PdfViewer.valueChange.Flag = true;
     }));
 }
Exemplo n.º 3
0
 /// <summary>
 /// 作用:经过初步测试,第一次Excel转pdf相对较慢,所以在进入程序的时候,执行一次Excel转PDF
 /// </summary>
 public void InitializationExcelToPdf()
 {
     try
     {
         using (Workbook workbook = new Workbook())
         {
             workbook.LoadFromFile(CommUtil.GetDocPath("test1.xlsx"));
             workbook.SaveToFile(CommUtil.GetDocPath("test1.pdf"), Spire.Xls.FileFormat.PDF);
         }
     }
     catch (Exception e)
     {
         initializationExcelToPdfThread.Abort();
     }
 }
Exemplo n.º 4
0
        public void Open_File()
        {
            //moonPdfPanel.OpenFile(@"e:\123.pdf");
            //_isLoaded = true;
            //moonPdfPanel.ZoomIn();
            //var valueChange = new ValueChange();

            //备注是部分
            valueChange.OnStringChangeEvent += (oo, ee) =>
            {
                moonPdfPanel.OpenFile(CommUtil.GetDocPath("test.pdf"));
                _isLoaded = true;
                moonPdfPanel.ZoomIn();
                a.Visibility = Visibility.Hidden;
            };


            //valueChange.Flag = true;
        }
Exemplo n.º 5
0
        private void Button_Click_Print(object sender, RoutedEventArgs e)
        {
            try
            {
                if (is_comprehensiv.IsChecked == true)//训练报告
                {
                    GenerateTrainReport();
                }
                else if (is_detail.IsChecked == true)//详细报告
                {
                    GenerateDetailReport();
                }
                else if (is_nurse.IsChecked == true)//看护记录报告
                {
                    GenerateNurseReport();
                }
                else
                {
                    return;
                }
            }
            catch (Exception ex)
            {
                //Console.WriteLine("生成Excel文件异常");
                logger.Error("生成Excel文件异常");
                return;
            }

            try
            {
                //直接打印Excel文件
                Workbook workbook = new Workbook();
                workbook.LoadFromFile(CommUtil.GetDocPath("test.xlsx"));
                System.Windows.Forms.PrintDialog dialog = new System.Windows.Forms.PrintDialog();
                dialog.AllowPrintToFile           = true;
                dialog.AllowCurrentPage           = true;
                dialog.AllowSomePages             = true;
                dialog.AllowSelection             = true;
                dialog.UseEXDialog                = true;
                dialog.PrinterSettings.Duplex     = Duplex.Simplex;
                dialog.PrinterSettings.FromPage   = 0;
                dialog.PrinterSettings.ToPage     = 8;
                dialog.PrinterSettings.PrintRange = PrintRange.SomePages;
                workbook.PrintDialog              = dialog;
                PrintDocument pd = workbook.PrintDocument;
                if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    pd.Print();
                }

                if (DocumentInput_Check.IsChecked == true)
                {
                    workbook.LoadFromFile(CommUtil.GetDocPath("test.xlsx"));
                    workbook.SaveToFile(@text_output_document.Text, FileFormat.PDF);
                }
            }
            catch (Exception ex)
            {
                //Console.WriteLine("训练报告打印异常");
                logger.Error("训练报告打印异常");
            }
        }