private static void SetDocumentWriterOptions(DocumentWriter docWriter, DocumentFormat format) { switch (format) { #if LEADTOOLS_V19_OR_LATER case DocumentFormat.Ltd: #else case DocumentFormat.Ltd: #endif // #if LEADTOOLS_V19_OR_LATER case DocumentFormat.Pdf: case DocumentFormat.Html: case DocumentFormat.Text: case DocumentFormat.Emf: case DocumentFormat.Xps: case DocumentFormat.Xls: break; case DocumentFormat.Doc: { DocDocumentOptions docOptions = docWriter.GetOptions(format) as DocDocumentOptions; docOptions.TextMode = DocumentTextMode.Framed; docWriter.SetOptions(format, docOptions); } break; case DocumentFormat.Rtf: { RtfDocumentOptions rtfOptions = docWriter.GetOptions(format) as RtfDocumentOptions; rtfOptions.TextMode = DocumentTextMode.Framed; docWriter.SetOptions(format, rtfOptions); } break; case DocumentFormat.Docx: { DocxDocumentOptions docxOptions = docWriter.GetOptions(format) as DocxDocumentOptions; docxOptions.TextMode = DocumentTextMode.Framed; docWriter.SetOptions(format, docxOptions); } break; default: throw new ArgumentException("Invalid format"); } }
public static void ExportPdfViaSvg(string filename) { var outputFile = Path.Combine(Leadtools.Demo.Support.Path.GetOutputPath(), Path.GetFileNameWithoutExtension(filename) + "_Svg.pdf"); // Setup a new RasterCodecs object using (var codecs = new RasterCodecs()) { // Check to see if we can use this method // https://www.leadtools.com/help/leadtools/v19/dh/co/leadtools.codecs~leadtools.codecs.rastercodecs~canloadsvg(string).html if (!codecs.CanLoadSvg(filename)) { Console.WriteLine("\nCannot load this file as SVG for conversion to PDF.\nSee: https://www.leadtools.com/help/leadtools/v19/dh/co/leadtools.codecs~leadtools.codecs.rastercodecs~canloadsvg(string).html#remarksSectionHeading"); return; } codecs.Options.RasterizeDocument.Load.Resolution = 300; // Get the number of pages in the input document var pageCount = codecs.GetTotalPages(filename); // Create a new instance of the LEADTOOLS Document Writer var docWriter = new DocumentWriter(); // Set the PDF options // https://www.leadtools.com/help/leadtools/v19/dh/ft/leadtools.forms.documentwriters~leadtools.forms.documentwriters.pdfdocumentoptions.html var pdfOptions = docWriter.GetOptions(DocumentFormat.Pdf) as PdfDocumentOptions; if (pdfOptions != null) { pdfOptions.DocumentType = PdfDocumentType.Pdf; docWriter.SetOptions(DocumentFormat.Pdf, pdfOptions); } // Create a new PDF document docWriter.BeginDocument(outputFile, DocumentFormat.Pdf); var message = ""; // Loop through all the pages for (var pageNumber = 1; pageNumber <= pageCount; pageNumber++) { // Get the page as SVG // https://www.leadtools.com/help/leadtools/v19/dh/co/leadtools.codecs~leadtools.codecs.rastercodecs~loadsvg.html var page = new DocumentSvgPage(); var lastMessageLen = message.Length; message = string.Format("\rConverting page {0} of {1}", pageNumber, pageCount); var diff = lastMessageLen - message.Length; Console.Write("{0}{1}", message, (diff > 0 ? new string( ' ', diff ) : "")); using (page.SvgDocument = codecs.LoadSvg(filename, pageNumber, null)) { // Add the page docWriter.AddPage(page); } } Console.Write("\r{0}\r", new String(' ', message.Length)); // Finally, finish writing the PDF file on disk docWriter.EndDocument(); } }
private DocumentWriter OpenDocumentWriterInstance(double pageWidth, double pageHeight, int resolution) { DocumentWriter documentWriterInstance = null; try { documentWriterInstance = new DocumentWriter(); { PdfDocumentOptions pdfOptions = documentWriterInstance.GetOptions(DocumentFormat.Pdf) as PdfDocumentOptions; int emptyPageResolution = resolution; if ((int)pageWidth == 0) { pageWidth = 11; } if ((int)pageHeight == 0) { pageHeight = 8.5; } pdfOptions.EmptyPageResolution = emptyPageResolution; pdfOptions.DocumentResolution = emptyPageResolution; pdfOptions.EmptyPageWidth = pageWidth; pdfOptions.EmptyPageHeight = pageHeight; pdfOptions.PageRestriction = DocumentPageRestriction.Relaxed; pdfOptions.PrintEnabled = true; pdfOptions.ImageOverText = true; documentWriterInstance.SetOptions(DocumentFormat.Pdf, pdfOptions); } return(documentWriterInstance); } catch (Exception) { throw; } }
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); } }
private void _okButton_Click(object sender, EventArgs e) { DocumentWriter docWriter = _ocrDocument.Engine.DocumentWriterInstance; IOcrDocumentManager ocrDocumentManager = _ocrDocument.Engine.DocumentManager; // Save the options MyFormat mf = _formatComboBox.SelectedItem as MyFormat; DocumentOptions documentOptions; if (mf.Format != DocumentFormat.User) { documentOptions = docWriter.GetOptions(mf.Format); } else { documentOptions = null; } switch (mf.Format) { case DocumentFormat.User: // Update the User (Engine) options { MyEngineFormat mef = _userFormatNameComboBox.SelectedItem as MyEngineFormat; ocrDocumentManager.EngineFormat = mef.Format; } break; case DocumentFormat.Pdf: // Update the PDF options { PdfDocumentOptions pdfOptions = documentOptions as PdfDocumentOptions; pdfOptions.DocumentType = (PdfDocumentType)_pdfDocumentTypeComboBox.SelectedItem; pdfOptions.ImageOverText = _pdfImageOverTextCheckBox.Checked; pdfOptions.Linearized = _pdfLinearizedCheckBox.Checked; pdfOptions.PageRestriction = DocumentPageRestriction.Relaxed; // Description options pdfOptions.Title = _pdfOptions.Title; pdfOptions.Subject = _pdfOptions.Subject; pdfOptions.Keywords = _pdfOptions.Keywords; pdfOptions.Author = _pdfOptions.Author; pdfOptions.Creator = _pdfOptions.Creator; pdfOptions.Producer = _pdfOptions.Producer; // Fonts options pdfOptions.FontEmbedMode = _pdfOptions.FontEmbedMode; // Security options pdfOptions.Protected = _pdfOptions.Protected; if (pdfOptions.Protected) { pdfOptions.UserPassword = _pdfOptions.UserPassword; pdfOptions.OwnerPassword = _pdfOptions.OwnerPassword; pdfOptions.EncryptionMode = _pdfOptions.EncryptionMode; pdfOptions.PrintEnabled = _pdfOptions.PrintEnabled; pdfOptions.HighQualityPrintEnabled = _pdfOptions.HighQualityPrintEnabled; pdfOptions.CopyEnabled = _pdfOptions.CopyEnabled; pdfOptions.EditEnabled = _pdfOptions.EditEnabled; pdfOptions.AnnotationsEnabled = _pdfOptions.AnnotationsEnabled; pdfOptions.AssemblyEnabled = _pdfOptions.AssemblyEnabled; } // Compression options pdfOptions.OneBitImageCompression = _pdfOptions.OneBitImageCompression; pdfOptions.ColoredImageCompression = _pdfOptions.ColoredImageCompression; pdfOptions.QualityFactor = _pdfOptions.QualityFactor; pdfOptions.ImageOverTextSize = _pdfOptions.ImageOverTextSize; pdfOptions.ImageOverTextMode = _pdfOptions.ImageOverTextMode; // Initial View Options pdfOptions.PageModeType = _pdfOptions.PageModeType; pdfOptions.PageLayoutType = _pdfOptions.PageLayoutType; pdfOptions.PageFitType = _pdfOptions.PageFitType; pdfOptions.ZoomPercent = _pdfOptions.ZoomPercent; pdfOptions.InitialPageNumber = _pdfOptions.InitialPageNumber; pdfOptions.FitWindow = _pdfOptions.FitWindow; pdfOptions.CenterWindow = _pdfOptions.CenterWindow; pdfOptions.DisplayDocTitle = _pdfOptions.DisplayDocTitle; pdfOptions.HideMenubar = _pdfOptions.HideMenubar; pdfOptions.HideToolbar = _pdfOptions.HideToolbar; pdfOptions.HideWindowUI = _pdfOptions.HideWindowUI; } break; case DocumentFormat.Doc: // Update the DOC options { DocDocumentOptions docOptions = documentOptions as DocDocumentOptions; docOptions.TextMode = (_cbFramedDoc.Checked) ? DocumentTextMode.Framed : DocumentTextMode.NonFramed; } break; case DocumentFormat.Docx: // Update the DOC options { DocxDocumentOptions docxOptions = documentOptions as DocxDocumentOptions; docxOptions.TextMode = (_cbFramedDocX.Checked) ? DocumentTextMode.Framed : DocumentTextMode.NonFramed; } break; case DocumentFormat.Rtf: // Update the RTF options { RtfDocumentOptions rtfOptions = documentOptions as RtfDocumentOptions; rtfOptions.TextMode = (_cbFramedRtf.Checked) ? DocumentTextMode.Framed : DocumentTextMode.NonFramed; } break; case DocumentFormat.Html: // Update the HTML options { HtmlDocumentOptions htmlOptions = documentOptions as HtmlDocumentOptions; htmlOptions.FontEmbedMode = (DocumentFontEmbedMode)_htmlEmbedFontModeComboBox.SelectedItem; htmlOptions.UseBackgroundColor = _htmlUseBackgroundColorCheckBox.Checked; htmlOptions.BackgroundColor = MainForm.ConvertColor(_htmlBackgroundColorValueLabel.BackColor); } break; case DocumentFormat.Text: // Update the TEXT options { TextDocumentOptions textOptions = documentOptions as TextDocumentOptions; textOptions.DocumentType = (TextDocumentType)_textDocumentTypeComboBox.SelectedItem; textOptions.AddPageNumber = _textAddPageNumberCheckBox.Checked; textOptions.AddPageBreak = _textAddPageBreakCheckBox.Checked; textOptions.Formatted = _textFormattedCheckBox.Checked; } break; case DocumentFormat.AltoXml: // Update the ALTOXML options { AltoXmlDocumentOptions altoXmlOptions = documentOptions as AltoXmlDocumentOptions; altoXmlOptions.FileName = _altoXmlFileNameTextBox.Text; altoXmlOptions.SoftwareCreator = _altoXmlSoftwareCreatorTextBox.Text; altoXmlOptions.SoftwareName = _altoXmlSoftwareNameTextBox.Text; altoXmlOptions.ApplicationDescription = _altoXmlApplicationDescriptionTextBox.Text; altoXmlOptions.Formatted = _altoXmlFormattedCheckBox.Checked; altoXmlOptions.Indentation = (altoXmlOptions.Formatted) ? _altoXmlIndentationTextBox.Text : ""; altoXmlOptions.Sort = _altoXmlSort.Checked; altoXmlOptions.PlainText = _altoXmlPlainText.Checked; altoXmlOptions.ShowGlyphInfo = _altoXmlShowGlyphInfo.Checked; altoXmlOptions.ShowGlyphVariants = _altoXmlShowGlyphVariants.Checked; altoXmlOptions.MeasurementUnit = (AltoXmlMeasurementUnit)_altoXmlMeasurementUnit.SelectedItem; } break; case DocumentFormat.Ltd: case DocumentFormat.Emf: case DocumentFormat.Xls: case DocumentFormat.Pub: case DocumentFormat.Mob: case DocumentFormat.Svg: default: // These formats have no options break; } if (documentOptions != null) { docWriter.SetOptions(mf.Format, documentOptions); } // Get the save paramters _selectedFileName = _fileNameTextBox.Text; _selectedFormat = mf.Format; _selectedViewDocument = _viewDocumentCheckBox.Checked; if (_isCustomFileName) { _outputDir = Path.GetDirectoryName(SelectedFileName); } }
public void SetDocumentWriter(DocumentWriter docWriter, bool showLtdFormat) { _documentWriter = docWriter; // This is the order of importance, show these first then the rest as they come along DocumentFormat[] importantFormats = { DocumentFormat.Pdf, DocumentFormat.Docx, DocumentFormat.Rtf, DocumentFormat.Text, DocumentFormat.Doc, DocumentFormat.Xls, DocumentFormat.Html }; List <DocumentFormat> formatsToAdd = new List <DocumentFormat>(); Array a = Enum.GetValues(typeof(DocumentFormat)); List <DocumentFormat> allFormats = new List <DocumentFormat>(); foreach (DocumentFormat format in a) { allFormats.Add(format); } // Add important once first: foreach (DocumentFormat format in importantFormats) { formatsToAdd.Add(format); allFormats.Remove(format); } // Add rest formatsToAdd.AddRange(allFormats); // Add rest foreach (DocumentFormat format in formatsToAdd) { bool addItem = true; if (format == DocumentFormat.User) { addItem = false; } else if (format == DocumentFormat.Ltd && !showLtdFormat) { addItem = false; } if (addItem) { string name = string.Format("{0} ({1})", DocumentWriter.GetFormatFriendlyName(format), DocumentWriter.GetFormatFileExtension(format).ToUpperInvariant()); DocumentFormatItem item = new DocumentFormatItem(format, name); _formatComboBox.Items.Add(item); if (format == DocumentFormat.Pdf) { _formatComboBox.SelectedItem = item; } } } if (_formatComboBox.SelectedIndex == -1 && _formatComboBox.Items.Count > 0) { _formatComboBox.SelectedIndex = 0; } PdfDocumentOptions pdfOptions = _documentWriter.GetOptions(DocumentFormat.Pdf) as PdfDocumentOptions; if (string.IsNullOrEmpty(pdfOptions.Creator)) { pdfOptions.Creator = "LEADTOOLS PDFWriter"; } if (string.IsNullOrEmpty(pdfOptions.Producer)) { pdfOptions.Producer = "LEAD Technologies, Inc."; } _documentWriter.SetOptions(DocumentFormat.Pdf, pdfOptions); }
private void _okButton_Click(object sender, EventArgs e) { DocumentOptions options = _documentWriter.GetOptions(_format); switch (_format) { case DocumentFormat.Pdf: // Update the PDF options { PdfDocumentOptions pdfOptions = options as PdfDocumentOptions; pdfOptions.DocumentType = (PdfDocumentType)_pdfDocumentTypeComboBox.SelectedItem; pdfOptions.ImageOverText = _pdfImageOverTextCheckBox.Checked; pdfOptions.Linearized = _pdfLinearizedCheckBox.Checked; pdfOptions.FontEmbedMode = _pdfOptions.FontEmbedMode; pdfOptions.Linearized = _pdfOptions.Linearized; pdfOptions.Title = _pdfOptions.Title; pdfOptions.Subject = _pdfOptions.Subject; pdfOptions.Keywords = _pdfOptions.Keywords; pdfOptions.Author = _pdfOptions.Author; pdfOptions.Creator = _pdfOptions.Creator; pdfOptions.Producer = _pdfOptions.Producer; pdfOptions.PageRestriction = DocumentPageRestriction.Relaxed; pdfOptions.Protected = _pdfOptions.Protected; if (pdfOptions.Protected) { pdfOptions.UserPassword = _pdfOptions.UserPassword; pdfOptions.OwnerPassword = _pdfOptions.OwnerPassword; pdfOptions.EncryptionMode = _pdfOptions.EncryptionMode; pdfOptions.PrintEnabled = _pdfOptions.PrintEnabled; pdfOptions.HighQualityPrintEnabled = _pdfOptions.HighQualityPrintEnabled; pdfOptions.CopyEnabled = _pdfOptions.CopyEnabled; pdfOptions.EditEnabled = _pdfOptions.EditEnabled; pdfOptions.AnnotationsEnabled = _pdfOptions.AnnotationsEnabled; pdfOptions.AssemblyEnabled = _pdfOptions.AssemblyEnabled; } // Compression options pdfOptions.OneBitImageCompression = _pdfOptions.OneBitImageCompression; pdfOptions.ColoredImageCompression = _pdfOptions.ColoredImageCompression; pdfOptions.QualityFactor = _pdfOptions.QualityFactor; pdfOptions.ImageOverTextSize = _pdfOptions.ImageOverTextSize; pdfOptions.ImageOverTextMode = _pdfOptions.ImageOverTextMode; // Linearized pdfOptions.Linearized = _pdfOptions.Linearized; // Initial View Options pdfOptions.PageModeType = _pdfOptions.PageModeType; pdfOptions.PageLayoutType = _pdfOptions.PageLayoutType; pdfOptions.PageFitType = _pdfOptions.PageFitType; pdfOptions.ZoomPercent = _pdfOptions.ZoomPercent; pdfOptions.InitialPageNumber = _pdfOptions.InitialPageNumber; pdfOptions.FitWindow = _pdfOptions.FitWindow; pdfOptions.CenterWindow = _pdfOptions.CenterWindow; pdfOptions.DisplayDocTitle = _pdfOptions.DisplayDocTitle; pdfOptions.HideMenubar = _pdfOptions.HideMenubar; pdfOptions.HideToolbar = _pdfOptions.HideToolbar; pdfOptions.HideWindowUI = _pdfOptions.HideWindowUI; } break; case DocumentFormat.Doc: // Update the DOC options { DocDocumentOptions docOptions = options as DocDocumentOptions; docOptions.TextMode = (_docFramedCheckBox.Checked) ? DocumentTextMode.Framed : DocumentTextMode.NonFramed; } break; case DocumentFormat.Docx: // Update the DOCX options { DocxDocumentOptions docxOptions = options as DocxDocumentOptions; docxOptions.TextMode = (_docxFramedCheckBox.Checked) ? DocumentTextMode.Framed : DocumentTextMode.NonFramed; } break; case DocumentFormat.Rtf: // Update the RTF options { RtfDocumentOptions rtfOptions = options as RtfDocumentOptions; rtfOptions.TextMode = (_rtfFramedCheckBox.Checked) ? DocumentTextMode.Framed : DocumentTextMode.NonFramed; } break; case DocumentFormat.Html: // Update the HTML options { HtmlDocumentOptions htmlOptions = options as HtmlDocumentOptions; htmlOptions.FontEmbedMode = (DocumentFontEmbedMode)_htmlEmbedFontModeComboBox.SelectedItem; htmlOptions.UseBackgroundColor = _htmlUseBackgroundColorCheckBox.Checked; htmlOptions.BackgroundColor = Leadtools.Demos.Converters.FromGdiPlusColor(_htmlBackgroundColorValueLabel.BackColor); } break; case DocumentFormat.Text: // Update the TEXT options { TextDocumentOptions textOptions = options as TextDocumentOptions; textOptions.DocumentType = (TextDocumentType)_textDocumentTypeComboBox.SelectedItem; textOptions.AddPageNumber = _textAddPageNumberCheckBox.Checked; textOptions.AddPageBreak = _textAddPageBreakCheckBox.Checked; textOptions.Formatted = _textFormattedCheckBox.Checked; } break; case DocumentFormat.AltoXml: // Update the ALTOXML options { AltoXmlDocumentOptions altoXmlOptions = options as AltoXmlDocumentOptions; altoXmlOptions.MeasurementUnit = (AltoXmlMeasurementUnit)_altoXmlMeasurementUnitComboBox.SelectedItem; altoXmlOptions.FileName = _altoXmlFileNameTextBox.Text; altoXmlOptions.SoftwareCreator = _altoXmlSoftwareCreatorTextBox.Text; altoXmlOptions.SoftwareName = _altoXmlSoftwareNameTextBox.Text; altoXmlOptions.ApplicationDescription = _altoXmlApplicationDescriptionTextBox.Text; altoXmlOptions.Formatted = _altoXmlFormattedCheckBox.Checked; altoXmlOptions.Indentation = _altoXmlIndentationTextBox.Text; altoXmlOptions.Sort = _altoXmlSortCheckBox.Checked; altoXmlOptions.PlainText = _altoXmlPlainTextCheckBox.Checked; altoXmlOptions.ShowGlyphInfo = _altoXmlShowGlyphInfoCheckBox.Checked; altoXmlOptions.ShowGlyphVariants = _altoXmlShowGlyphVariantsCheckBox.Checked; } break; case DocumentFormat.Ltd: case DocumentFormat.Emf: default: // These formats have no options break; } if (options != null) { _documentWriter.SetOptions(_format, options); } }
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); }
public void UpdateDocumentWriterOptions() { // Save the options DocumentFormat format = this.SelectedDocumentFormat; Properties.Settings settings = new Properties.Settings(); settings.Format = format.ToString(); // Update the options DocumentOptions documentOptions = _docWriter.GetOptions(format); switch (format) { case DocumentFormat.Pdf: // Update the PDF options { PdfDocumentOptions pdfOptions = documentOptions as PdfDocumentOptions; pdfOptions.DocumentType = (PdfDocumentType)_pdfDocumentTypeComboBox.SelectedItem; pdfOptions.ImageOverText = _pdfImageOverTextCheckBox.Checked; pdfOptions.Linearized = _pdfLinearizedCheckBox.Checked; pdfOptions.PageRestriction = DocumentPageRestriction.Relaxed; // Description options pdfOptions.Title = _pdfOptions.Title; pdfOptions.Subject = _pdfOptions.Subject; pdfOptions.Keywords = _pdfOptions.Keywords; pdfOptions.Author = _pdfOptions.Author; pdfOptions.Creator = _pdfOptions.Creator; pdfOptions.Producer = _pdfOptions.Producer; // Fonts options pdfOptions.FontEmbedMode = _pdfOptions.FontEmbedMode; pdfOptions.Linearized = _pdfOptions.Linearized; // Security options pdfOptions.Protected = _pdfOptions.Protected; if (pdfOptions.Protected) { pdfOptions.UserPassword = _pdfOptions.UserPassword; pdfOptions.OwnerPassword = _pdfOptions.OwnerPassword; pdfOptions.EncryptionMode = _pdfOptions.EncryptionMode; pdfOptions.PrintEnabled = _pdfOptions.PrintEnabled; pdfOptions.HighQualityPrintEnabled = _pdfOptions.HighQualityPrintEnabled; pdfOptions.CopyEnabled = _pdfOptions.CopyEnabled; pdfOptions.EditEnabled = _pdfOptions.EditEnabled; pdfOptions.AnnotationsEnabled = _pdfOptions.AnnotationsEnabled; pdfOptions.AssemblyEnabled = _pdfOptions.AssemblyEnabled; } // Compression options pdfOptions.OneBitImageCompression = _pdfOptions.OneBitImageCompression; pdfOptions.ColoredImageCompression = _pdfOptions.ColoredImageCompression; pdfOptions.QualityFactor = _pdfOptions.QualityFactor; pdfOptions.ImageOverTextSize = _pdfOptions.ImageOverTextSize; pdfOptions.ImageOverTextMode = _pdfOptions.ImageOverTextMode; // Initial View Options pdfOptions.PageModeType = _pdfOptions.PageModeType; pdfOptions.PageLayoutType = _pdfOptions.PageLayoutType; pdfOptions.PageFitType = _pdfOptions.PageFitType; pdfOptions.ZoomPercent = _pdfOptions.ZoomPercent; pdfOptions.InitialPageNumber = _pdfOptions.InitialPageNumber; pdfOptions.FitWindow = _pdfOptions.FitWindow; pdfOptions.CenterWindow = _pdfOptions.CenterWindow; pdfOptions.DisplayDocTitle = _pdfOptions.DisplayDocTitle; pdfOptions.HideMenubar = _pdfOptions.HideMenubar; pdfOptions.HideToolbar = _pdfOptions.HideToolbar; pdfOptions.HideWindowUI = _pdfOptions.HideWindowUI; } break; case DocumentFormat.Doc: // Update the DOC options { DocDocumentOptions docOptions = documentOptions as DocDocumentOptions; docOptions.TextMode = (_cbFramedDoc.Checked) ? DocumentTextMode.Framed : DocumentTextMode.NonFramed; } break; case DocumentFormat.Docx: // Update the DOCX options { DocxDocumentOptions docxOptions = documentOptions as DocxDocumentOptions; docxOptions.TextMode = (_cbFramedDocX.Checked) ? DocumentTextMode.Framed : DocumentTextMode.NonFramed; } break; case DocumentFormat.Rtf: // Update the RTF options { RtfDocumentOptions rtfOptions = documentOptions as RtfDocumentOptions; rtfOptions.TextMode = (_cbFramedRtf.Checked) ? DocumentTextMode.Framed : DocumentTextMode.NonFramed; } break; case DocumentFormat.Html: // Update the HTML options { HtmlDocumentOptions htmlOptions = documentOptions as HtmlDocumentOptions; htmlOptions.FontEmbedMode = (DocumentFontEmbedMode)_htmlEmbedFontModeComboBox.SelectedItem; htmlOptions.UseBackgroundColor = _htmlUseBackgroundColorCheckBox.Checked; htmlOptions.BackgroundColor = ConvertColor(_htmlBackgroundColorValueLabel.BackColor); } break; case DocumentFormat.Text: // Update the TEXT options { TextDocumentOptions textOptions = documentOptions as TextDocumentOptions; textOptions.DocumentType = (TextDocumentType)_textDocumentTypeComboBox.SelectedItem; textOptions.AddPageNumber = _textAddPageNumberCheckBox.Checked; textOptions.AddPageBreak = _textAddPageBreakCheckBox.Checked; textOptions.Formatted = _textFormattedCheckBox.Checked; } break; case DocumentFormat.AltoXml: // Update the DOCX options { AltoXmlDocumentOptions altoXmlOptions = documentOptions as AltoXmlDocumentOptions; altoXmlOptions.FileName = _altoXmlFileNameTextBox.Text; altoXmlOptions.SoftwareCreator = _altoXmlSoftwareCreatorTextBox.Text; altoXmlOptions.SoftwareName = _altoXmlSoftwareNameTextBox.Text; altoXmlOptions.ApplicationDescription = _altoXmlApplicationDescriptionTextBox.Text; altoXmlOptions.Formatted = _altoXmlFormattedCheckBox.Checked; altoXmlOptions.Indentation = _altoXmlIndentationTextBox.Text; altoXmlOptions.Sort = _altoXmlSort.Checked; altoXmlOptions.PlainText = _altoXmlPlainText.Checked; altoXmlOptions.ShowGlyphInfo = _altoXmlShowGlyphInfo.Checked; altoXmlOptions.ShowGlyphVariants = _altoXmlShowGlyphVariants.Checked; altoXmlOptions.MeasurementUnit = (AltoXmlMeasurementUnit)_altoXmlMeasurementUnit.SelectedItem; } break; case DocumentFormat.Emf: case DocumentFormat.Xls: case DocumentFormat.Pub: case DocumentFormat.Mob: case DocumentFormat.Svg: default: // These formats have no options break; } if (documentOptions != null) { _docWriter.SetOptions(format, documentOptions); } using (MemoryStream ms = new MemoryStream()) { _docWriter.SaveOptions(ms); settings.FormatOptionsXml = Encoding.Unicode.GetString(ms.ToArray()); } settings.Save(); }