Ejemplo n.º 1
0
        public byte[] ToPdfBytes(ExportEventArgs exportEventArgs)
        {
            var converter = new PdfConverter
            {
                LicenseKey = Settings.Default.HtmlToPdfLicenseKey
            };

            converter.PdfDocumentOptions.PdfPageSize           = GetPdfPageSize(exportEventArgs);
            converter.PdfDocumentOptions.PdfPageOrientation    = GetPageOrientation(exportEventArgs);
            converter.PdfDocumentOptions.LeftMargin            = 18;
            converter.PdfDocumentOptions.RightMargin           = 18;
            converter.PdfDocumentOptions.TopMargin             = 18;
            converter.PdfDocumentOptions.BottomMargin          = 18;
            converter.PdfDocumentOptions.GenerateSelectablePdf = true;
            converter.PdfDocumentOptions.FitWidth = true;
            converter.PageWidth       = 1200;
            converter.AvoidTextBreak  = true;
            converter.AvoidImageBreak = true;
            var html = exportEventArgs.ExportType == ExportType.CustomPdf
                                        ? exportEventArgs.Document
                                        : String.Format("<html><head>{0}</head><body><CENTER><BR/>{1}</center></body></html>", ExportPdfHelper.cssPdf,
                                                        exportEventArgs.Document);

            return(converter.GetPdfBytesFromHtmlString(html));
        }
