Beispiel #1
0
        public virtual void proPdf()
        {
            try
            {
                PrintableComponentLink y = new DevExpress.XtraPrinting.PrintableComponentLink(new PrintingSystem());
                y.Component = grcListado;
                y.CreateReportHeaderArea += y_CreateReportHeaderArea;

                this.saveFileDialog.FileName         = "";
                this.saveFileDialog.Filter           = "Adobe PDF|*.pdf";
                this.saveFileDialog.FilterIndex      = 2;
                this.saveFileDialog.RestoreDirectory = true;

                Stream filename;
                string varNombre;

                if (this.saveFileDialog.ShowDialog() == DialogResult.OK)
                {
                    filename  = this.saveFileDialog.OpenFile();
                    varNombre = this.saveFileDialog.FileName;

                    if (filename != null)
                    {
                        filename.Close();
                        y.ExportToPdf(varNombre);
                    }
                    proAbrirArchivo(varNombre);
                }
            }
            catch (Exception ex) { XtraMessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }
        }
        void PDFClick(object sender, EventArgs e)
        {
            using (SaveFileDialog saveDialog = new SaveFileDialog())
            {
                saveDialog.Filter = "*.pdf|*.pdf";
                if (saveDialog.ShowDialog() == DialogResult.OK)
                {
                    string exportFilePath = saveDialog.FileName;
                    DevExpress.XtraPrinting.PrintableComponentLink link = new DevExpress.XtraPrinting.PrintableComponentLink(new PrintingSystem());
                    link.VerticalContentSplitting = DevExpress.XtraPrinting.VerticalContentSplitting.Exact;
                    link.Margins.Left             = 0;
                    link.Margins.Right            = 0;
                    link.Margins.Top    = 0;
                    link.Margins.Bottom = 0;
                    link.Component      = receiptsJournalGrid;
                    //link.Landscape = true;// ориентация альбомная
                    link.PaperKind = System.Drawing.Printing.PaperKind.A4;

                    string fileExtenstion = new FileInfo(exportFilePath).Extension;

                    switch (fileExtenstion)
                    {
                    case ".pdf":
                        receiptsJournalGridView.OptionsPrint.ExpandAllDetails = true;
                        receiptsJournalGridView.OptionsPrint.AutoWidth        = true;
                        link.ExportToPdf(exportFilePath);
                        break;

                    default:
                        break;
                    }

                    if (File.Exists(exportFilePath))
                    {
                        try
                        {
                            System.Diagnostics.Process.Start(exportFilePath);
                        }
                        catch
                        {
                            String msg = "The file could not be opened." + Environment.NewLine + Environment.NewLine + "Path: " + exportFilePath;
                            MessageBox.Show(msg, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    else
                    {
                        String msg = "The file could not be saved." + Environment.NewLine + Environment.NewLine + "Path: " + exportFilePath;
                        MessageBox.Show(msg, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }