Esempio n. 1
0
        public static void SaveStreamAsPdf( object sender, Leadtools.Printer.EmfEventArgs e )
        {
            try
             {
            ConsoleMethods.Info( "EMF Event: SaveStreamAsPdf" );
            // Write the EMF as file to disk.
            const string format = "pdf";
            string path = Path.Combine(
               GetOutputRootPath(),
               format + @"\",
               GetRandomFileName( format ) );
            Directory.CreateDirectory( Path.GetDirectoryName( path ) );

            // Create an instance of the LEADTOOLS DocumentWriter
            var docWriter = new DocumentWriter();
            docWriter.BeginDocument( path, DocumentFormat.Pdf );

            var page = new DocumentEmfPage() {
               EmfHandle = new Metafile( new MemoryStream( e.Stream.ToArray() ) )
                  .GetHenhmetafile()
            };
            docWriter.AddPage( page );
            docWriter.EndDocument();
            ConsoleMethods.Success( "SaveStreamAsPdf: Complete" );
            ConsoleMethods.Verbose( path );
             }
             catch ( Exception ex )
             {
            ConsoleMethods.Error( ex.Message, 4000 );
             }
        }
Esempio n. 2
0
        public void Save()
        {
            try
            {
                _saving = true;
                if (_tempFiles.Count == 0)
                {
                    MessageBox.Show("No pages where printed.", FrmMain._strTittle, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                Application.DoEvents();
                string             strName            = _savename;
                DocumentFormat     documentFormat     = DocumentFormat.User;
                DocumentOptions    documentOptions    = null;
                PdfDocumentOptions PdfdocumentOptions = new PdfDocumentOptions();

                InstallFonts();

                string strExt = "";

                if (_format.ToLower() == "pdf")
                {
                    documentFormat  = DocumentFormat.Pdf;
                    documentOptions = new PdfDocumentOptions();
                    (documentOptions as PdfDocumentOptions).DocumentType  = PdfDocumentType.Pdf;
                    (documentOptions as PdfDocumentOptions).FontEmbedMode = DocumentFontEmbedMode.Auto;
                    strExt = "pdf";
                }

                if (_format.ToLower() == "doc")
                {
                    documentFormat  = DocumentFormat.Doc;
                    documentOptions = new DocDocumentOptions();
                    (documentOptions as DocDocumentOptions).TextMode = DocumentTextMode.Framed;
                    strExt = "doc";
                }

                if (_format.ToLower() == "xps")
                {
                    documentFormat  = DocumentFormat.Xps;
                    documentOptions = new XpsDocumentOptions();
                    strExt          = "xps";
                }

                if (_format.ToLower() == "text")
                {
                    documentFormat  = DocumentFormat.Text;
                    documentOptions = new TextDocumentOptions();
                    strExt          = "txt";
                }

                if (!strName.Contains("." + strExt.ToLower()))
                {
                    strName += "." + strExt.ToLower();
                }

                if (_jobData != null)
                {
                    strName = Path.GetDirectoryName(strName) + "\\(" + _jobData.IPAddress + ") " + Path.GetFileName(strName);
                }

                _fileSaved = strName;

                DocumentWriter documentWriter = new DocumentWriter();
                documentWriter.SetOptions(documentFormat, documentOptions);
                documentWriter.BeginDocument(strName, documentFormat);

                foreach (string strFile in _tempFiles)
                {
#if LEADTOOLS_V20_OR_LATER
                    DocumentWriterEmfPage documentPage = new DocumentWriterEmfPage();
#elif LEADTOOLS_V19_OR_LATER
                    DocumentEmfPage documentPage = new DocumentEmfPage();
#else
                    DocumentPage documentPage = DocumentPage.Empty;
#endif // #if LEADTOOLS_V19_OR_LATER
                    Metafile metaFile = new Metafile(strFile);

                    documentPage.EmfHandle = metaFile.GetHenhmetafile();

                    documentWriter.AddPage(documentPage);

                    (new Metafile(documentPage.EmfHandle, true)).Dispose();
                    metaFile.Dispose();
                }
                documentWriter.EndDocument();

                _saved  = true;
                _saving = false;
            }
            catch (Exception Ex)
            {
                _saving = false;
                MessageBox.Show(Ex.Message, FrmMain._strTittle, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
Esempio n. 3
0
        private DialogResult SavePrintedJobsDocument()
        {
            System.Windows.Forms.DialogResult result = DialogResult.Cancel;

            try
            {
                SaveFileDialog saveFileDialog = new SaveFileDialog();
                string         strFilter;
#if LTV16_CONFIG
                strFilter = "(*.PDF Files)|*.pdf|(*.PDFA Files)|*.pdf|(*.Doc Files)|*.doc|(*.RTF Files)|*.rtf|(*.Text Files)|*.txt|(*.HTML Files)|*.html|(*.DOCX Files)|*.docx|(*.XPS Files)|*.xps";
#endif
#if LEADTOOLS_V17_OR_LATER
                strFilter = "(*.PDF Files)|*.pdf|(*.PDFA Files)|*.pdf|(*.Doc Files)|*.doc|(*.RTF Files)|*.rtf|(*.Text Files)|*.txt|(*.HTML Files)|*.html|(*.DOCX Files)|*.docx|(*.XPS Files)|*.xps|(*.XLS Files)|*.xls";
#endif
                saveFileDialog.Filter = strFilter;
                result = saveFileDialog.ShowDialog();

                if (result == DialogResult.OK)
                {
                    Application.DoEvents();
                    Cursor = Cursors.WaitCursor;
                    DocumentFormat     documentFormat     = DocumentFormat.User;
                    DocumentOptions    documentOptions    = null;
                    PdfDocumentOptions PdfdocumentOptions = new PdfDocumentOptions();
                    string             fileName           = saveFileDialog.FileName;

                    switch (saveFileDialog.FilterIndex)
                    {
                    case 1:
                        documentFormat  = DocumentFormat.Pdf;
                        documentOptions = new PdfDocumentOptions();
                        (documentOptions as PdfDocumentOptions).DocumentType  = PdfDocumentType.Pdf;
                        (documentOptions as PdfDocumentOptions).FontEmbedMode = DocumentFontEmbedMode.Auto;
                        break;

                    case 2:
                        documentFormat  = DocumentFormat.Pdf;
                        documentOptions = new PdfDocumentOptions();
                        (documentOptions as PdfDocumentOptions).DocumentType  = PdfDocumentType.PdfA;
                        (documentOptions as PdfDocumentOptions).FontEmbedMode = DocumentFontEmbedMode.Auto;
                        (documentOptions as PdfDocumentOptions).ImageOverText = true;
                        break;

                    case 3:
                        documentFormat  = DocumentFormat.Doc;
                        documentOptions = new DocDocumentOptions();
                        (documentOptions as DocDocumentOptions).TextMode = DocumentTextMode.Framed;
                        break;

                    case 4:
                        documentFormat  = DocumentFormat.Rtf;
                        documentOptions = new RtfDocumentOptions();
                        (documentOptions as RtfDocumentOptions).TextMode = DocumentTextMode.Framed;
                        break;

                    case 5:
                        documentFormat  = DocumentFormat.Text;
                        documentOptions = new TextDocumentOptions();
                        (documentOptions as TextDocumentOptions).DocumentType = TextDocumentType.Unicode;
                        (documentOptions as TextDocumentOptions).Formatted    = true;
                        break;

                    case 6:
                        documentFormat  = DocumentFormat.Html;
                        documentOptions = new HtmlDocumentOptions();
                        (documentOptions as HtmlDocumentOptions).FontEmbedMode = DocumentFontEmbedMode.Auto;
                        break;

                    case 7:
                        documentFormat  = DocumentFormat.Docx;
                        documentOptions = new DocxDocumentOptions();
                        (documentOptions as DocxDocumentOptions).MaintainAspectRatio = true;
                        (documentOptions as DocxDocumentOptions).PageRestriction     = DocumentPageRestriction.Default;
                        (documentOptions as DocxDocumentOptions).TextMode            = DocumentTextMode.Framed;
                        break;

                    case 8:
                        documentFormat  = DocumentFormat.Xps;
                        documentOptions = new XpsDocumentOptions();
                        break;

#if LTV16_CONFIG
                    case 9:
                        SaveAsEmf(fileName);
                        return(result);
#endif
#if LEADTOOLS_V17_OR_LATER
                    case 9:
                        documentFormat  = DocumentFormat.Xls;
                        documentOptions = new XlsDocumentOptions();
                        (documentOptions as XlsDocumentOptions).PageRestriction = DocumentPageRestriction.Relaxed;
                        break;

                    case 10:
                        SaveAsEmf(fileName);
                        return(result);
#endif
                    }

                    DocumentWriter documentWriter = new DocumentWriter();
                    documentWriter.SetOptions(documentFormat, documentOptions);
                    documentWriter.BeginDocument(fileName, documentFormat);

                    foreach (IntPtr metaFile in _lstMetaFiles)
                    {
#if LEADTOOLS_V20_OR_LATER
                        DocumentWriterEmfPage documentPage = new DocumentWriterEmfPage();
#elif LEADTOOLS_V19_OR_LATER
                        DocumentEmfPage documentPage = new DocumentEmfPage();
#else
                        DocumentPage documentPage = DocumentPage.Empty;
#endif // #if LEADTOOLS_V19_OR_LATER

                        int index = _lstMetaFiles.IndexOf(metaFile);

                        documentPage.EmfHandle = metaFile;

                        if (saveFileDialog.FilterIndex == 2)
                        {
                            documentPage.Image = _codec.Load(_tempFiles[index]);
                        }

                        documentWriter.AddPage(documentPage);
                    }
                    documentWriter.EndDocument();

                    if (ViewOutputFile)
                    {
                        System.Diagnostics.Process.Start(fileName);
                    }
                }
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message, "LEADTOOLS Printer Demo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }

            return(result);
        }