Ejemplo n.º 2
0
        private void btnExport_Click(object sender, EventArgs e)
        {
            try
            {
                if (!SelectedItems.Any())
                {
                    MessageBox.Show(strings.ExportNoItemSelected, strings.ExportFormMessageCaption, MessageBoxButtons.OK,
                                    MessageBoxIcon.Exclamation);
                    return;
                }

                ExportEventArgs args = new ExportEventArgs()
                {
                    ProjectName = txtProjectName.Text, Path = txtExportPath.Text
                };
                if (PathValidating != null)
                {
                    PathValidating(this, args);
                }
                if (!args.Cancel)
                {
                    MessageBox.Show(strings.PathIsNotValid, strings.ExportFormMessageCaption, MessageBoxButtons.OK,
                                    MessageBoxIcon.Exclamation);
                    return;
                }

                int    numofChecked   = SelectedItems.Count();
                string confirmMessage = string.Format(strings.ExportConfirmation,
                                                      numofChecked, numofChecked == 1 ? strings.Item : strings.Items);
                DialogResult answer = MessageBox.Show(
                    confirmMessage, strings.ExportFormMessageCaption, MessageBoxButtons.YesNo,
                    MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
                if (answer == DialogResult.No)
                {
                    return;
                }

                args = new ExportEventArgs()
                {
                    ProjectName        = txtProjectName.Text,
                    Path               = txtExportPath.Text,
                    SelectedComponents = SelectedItems
                };
                if (ExportRequestedRaised != null)
                {
                    ExportRequestedRaised(this, args);
                }
                if (args.Cancel)
                {
                    return;
                }
                MessageBox.Show(string.Format(strings.SuccessfullyExported, numofChecked),
                                strings.ExportFormMessageCaption, MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, strings.ExportFormMessageCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 3
0
        private void Editor_Export(object sender, ExportEventArgs e)
        {
            switch (e.Target)
            {
            case Enums.ExportTarget.Editor:
                string     content = GenerateCharSetCode(e.Prefix, e.Postfix, e.SingleDim, e.CharSet, e.Colors);
                TextEditor editor  = new TextEditor(e.CharSet.Name, content);
                editor.MdiParent = this;
                editor.Show();
                break;

            case Enums.ExportTarget.Clipboard:
                string contentc = GenerateCharSetCode(e.Prefix, e.Postfix, e.SingleDim, e.CharSet, e.Colors);
                Clipboard.SetText(contentc);
                MessageBox.Show("Content copied to clipboard");
                break;

            case Enums.ExportTarget.File:

                string contentf = GenerateCharSetCode(e.Prefix, e.Postfix, e.SingleDim, e.CharSet, e.Colors);
                using (var dlg = new SaveFileDialog {
                    FileName = this.Name + ".zxbas", Filter = "Basic files (.zxbas)|*.zxbas|Basic files (.bas)|*.bas"
                })
                {
                    if (dlg.ShowDialog() == DialogResult.OK)
                    {
                        File.WriteAllText(dlg.FileName, contentf);
                    }
                }

                break;
            }
        }
Ejemplo n.º 4
0
 private void ExportLibrary(object sender, ExportEventArgs e)
 {
     Database.ExportToExcel(e.Data);
     if (e.Data.OpenAfterExport)
     {
         System.Diagnostics.Process.Start(e.Data.FileName);
     }
 }
 private static ExpertPdf.HtmlToPdf.PdfPageSize GetPdfPageSize(ExportEventArgs exportEventArgs)
 {
     switch (exportEventArgs.Settings.PdfPageSize)
     {
         case PdfPageSize.Letter:
             return ExpertPdf.HtmlToPdf.PdfPageSize.Letter;
         case PdfPageSize.Legal:
             return ExpertPdf.HtmlToPdf.PdfPageSize.Legal;
     }
     throw new NotSupportedException();
 }
 private static ExpertPdf.HtmlToPdf.PDFPageOrientation GetPageOrientation(ExportEventArgs exportEventArgs)
 {
     switch (exportEventArgs.Settings.PdfPageOrientation)
     {
         case PDFPageOrientation.Landscape:
             return ExpertPdf.HtmlToPdf.PDFPageOrientation.Landscape;
         case PDFPageOrientation.Portrait:
             return ExpertPdf.HtmlToPdf.PDFPageOrientation.Portrait;
     }
     throw new NotSupportedException();
 }
Ejemplo n.º 7
0
        private static ExpertPdf.HtmlToPdf.PdfPageSize GetPdfPageSize(ExportEventArgs exportEventArgs)
        {
            switch (exportEventArgs.Settings.PdfPageSize)
            {
            case PdfPageSize.Letter:
                return(ExpertPdf.HtmlToPdf.PdfPageSize.Letter);

            case PdfPageSize.Legal:
                return(ExpertPdf.HtmlToPdf.PdfPageSize.Legal);
            }
            throw new NotSupportedException();
        }
Ejemplo n.º 8
0
        private static ExpertPdf.HtmlToPdf.PDFPageOrientation GetPageOrientation(ExportEventArgs exportEventArgs)
        {
            switch (exportEventArgs.Settings.PdfPageOrientation)
            {
            case PDFPageOrientation.Landscape:
                return(ExpertPdf.HtmlToPdf.PDFPageOrientation.Landscape);

            case PDFPageOrientation.Portrait:
                return(ExpertPdf.HtmlToPdf.PDFPageOrientation.Portrait);
            }
            throw new NotSupportedException();
        }
Ejemplo n.º 9
0
        private void Export_Requested(object sender, ExportEventArgs args)
        {
            switch (args.ExportType)
            {
            case ExportType.Image:
                ExportImages(false);
                break;

            case ExportType.PDFSharp:
                ExportViaPDFSharp(false);
                break;
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 导出Model类
        /// </summary>
        /// <param name="strDbName">数据库名称</param>
        /// <param name="table">数据库表</param>
        /// <param name="savePath">文件夹存储路径</param>
        public void ExportModel(string strDbName, List <Table> tables, string saveDirectoryPath)
        {
            nVelocity = new NVelocityHelper(AppDomain.CurrentDomain.BaseDirectory + "Template");
            nVelocity.TemplateFileName = "ModelTpl.cstpl";
            nVelocity.Put("ConnType", Config.ConnType.ToString());
            nVelocity.Put("DatabaseName", Config.DatabaseName);
            nVelocity.Put("this", this);

            ExportEventArgs args = new ExportEventArgs();

            args.IsFinished = false;
            args.Info       = "开始生成Model类……";
            if (null != OnExport)
            {
                this.OnExport(this, args);
            }

            if (!Directory.Exists(saveDirectoryPath + Config.DatabaseName))
            {
                Directory.CreateDirectory(saveDirectoryPath + Config.DatabaseName);
            }

            args.TotalNum = tables.Count;
            foreach (Table table in tables)
            {
                nVelocity.Remove("Table");
                nVelocity.Put("Table", table);
                nVelocity.Remove("Columns");
                nVelocity.Put("Columns", table.Columns);
                int i = 0;
                nVelocity.Put("i", i);
                File.WriteAllText(Path.Combine(saveDirectoryPath, Config.DatabaseName + "/" + table.Name + ".cs"), nVelocity.Content, encoding);

                ++args.NowIndex;
                if (null != OnExport)
                {
                    this.OnExport(this, args);
                }
            }

            args.IsFinished = true;
            args.Info       = "Model类生成完成";
            if (null != OnExport)
            {
                this.OnExport(this, args);
            }

            nVelocity.Dispose();
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 导出数据字典
        /// </summary>
        /// <param name="strDbName">数据库名称</param>
        /// <param name="table">数据库表</param>
        /// <param name="savePath">文件存储路径</param>
        public void ExportDbDic(string strDbName, List <Table> tables, string saveFilePath)
        {
            nVelocity = new NVelocityHelper(AppDomain.CurrentDomain.BaseDirectory + "Template");
            nVelocity.TemplateFileName = "DbDicTpl.html";
            nVelocity.Put("ConnType", Config.ConnType.ToString());
            nVelocity.Put("DatabaseName", Config.DatabaseName);
            nVelocity.Put("this", this);

            int i = 1;

            nVelocity.Put("i", i);

            int j = 0;

            nVelocity.Put("j", j);

            ExportEventArgs args = new ExportEventArgs();

            args.IsFinished = false;
            args.Info       = "开始生成数据字典……";
            if (null != OnExport)
            {
                this.OnExport(this, args);
            }

            args.TotalNum = tables.Count;
            args.NowIndex = 1;

            nVelocity.Remove("Tables");
            nVelocity.Put("Tables", tables);
            File.WriteAllText(saveFilePath, nVelocity.Content, encoding);

            args.IsFinished = true;
            args.NowIndex   = args.TotalNum;
            args.Info       = "数据字典生成完成";
            if (null != OnExport)
            {
                this.OnExport(this, args);
            }

            nVelocity.Dispose();
        }
        public static byte[] ConvertToPdf(this HtmlTag tag)
        {
            // todo this method is ok, but how about we also move this code somewhere and make a builder that can be controlled instead of defaults here and then keep this method but plugin to the builder.
            var html = tag.ToString();

            var settings = new ExportEventArgs.ExportSettings
                           	{
                           		PdfPageOrientation = PDFPageOrientation.Portrait,
                           		PdfPageSize = PdfPageSize.Letter
                           	};

            var options = new ExportEventArgs(html, "export")
                          	{
                          		ExportType = ExportType.CustomPdf,
                          		SendByEmail = false,
                          		Settings = settings
                          	};

            return ExportPdfHelper.ToPdfBytes(options);
        }
        public static byte[] ConvertToPdf(this HtmlTag tag)
        {
            // todo this method is ok, but how about we also move this code somewhere and make a builder that can be controlled instead of defaults here and then keep this method but plugin to the builder.
            var html = tag.ToString();

            var settings = new ExportEventArgs.ExportSettings
            {
                PdfPageOrientation = PDFPageOrientation.Portrait,
                PdfPageSize        = PdfPageSize.Letter
            };

            var options = new ExportEventArgs(html, "export")
            {
                ExportType  = ExportType.CustomPdf,
                SendByEmail = false,
                Settings    = settings
            };

            return(ExportPdfHelper.ToPdfBytes(options));
        }
Ejemplo n.º 14
0
        private void Export_Requested(object sender, ExportEventArgs args)
        {
            switch (args.ExportType)
            {
            case ExportType.Image:
                ExportImages(FileCardExporterFactory.BuildFileCardExporter(false));
                break;

            case ExportType.SingleImage:
                ExportImages(FileCardExporterFactory.BuildImageExporter());
                break;

            case ExportType.SingleImageClipboard:
                ExportImages(FileCardExporterFactory.BuildImageClipboardExporter());
                break;

            case ExportType.PDFSharp:
                ExportViaPDFSharp(false);
                break;
            }
        }
Ejemplo n.º 15
0
        private void StaticUpdater_OnExportEvent(object sender, ExportEventArgs e)
        {
            MainWindow window = (MainWindow)MainWindow;

            switch (e.ExportType)
            {
            case ExportType.Screenshot:
                window.ExportScreenshot();
                break;

            case ExportType.Individual:
                switch (e.EditType)
                {
                case EditType.Appointment:
                    window.ExportAppointment();
                    break;

                case EditType.Contact:
                    window.ExportContact();
                    break;

                case EditType.Task:
                    window.ExportTask();
                    break;

                case EditType.Note:
                    window.ExportNote();
                    break;

                default:
                    break;
                }
                break;

            default:
                break;
            }
        }
 public byte[] ToPdfBytes(ExportEventArgs exportEventArgs)
 {
     var converter = new PdfConverter
                         {
                             LicenseKey = Settings.Default.HtmlToPdfLicenseKey
                         };
     converter.PdfDocumentOptions.PdfPageSize = GetPdfPageSize(exportEventArgs);
     converter.PdfDocumentOptions.PdfPageOrientation = GetPageOrientation(exportEventArgs);
     converter.PdfDocumentOptions.LeftMargin = 18;
     converter.PdfDocumentOptions.RightMargin = 18;
     converter.PdfDocumentOptions.TopMargin = 18;
     converter.PdfDocumentOptions.BottomMargin = 18;
     converter.PdfDocumentOptions.GenerateSelectablePdf = true;
     converter.PdfDocumentOptions.FitWidth = true;
     converter.PageWidth = 1200;
     converter.AvoidTextBreak = true;
     converter.AvoidImageBreak = true;
     var html = exportEventArgs.ExportType == ExportType.CustomPdf
                	? exportEventArgs.Document
                	: String.Format("<html><head>{0}</head><body><CENTER><BR/>{1}</center></body></html>", ExportPdfHelper.cssPdf,
                	                exportEventArgs.Document);
     return converter.GetPdfBytesFromHtmlString(html);
 }
 public static byte[] ToPdfBytes(ExportEventArgs exportEventArgs)
 {
     return Converter.ToPdfBytes(exportEventArgs);
 }
Ejemplo n.º 18
0
 void AutostartCommand_ScriptExported(object sender, ExportEventArgs e)
 {
     AddTransactionNames(e.Script as IVuGenScript,Path.Combine(e.PersistenceToken.LocalPath,e.PersistenceToken.LoadData));
 }
Ejemplo n.º 19
0
 void AutostartCommand_ScriptExported(object sender, ExportEventArgs e)
 {
     AddTransactionNames(e.Script as IVuGenScript, Path.Combine(e.PersistenceToken.LocalPath, e.PersistenceToken.LoadData));
 }
 public static byte[] ToPdfBytes(ExportEventArgs exportEventArgs)
 {
     return(Converter.ToPdfBytes(exportEventArgs));
 }
Ejemplo n.º 21
0
        /// <summary>
        /// Export document to jpg stream supplied by DocManager
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void docManager_ExportEvent(object sender, ExportEventArgs e)
        {
            Size size   = drawArea.GraphicsList.GetSize();
            int  width  = size.Width;
            int  height = size.Height;

            int stride = GetStride(width, System.Drawing.Imaging.PixelFormat.Format32bppRgb);

            Debug.Assert(stride > 0);

            // Define the image palette
            BitmapPalette myPalette = BitmapPalettes.Halftone256;

            byte[]       bmpData     = new byte[stride * height];
            GCHandle     pinnedArray = GCHandle.Alloc(bmpData, GCHandleType.Pinned);
            IntPtr       pointer     = pinnedArray.AddrOfPinnedObject();
            BitmapSource image       = null;

            try
            {
                Image bmp = new Bitmap(width, height, stride, System.Drawing.Imaging.PixelFormat.Format32bppRgb, pointer);

                using (Graphics g = Graphics.FromImage(bmp))
                {
                    SolidBrush brush = new SolidBrush(System.Drawing.Color.FromArgb(255, 255, 255));
                    g.FillRectangle(brush, new Rectangle(0, 0, width, height));

                    if (drawArea.GraphicsList != null)
                    {
                        drawArea.GraphicsList.Draw(g);
                    }
                }

                // Creates a new empty image with the pre-defined palette
                image = BitmapSource.Create(
                    width,
                    height,
                    96,
                    96,
                    PixelFormats.Bgr32, // Indexed8
                    myPalette,
                    pointer,
                    stride * height,
                    stride);
            }
            finally
            {
                //do your stuff
                pinnedArray.Free();
            }

            Stream            stream  = e.SaveStream;
            JpegBitmapEncoder encoder = new JpegBitmapEncoder();

            encoder.FlipHorizontal = false;
            encoder.FlipVertical   = false;
            encoder.QualityLevel   = 30;
            encoder.Rotation       = Rotation.Rotate0;
            encoder.Frames.Add(BitmapFrame.Create(image));
            encoder.Save(stream);
        }