public bool Test() { try { ConverterSettingsFile settingsFile = new ConverterSettingsFile(); string filePath; var settings = new ConverterSettings(); DefaultSettingsLocatorHelper.EnsureDefaultSettingsFilePresent(out filePath, settings); settingsFile.Load(filePath); settingsFile.Settings.StandardVersion = _version; settingsFile.Settings.FB2ImportSettings.FixMode = FixOptions.UseFb2Fix; IFb2EPubConverterEngine converter = ConvertProcessor.CreateConverterEngine(settingsFile.Settings); var path = new StringBuilder(); path.AppendFormat(@"{0}\TestFiles\Test_001.fb2", Directory.GetCurrentDirectory()); converter.LoadAndCheckFB2Files(path.ToString()); string outPath = Path.GetTempPath(); converter.Save(outPath); } catch (Exception ex) { _lastException = ex; return(false); } return(true); }
public static T ConVal <T>(this object?initialValue, ConverterSettings settings) where T : struct { var value = ConVal(initialValue, typeof(T), settings); return(value == null ? default : (T)value); }
public void Init() { // MAKE SURE before you run this test, you MUST change the API key to yours; otherwise the test fails. this._settings = ConverterSettings.CreateInstance(); this._formats = new Formats(); this._wrapper = new ConverterWrapper(this._settings); this._input = new InputParameters() { InputFormat = this._formats.Website.Website, InputMethod = InputMethod.Url, Filepath = "http://www.google.com" }; this._output = new OutputParameters() { DownloadMethod = DownloadMethod.False, OutputStorage = OutputStorage.None, Wait = true }; this._conversion = new ConversionParameters() { OutputFormat = this._formats.Document.Pdf, ConverterOptions = null }; }
protected string ConvertVB(string program) { ConverterSettings settings = new ConverterSettings("prog.vb"); ApplySettings(settings); Module module = Parser.ParseModule(new CompileUnit(), new StringReader(program), settings); return GetStringFromModule(module, settings); }
public static (string title, string content) GetWord(SiteInfo siteInfo, bool isFirstLineTitle, bool isFirstLineRemove, bool isClearFormat, bool isFirstLineIndent, bool isClearFontSize, bool isClearFontFamily, bool isClearImages, string fileName) { var docsFilePath = PathUtils.GetTemporaryFilesPath(fileName); var imageDirectoryPath = PathUtility.GetUploadDirectoryPath(siteInfo, EUploadType.Image); var imageDirectoryUrl = PageUtility.GetSiteUrlByPhysicalPath(siteInfo, imageDirectoryPath, true); var settings = new ConverterSettings { IsFirstLineTitle = isFirstLineTitle, IsFirstLineRemove = isFirstLineRemove, IsClearFormat = isClearFormat, IsFirstLineIndent = isFirstLineIndent, IsClearFontSize = isClearFontSize, IsClearFontFamily = isClearFontFamily, IsClearImages = isClearImages, ImageDirectoryPath = imageDirectoryPath, ImageDirectoryUrl = imageDirectoryUrl, IsSaveHtml = false }; var(title, content) = ConvertToHtml(docsFilePath, settings); FileUtils.DeleteFileIfExists(docsFilePath); content = ContentUtility.TextEditorContentDecode(siteInfo, content, true); return(title, content); }
public void ToJson(FileInfo file, ConverterSettings settings) { string json = JsonConvert.SerializeObject(this, settings.JsonSettings); string fileName = file.DirectoryName + "/" + Path.GetFileNameWithoutExtension(file.FullName) + ".json"; File.WriteAllText(fileName, json); }
public static List <FileInfo> Expand(FileInfo file) { Metadata met = FromMeta(file); List <FileInfo> expandedfiles = new List <FileInfo>(); ConverterSettings settngs = new ConverterSettings(); for (int i = 0; i < met.ImcEntries.Count; i++) { string name = Path.GetFileNameWithoutExtension(file.FullName); FileInfo imcfile = new FileInfo(file.DirectoryName + "/" + name + "_imc_" + i); met.ImcEntries[i].ToImc(imcfile, settngs); expandedfiles.Add(imcfile); } /*foreach (KeyValuePair<XivRace, EquipmentDeformationParameter> entry in met.EqdpEntries) * { * } * * foreach (KeyValuePair<XivRace, ExtraSkeletonEntry> entry in met.EstEntries) * { * } * * GmpEntry; * EqpEntry; */ return(expandedfiles); }
public static ConverterSettings ApplySettings(string fileName, CompilerErrorCollection errors, CompilerWarningCollection warnings) { ConverterSettings settings = new ConverterSettings(fileName, errors, warnings); settings.SimplifyTypeNames = true; return(settings); }
public bool Test() { try { ConverterSettingsFile settingsFile = new ConverterSettingsFile(); string filePath; var settings = new ConverterSettings(); DefaultSettingsLocatorHelper.EnsureDefaultSettingsFilePresent(out filePath, settings); settingsFile.Load(filePath); settingsFile.Settings.StandardVersion = _version; settingsFile.Settings.FB2ImportSettings.FixMode = FixOptions.UseFb2Fix; IFb2EPubConverterEngine converter = ConvertProcessor.CreateConverterEngine(settingsFile.Settings); var path = new StringBuilder(); path.AppendFormat(@"{0}\TestFiles\Test_001.fb2", Directory.GetCurrentDirectory()); converter.LoadAndCheckFB2Files(path.ToString()); string outPath = Path.GetTempPath(); converter.Save(outPath); } catch (Exception ex) { _lastException = ex; return false; } return true; }
public void Init() { // MAKE SURE before you run this test, you MUST change the API key to yours; otherwise the test fails. this._settings = ConverterSettings.CreateInstance(); this._formats = new Formats(); this._wrapper = new ConverterWrapper(this._settings); this._input = new InputParameters() { InputFormat = this._formats.Document.Md, InputMethod = InputMethod.Download, Filepath = "https://raw.githubusercontent.com/aliencube/CloudConvert.NET/dev/README.md", Filename = "README.md", }; this._output = new OutputParameters() { DownloadMethod = DownloadMethod.False, OutputStorage = OutputStorage.OneDrive, }; this._conversion = new ConversionParameters() { OutputFormat = this._formats.Document.Docx, ConverterOptions = new MarkdownConverterOptions() { InputMarkdownSyntax = MarkdownSyntaxType.Auto }, }; }
ConverterSettings ApplySettings(string fileName, CompilerErrorCollection errors, CompilerWarningCollection warnings) { ConverterSettings settings = new ConverterSettings(fileName, errors, warnings); settings.SimplifyTypeNames = simplifyTypeNames; settings.RemoveRedundantTypeReferences = removeRedundantTypeReferences; return(settings); }
protected string ConvertVB(string program) { ConverterSettings settings = new ConverterSettings("prog.vb"); ApplySettings(settings); Module module = Parser.ParseModule(new CompileUnit(), new StringReader(program), settings); return(GetStringFromModule(module, settings)); }
public sealed override object Convert(object?value, ConverterSettings settings) { if (value == null) { throw new ArgumentNullException(nameof(value)); } return(Convert((T)value, settings)); }
public override string GenerateCode(AbstractNode node, string indentation) { StringBuilder errorBuilder = new StringBuilder(); ConverterSettings settings = new ConverterSettings("codegeneration.cs"); string output = null; Node booNode = (Node)node.AcceptVisitor(new ConvertVisitor(settings), null); if (settings.Errors.Count > 0) { foreach (CompilerError error in settings.Errors) { errorBuilder.AppendLine(error.ToString()); } } else { if (settings.Warnings.Count > 0) { foreach (CompilerWarning warning in settings.Warnings) { errorBuilder.AppendLine(warning.ToString()); } } booNode.Accept(new RemoveRedundantTypeReferencesVisitor()); using (StringWriter w = new StringWriter()) { BooPrinterVisitor printer = new BooPrinterVisitor(w); int indentCount = 0; foreach (char c in indentation) { if (c == '\t') { indentCount += 4; } else { indentCount += 1; } } indentCount /= 4; while (indentCount-- > 0) { printer.Indent(); } booNode.Accept(printer); output = w.ToString(); } } if (errorBuilder.Length > 0) { MessageService.ShowMessage(errorBuilder.ToString()); } return(output); }
protected void TestStatement(string input, string output) { ConverterSettings dummySet = new ConverterSettings("dummy.cs"); ApplySettings(dummySet); if (dummySet.RemoveRedundantTypeReferences) { TestInClass("public void Method() {\n" + input + "\n}", "public def Method():\n\t" + output.Replace("\n", "\n\t")); } else if (dummySet.SimplifyTypeNames) { TestInClass("public void Method() {\n" + input + "\n}", "public def Method() as void:\n\t" + output.Replace("\n", "\n\t")); } else { TestInClass("public void Method() {\n" + input + "\n}", "public def Method() as System.Void:\n\t" + output.Replace("\n", "\n\t")); } }
/// <summary> /// Builds the ConverterSettings object given by the xml element (XElement) /// </summary> /// <typeparam name="T">The type of object to create. In this case, it'll be ConverterSettings</typeparam> /// <param name="element">The xml node to generate the ConverterSettings object from</param> /// <returns>The generated convertersettings object</returns> protected override T OnBuildElement <T>(XElement element) { var name = XElementHelper.ReadStringValue(element, "name"); var friendlyName = XElementHelper.ReadStringValue(element, "friendlyName"); var defaultConfigurationFile = XElementHelper.ReadStringValue(element, "defaultConfigurationFile"); var additionalInformation = XElementHelper.ReadStringValue(element, "informationText", false); // Build game configuration models var sourceGameName = XElementHelper.ReadStringValue(element, "sourceGame"); var targetGameName = XElementHelper.ReadStringValue(element, "targetGame"); var sourceGame = GameConfigurations.FirstOrDefault(g => g.Name.Equals(sourceGameName)); var targetGame = GameConfigurations.FirstOrDefault(g => g.Name.Equals(targetGameName)); var requiredFolders = RequiredFolderFactory.BuildConfiguration <IRequiredFolder>(element); var requiredFiles = RequiredFileFactory.BuildConfiguration <IRequiredFile>(element); var errorMessage = "Could not find game configuration for {0}. Could not find game in " + AbsoluteGameConfigurationPath + " with name {1}. "; // Build preference categories var categories = PreferenceCategoryFactory.BuildModels <IPreferenceCategory>(defaultConfigurationFile); if (sourceGame == null) { EventAggregator.PublishOnUIThread( new LogEntry(string.Format(errorMessage, "source game", sourceGameName), LogEntrySeverity.Error, LogEntrySource.UI, AbsoluteGameConfigurationPath)); } if (targetGame == null) { EventAggregator.PublishOnUIThread( new LogEntry(string.Format(errorMessage, "target game", targetGameName), LogEntrySeverity.Error, LogEntrySource.UI, AbsoluteGameConfigurationPath)); } var settings = new ConverterSettings(EventAggregator) { Name = name, FriendlyName = friendlyName, DefaultConfigurationFile = Path.Combine(Environment.CurrentDirectory, defaultConfigurationFile), SourceGame = sourceGame, TargetGame = targetGame, Categories = categories, AdditionalInformation = additionalInformation }; requiredFolders.ForEach(f => settings.RequiredItems.Add(f)); requiredFiles.ForEach(f => settings.RequiredItems.Add(f)); return(settings as T); }
public void ToPNG(FileInfo file, ConverterSettings settings) { string fileName = file.DirectoryName + "/" + Path.GetFileNameWithoutExtension(file.FullName) + ".png"; PngEncoder encoder = new PngEncoder(); encoder.BitDepth = PngBitDepth.Bit16; Image img = Image.LoadPixelData <Rgba32>(this.pixelData, this.width, this.height); img.Save(fileName, encoder); img.Dispose(); }
public static async Task <(string title, string imageUrl, string body)> GetWordAsync(IPathManager pathManager, Site siteInfo, bool isFirstLineTitle, bool isClearFormat, bool isFirstLineIndent, bool isClearFontSize, bool isClearFontFamily, bool isClearImages, string docsFilePath, string docsFileTitle) { string imageDirectoryPath; string imageDirectoryUrl; if (siteInfo != null) { imageDirectoryPath = await pathManager.GetUploadDirectoryPathAsync(siteInfo, UploadType.Image); imageDirectoryUrl = await pathManager.GetSiteUrlByPhysicalPathAsync(siteInfo, imageDirectoryPath, true); } else { var fileName = PathUtils.GetFileName(docsFilePath); imageDirectoryPath = PathUtils.Combine(pathManager.WebRootPath, PathUtils.GetMaterialVirtualDirectoryPath(UploadType.Image)); imageDirectoryUrl = PathUtils.GetMaterialVirtualFilePath(UploadType.Image, fileName); } var settings = new ConverterSettings { IsFirstLineTitle = isFirstLineTitle, IsClearFormat = isClearFormat, IsFirstLineIndent = isFirstLineIndent, IsClearFontSize = isClearFontSize, IsClearFontFamily = isClearFontFamily, IsClearImages = isClearImages, ImageDirectoryPath = imageDirectoryPath, ImageDirectoryUrl = imageDirectoryUrl, IsSaveHtml = false }; var(title, imageUrl, body) = ConvertToHtml(docsFilePath, settings); FileUtils.DeleteFileIfExists(docsFilePath); if (siteInfo != null) { body = await pathManager.DecodeTextEditorAsync(siteInfo, body, true); } if (string.IsNullOrEmpty(title)) { title = docsFileTitle; } return(title, imageUrl, body); }
public void CreateDictionaryAndConvertItBackAndRespectDataContracts_Success(string resolverName) { // Set to default, because this is going to be ignored! dummy.String08 = nameof(DictionaryDummy.String08); dummy.String05 = nameof(DictionaryDummy.String05); var settings = new ConverterSettings { Resolver = GetResolver(resolverName) }; var dictionary = dummy.ToDictionary(settings); var expected = new Dictionary <string, object> { { nameof(DictionaryDummy.String01), "A" }, { nameof(DictionaryDummy.String02), nameof(DictionaryDummy.String02) }, { nameof(DictionaryDummy.String03), nameof(DictionaryDummy.String03) }, { "Custom" + nameof(DictionaryDummy.String04), "D" }, // { nameof(Dummy.String05), nameof(Dummy.String05) }, { nameof(DictionaryDummy.String06), "F" }, //{ nameof(Dummy.String07), nameof(Dummy.String07) }, // { nameof(Dummy.String08), nameof(Dummy.String08) }, { nameof(DictionaryDummy.Dict1), new Dictionary <string, object> { { "val1", 1 }, { "val2", "2" }, { "val3", true } } }, { nameof(DictionaryDummy.Dict2), new Dictionary <string, object> { { "val1", 1 }, { "val2", 2 }, { "val3", 3 } } }, { nameof(DictionaryDummy.Col1), new Dictionary <string, object> { { "0", 1 }, { "1", 2 }, { "2", 3 } } }, { nameof(DictionaryDummy.Col2), new Dictionary <string, object> { { "0", 1 }, { "1", 2 }, { "2", "3" }, { "3", true } } }, { nameof(DictionaryDummy.Vec3), new Dictionary <string, object> { { "X", 3f }, { "Y", 2f }, { "Z", 1f } } }, }; Assert.Equal(dictionary, expected, new DictionaryComparer <string, object>()); var result = dictionary.ToInstance <DictionaryDummy>(settings); Assert.Equal(dummy, result); var result2 = dictionary.ToInstance <DictionaryDummy>(settings); Assert.Equal(new Vector3(3, 2, 1), result2.Vec3); }
string GetStringFromModule(Module module, ConverterSettings settings) { if (settings.Errors.Count > 0) { Assert.Fail(settings.Errors.Count.ToString() + " errors: " + settings.Errors[0]); } if (settings.Warnings.Count > 0) { Assert.Fail(settings.Warnings.Count.ToString() + " warnings: " + settings.Warnings[0]); } Assert.IsNotNull(module, "Module is null"); string str = module.ToCodeString(); str = str.Trim().Replace("\r", ""); for (int i = 0; i < 5; i++) { str = str.Replace("\n\n", "\n"); str = str.Replace(" ", " "); } return str; }
public void ToDDS(FileInfo file, ConverterSettings settings) { List <byte> dds = new List <byte>(); dds.AddRange(DDS.CreateDDSHeader(this.textureFormat, (uint)this.width, (uint)this.height, this.mipMapCount, this.layers)); byte[] data = this.rawData; if (this.textureFormat == XivTexFormat.A8R8G8B8 && this.layers > 1) { data = ShiftLayers(data); } dds.AddRange(data); string fileName = file.DirectoryName + "/" + Path.GetFileNameWithoutExtension(file.FullName) + ".dds"; File.WriteAllBytes(fileName, dds.ToArray()); }
public void Test() { ConverterSettingsFile settingsFile = new ConverterSettingsFile(); string filePath; var settings = new ConverterSettings(); DefaultSettingsLocatorHelper.EnsureDefaultSettingsFilePresent(out filePath, settings); settingsFile.Load(filePath); settingsFile.Settings.StandardVersion = _version; settingsFile.Settings.FB2ImportSettings.FixMode = FixOptions.UseFb2Fix; settingsFile.Settings.V3Settings.FootnotesCreationMode = FootnotesGenerationMode.Combined; IFb2EPubConverterEngine converter = ConvertProcessor.CreateConverterEngine(settingsFile.Settings); var path = new StringBuilder(); path.AppendFormat(@"{0}\TestFiles\Test_001.fb2", Directory.GetCurrentDirectory()); converter.LoadAndCheckFB2Files(path.ToString()); string outPath = Path.GetTempPath(); converter.Save(outPath); }
protected void TestStatement(string input, string output) { ConverterSettings dummySet = new ConverterSettings("dummy.cs"); ApplySettings(dummySet); if (dummySet.RemoveRedundantTypeReferences) { TestInClass("public void Method() {\n" + input + "\n}", "public def Method():\n\t" + output.Replace("\n", "\n\t")); } else if (dummySet.SimplifyTypeNames) { TestInClass("public void Method() {\n" + input + "\n}", "public def Method() as void:\n\t" + output.Replace("\n", "\n\t")); } else { TestInClass("public void Method() {\n" + input + "\n}", "public def Method() as System.Void:\n\t" + output.Replace("\n", "\n\t")); } }
string GetStringFromModule(Module module, ConverterSettings settings) { if (settings.Errors.Count > 0) { Assert.Fail(settings.Errors.Count.ToString() + " errors: " + settings.Errors[0]); } if (settings.Warnings.Count > 0) { Assert.Fail(settings.Warnings.Count.ToString() + " warnings: " + settings.Warnings[0]); } Assert.IsNotNull(module, "Module is null"); string str = module.ToCodeString(); str = str.Trim().Replace("\r", ""); for (int i = 0; i < 5; i++) { str = str.Replace("\n\n", "\n"); str = str.Replace(" ", " "); } return(str); }
static async Task Main() { var builder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()); builder.SetupAppSettingsAndLogging(); var config = builder.Build(); var logger = config.SetupSerilog(); string inPdfPath = $"{Directory.GetCurrentDirectory()}\\BlackRectanglesWithSomeText.pdf"; var workingDir = Directory.CreateDirectory("output"); var converterSettings = new ConverterSettings { Pdf2SwfExecutableFilePath = ConverterHelper.SetupPdf2SwfNativeExeFromEmbeddedResources() }; var gs = PdfProcessorHelper.SetupGhostScriptFromEmbeddedResources(); var pdfProcesserSettings = new PdfProcessorSettings { SearchForGhosts = false, GhostScriptDllPath = gs.GhostScriptDllPath, GhostScriptVersion = gs.GhostScriptVersion }; var converter = new Converter(converterSettings, new PdfProcessorHelper(pdfProcesserSettings), logger); var status = await converter.ConvertPdf2Swf(inPdfPath, new ConversionOptions { HowToConvert = ConversionPath.Both, OutputDirectory = workingDir.FullName, OverwriteExistingSwfs = true }); logger.LogWarning($"Result is {status.State}"); System.Console.ReadKey(); }
private void OnExtractClick(object sender, RoutedEventArgs e) { FileInfo modPackFile = new FileInfo(this.PathBox.Text); DirectoryInfo outputdirectory = new DirectoryInfo(this.OutputBox.Text); ConverterSettings settings = new ConverterSettings { TextureFormat = ConverterSettings.TextureFormats.Png }; Task.Run(() => { List <FileInfo> files = Extractor.Extract(modPackFile, outputdirectory); foreach (FileInfo extractedFile in files) { ResourceConverter.Convert(extractedFile, settings); } System.Windows.MessageBox.Show("Done!", "Extract Successful"); }); }
public static void Main(string[] args) { if (args.Length <= 0) { Console.WriteLine("You must provide the path to a file to extract"); return; } string path = args[0]; Console.WriteLine("Running extractor on file: " + path); FileInfo inputModPack = new FileInfo(path); string outputDirPath = Path.GetFileNameWithoutExtension(inputModPack.Name) + "/"; DirectoryInfo outputDirectory = new DirectoryInfo(outputDirPath); if (outputDirectory.Exists) { outputDirectory.Delete(true); } outputDirectory.Create(); List <FileInfo> files = Extractor.Extract(inputModPack, outputDirectory); ConverterSettings settings = new ConverterSettings(); settings.TextureFormat = ConverterSettings.TextureFormats.Png; foreach (FileInfo extractedFile in files) { ResourceConverter.Convert(extractedFile, settings); } Console.WriteLine("Extraction complete"); Console.ReadKey(); }
public void Init() { this._settings = ConverterSettings.CreateInstance(); }
static void Main(string[] args) { // Activate Gnostice product Framework.ActivateLicense("4AF4-263D-70A5-F5C8-57E6-045C-ED92-5369"); // Instantiate DocumentConverter DocumentConverter docConverter = new DocumentConverter(); // Subscribe to Error event docConverter.Error += docConverter_Error; // Input Directory string inputPath = @"../../../../../03. Sample Files/"; // Output Directory string outputPath = @"../../../../../04. Output/"; // Output Format string outputFormat = "txt"; // List of files as input for the document Converter List<string> inputFiles = Directory.GetFiles(inputPath).ToList(); // Single input file string inputFile = inputPath + "input.docx"; // Single output file string outputFile = outputPath + "output." + outputFormat; #region Simple Conversion // Converting sample input file to TXT format docConverter.ConvertToFile(inputFile, outputFile); #endregion // public List<string> ConvertToFile( // object input, => accepts string (file name) or Stream (file stream) or List<string> or List<Stream> // string outputFileFormat, => expected output file format // string outputDir, => directory in which the output files are to be stored // string baseFileName = "", => name of the output converted file // ConversionMode conversionmode, => ConversionMode.ConvertToSeparateFiles to create a separated file for each converted input file // ConverterSettings converterSettings = null, => specifiy the range of pages to be converted // EncoderSettings encoderSettings = null, => set the information for encoding the document // string inputDocPassword = "" => password for the input document // ); #region One to One Conversion // Converts all //ConversionMode.ConvertToSeparateFiles=>Many to many conversion //Convert list of files in inputFiles into a single output file by specifying Conversion mode as ConversionMode.ConvertToSeperateFiles docConverter.ConvertToFile(inputFiles, outputFormat, outputPath, "ConvertToTXT_OneToOne_Multiple", ConversionMode.ConvertToSeperateFiles); #endregion #region Convert to single file //ConversionMode.ConverToSingleFile => Convert all the input files and merge it to a single file //Converts list of files in inputFiles into a single output file by specifying Conversion mode as ConversionMode.ConvertToSingleFile docConverter.ConvertToFile(inputFiles, outputFormat, outputPath, "ConvertToTXT_ManyToOne", ConversionMode.ConvertToSingleFile); #endregion #region Converting file using ConverterSettings // Instantiate ConverterSettings ConverterSettings cp = new ConverterSettings(); // Converter Parameter : PageRange // 4 different types of page ranges // PageRange.All => Converts all pages in input file // PageRange.Even => Converts Pages with even page number // PageRange.Odd => Converts Pages with odd page number // PageRange.Custom => Converts set of pages from input file. ** page range should be specified in CustomPageRange // Convert all even pages in input file cp.PageRange = PageRange.Even; docConverter.ConvertToFile(inputFile, outputFormat, outputPath, "ConvertToTXT_WithConverterSettings_Even", ConversionMode.ConvertToSeperateFiles, null, cp); // Convert specific pages from input file, say one needs to convert pages 1,4,8,9,10,11,12 from input file cp.PageRange = PageRange.Custom; cp.CustomPageRange = "1,4,8-12"; // **PageRange should be set to PageRange.Custom docConverter.ConvertToFile(inputFile, outputFormat, outputPath, "ConvertToTXT_WithConverterSettings_Custom", ConversionMode.ConvertToSeperateFiles, null, cp); #endregion #region TXT Encoder Parameters // For encoding file into TXT textEncoderParams have to be specified TextEncoderSettings txtEncoderParams = new TextEncoderSettings(); txtEncoderParams.ByteOrderMarkBytes = new byte[0]; // Types of file Encoding Files 'FileEncoding' // FileEncoding.ISO_8859_1=> encoding files in ISO 8859-1 // FileEncoding.US_ASCII=>Encoding files in US ASCII // FileEncoding.UTF_16BE=> Encoding files in UTF 16BE // FileEncoding.UTF_16LE=> Encoding files in UTF 16LE // FileEncoding.UTF_8=> Encoding files in UTF 8 (default file encoding) txtEncoderParams.FileEncoding = FileEncoding.UTF_8; // 6 members of TextFormatter // TextFormatter.BreakLines=> break point at every line // TextFormatter.BreakPages=>break point at every page // TextFormatter.BreakParagraphs=>break point at every paragraph // TextFormatter.CustomPageBreak=>to enable cutom break point // TextFormatter.CustomPageBreakText=>set the custom break point // TextFormatter.FILE_SEPARATOR_CHAR=>set the file separator character // TextFormatter.PageBreakText=>set the page break text // For setting break point to every line txtEncoderParams.TextFormatter.CustomPageBreak = true; txtEncoderParams.TextFormatter.CustomPageBreakText = "<<Page Break>>"; // txtEncoderParams.UseByteOrderMark=>to use byte order mark txtEncoderParams.UseByteOrderMark = true; docConverter.ConvertToFile(inputFile, "txt", outputPath, "ConvertToTXT_WithEncoderSettings", ConversionMode.ConvertToSeperateFiles, txtEncoderParams, cp); #endregion }
static void Main(string[] args) { // Activate Gnostice product Framework.ActivateLicense("4AF4-263D-70A5-F5C8-57E6-045C-ED92-5369"); // Instantiate DocumentConverter DocumentConverter docConverter = new DocumentConverter(); // Subscribe to Error event docConverter.Error += docConverter_Error; // Input Directory string inputPath = @"../../../../../03. Sample Files/"; // Output Directory string outputPath = @"../../../../../04. Output/"; // Output Format string outputFormat = "docx"; // List of files as input for the document Converter List<string> inputFiles = Directory.GetFiles(inputPath).ToList(); // Single input file string inputFile = inputPath + "input.pdf"; // Single output file string outputFile = outputPath + "output." + outputFormat; #region Simple Conversion // Converting sample input file to DOCX format docConverter.ConvertToFile(inputFile, outputFile); #endregion // public List<string> ConvertToFile( // object input, => accepts string (file name) or Stream (file stream) or List<string> or List<Stream> // string outputFileFormat, => expected output file format // string outputDir, => directory in which the output files are to be stored // string baseFileName = "", => name of the output converted file // ConversionMode conversionmode, => ConversionMode.ConvertToSeparateFiles to create a separated file for each converted input file // ConverterSettings converterSettings = null, => specifiy the range of pages to be converted // EncoderSettings encoderSettings = null, => set the information for encoding the document // string inputDocPassword = "" => password for the input document // ); #region One to One Conversion // Converts all //ConversionMode.ConvertToSeparateFiles=>Many to many conversion //Convert list of files in inputFiles into a single output file by specifying Conversion mode as ConversionMode.ConvertToSeperateFiles docConverter.ConvertToFile(inputFiles, outputFormat, outputPath, "ConvertToDOCX_OneToOne_Multiple", ConversionMode.ConvertToSeperateFiles); #endregion #region Convert to single file //ConversionMode.ConverToSingleFile => Convert all the input files and merge it to a single file //Converts list of files in inputFiles into a single output file by specifying Conversion mode as ConversionMode.ConvertToSingleFile docConverter.ConvertToFile(inputFiles, outputFormat, outputPath, "ConvertToDOCX_ManyToOne", ConversionMode.ConvertToSingleFile); #endregion #region Converting file using ConverterSettings // Instantiate ConverterSettings ConverterSettings cp = new ConverterSettings(); //Converter Parameter : PageRange //4 different types of page ranges //PageRange.All => Converts all pages in input file //PageRange.Even => Converts Pages with even page number //PageRange.Odd => Converts Pages with odd page number //PageRange.Custom => Converts set of pages from input file. ** page range should be specified in CustomPageRange // Convert all even pages in input file cp.PageRange = PageRange.Even; docConverter.ConvertToFile(inputFile, outputFormat, outputPath, "ConvertToDOCX_WithConverterSettings_Even", ConversionMode.ConvertToSeperateFiles, null, cp); // Convert specific pages from input file, say one need to convert 1,3,5,6,7,10 pages from input file cp.PageRange = PageRange.Custom; cp.CustomPageRange = "1,3,5-7,10"; // **PageRange should be set to PageRange.Custom docConverter.ConvertToFile(inputFile, outputFormat, outputPath, "ConvertToDOCX_WithConverterSettings_Custom", ConversionMode.ConvertToSeperateFiles, null, cp); #endregion }
static void Main(string[] args) { // Activate Gnostice product Framework.ActivateLicense("4AF4-263D-70A5-F5C8-57E6-045C-ED92-5369"); // Instantiate DocumentConverter DocumentConverter docConverter = new DocumentConverter(); // Subscribe to Error event docConverter.Error += docConverter_Error; // Input Directory string inputPath = @"../../../../../03. Sample Files/"; // Output Directory string outputPath = @"../../../../../04. Output/"; // Output Format string outputFormat = "jpg"; // List of files as input for the document Converter List<string> inputFiles = Directory.GetFiles(inputPath).ToList(); // Single input file string inputFile = inputPath + "input.docx"; // Single output file string outputFile = outputPath + "output." + outputFormat; #region Simple Conversion // Converting sample input file to JPEG format docConverter.ConvertToFile(inputFile, outputFile); #endregion // public List<string> ConvertToFile( // object input, => accepts string (file name) or Stream (file stream) or List<string> or List<Stream> // string outputFileFormat, => expected output file format // string outputDir, => directory in which the output files are to be stored // string baseFileName = "", => name of the output converted file // ConversionMode conversionmode, => ConversionMode.ConvertToSeparateFiles to create a separated file for each converted input file // ConverterSettings converterSettings = null, => specifiy the range of pages to be converted // EncoderSettings encoderSettings = null, => set the information for encoding the document // string inputDocPassword = "" => password for the input document // ); #region One to One Conversion // Converts all // ConversionMode.ConvertToSeparateFiles=>Many to many conversion // Convert list of files in inputFiles into a single output file by specifying Conversion mode as ConversionMode.ConvertToSeperateFiles docConverter.ConvertToFile(inputFiles, outputFormat, outputPath, "ConvertToJPEG_OneToOne_Multiple", ConversionMode.ConvertToSeperateFiles); #endregion #region Convert to single file //ConversionMode.ConverToSingleFile => Convert all the input files and merge it to a single file //Converts list of files in inputFiles into a single output file by specifying Conversion mode as ConversionMode.ConvertToSingleFile docConverter.ConvertToFile(inputFiles, outputFormat, outputPath, "ConvertToJPEG_ManyToOne", ConversionMode.ConvertToSingleFile); #endregion #region Converting file using ConverterSettings // Instantiate ConverterSettings ConverterSettings cp = new ConverterSettings(); //Converter Parameter : PageRange // 4 different types of page ranges // PageRange.All => Converts all pages in input file // PageRange.Even => Converts Pages with even page number // PageRange.Odd => Converts Pages with odd page number // PageRange.Custom => Converts set of pages from input file. ** page range should be specified in CustomPageRange // Convert all odd pages in input file cp.PageRange = PageRange.Odd; docConverter.ConvertToFile(inputFile, outputFormat, outputPath, "ConvertToJPEG_WithConverterSettings_Even", ConversionMode.ConvertToSeperateFiles, null, cp); // Convert specific pages from input file, say one need to convert 1,3,5,6,7,10 pages from input file cp.PageRange = PageRange.Custom; cp.CustomPageRange = "1,3,5-7,10"; // **PageRange should be set to PageRange.Custom docConverter.ConvertToFile(inputFile, outputFormat, outputPath, "ConvertToJPEG_WithConverterSettings_Custom", ConversionMode.ConvertToSeperateFiles, null, cp); #endregion #region JPEG encoder formats JPEGEncoderSettings jpegEncoderFormats = new JPEGEncoderSettings(); // Page Scaling // 2 modes // PageScaling.None // PageScalling.UseRenderingResolution jpegEncoderFormats.PageScalling = PageScalling.None; //Quality level in percentage of the quality of the original file jpegEncoderFormats.QualityLevel = 10; // Rendering Setting level // The compositing mode CompositingMode determines whether pixels from a source image overwrite or are combined with background pixels. // 2 compositing modes // CompositingMode.SourceOver => Specifies that when a color is rendered, it is blended with the background color. The blend is determined by the alpha component of the color being rendered. // Compositing.SourceCopy => Specifies that when a color is rendered, it overwrites the background color. jpegEncoderFormats.RenderingSettings.Image.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy; // The composition quality CompositingQuality sets the rendering quality of composited images drawn // 6 compositing quality types // CompositingQuality.AssumeLinear => Assume linear values // CompositingQuality.Default => Default quality // CompositingQuality.GammaCorrected => Use Gamma correction // CompositingQuality.HighQuality => High quality low speed compositing // CompositingQuality.HighSpeed => High speed low quality compositing // CompositingQuality.Invalid => Invalid quality jpegEncoderFormats.RenderingSettings.Image.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.Default; // The Interpolation mode sets the interpolation mode associated with this jpeg file // 9 Interpolation modes // InterpolationMode.Bicubic => Specifies bicubic interpolation. No prefiltering is done. This mode is not suitable for shrinking an image below 25 percent of its original size. // InterpolationMode.Bilinear => Specifies bilinear interpolation. No prefiltering is done. This mode is not suitable for shrinking an image below 50 percent of its original size. // InterpolationMode.Default => Specifies default mode. // InterpolationMode.High => Specifies high quality interpolation. // InterpolationMode.HighQualityBicubic => Specifies high-quality, bicubic interpolation. Prefiltering is performed to ensure high-quality shrinking. This mode produces the highest quality transformed images. // InterpolationMode.HighQualityBilinear => Specifies high-quality, bilinear interpolation. Prefiltering is performed to ensure high-quality shrinking. // InterpolationMode.Invalid => Equivalent to the Invalid element of the QualityMode enumeration. // InterpolationMode.Low => Specifies low quality interpolation. // InterpolationMode.NearestNeighbor => Specifies nearest-neighbor interpolation jpegEncoderFormats.RenderingSettings.Image.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Default; // The pixel offset mode sets a value specifying how pixels are offset during rendering of this jpeg file // 6 pixel offset modes // PixelOffsetMode.Half => Specifies that pixels are offset by -.5 units, both horizontally and vertically, for high speed antialiasing. // PixelOffsetMode.Default => Specifies the default mode // PixelOffsetMode.None => Specifies no pixel offset // PixelOffsetMode.HighQuality => High quality low speed rendering // PixelOffsetMode.HighSpeed => High speed low quality rendenring // PixelOffsetMode.Invalid => Specifies an invalid mode jpegEncoderFormats.RenderingSettings.Image.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Default; // The smoothing mode specifies whether lines, curves, and the edges of filled areas use smoothing (also called antialiasing) // 6 Line Smoothening modes for line art // SmoothingMode.AntiAlias => Specifies antialiased rendering. // SmoothingMode.Default => Specifies no antialiasing. // SmoothingMode.HighQuality => Specifies antialiased rendering. // SmoothingMode.HighSpeed => Specifies no antialiasing. // SmoothingMode.Invalid => Specifies an invalid mode. // SmoothingMode.None => Specifies no antialiasing. jpegEncoderFormats.RenderingSettings.LineArt.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.Default; //Text Contarst jpegEncoderFormats.RenderingSettings.Text.TextContrast = 5; // Text Rendering Hint // 6 types of text rendering hints // TextRenderingHint.SystemDefault => Each character is drawn using its glyph bitmap, with the system default rendering hint. The text will be drawn using whatever font-smoothing settings the user has selected for the system. // TextRenderingHint.AntiAlias => Each character is drawn using its antialiased glyph bitmap without hinting. Better quality due to antialiasing. Stem width differences may be noticeable because hinting is turned off. // TextRenderingHint.AntiAliasGridFit => Each character is drawn using its antialiased glyph bitmap with hinting. Much better quality due to antialiasing, but at a higher performance cost. // TextRenderingHint.ClearTypeGridFit => Each character is drawn using its glyph ClearType bitmap with hinting. The highest quality setting. Used to take advantage of ClearType font features. // TextRenderingHint.SingleBitPerPixelPerGridFit => Each character is drawn using its glyph bitmap. Hinting is used to improve character appearance on stems and curvature. // TextRenderingHint.SingleBitPerPixel => Each character is drawn using its glyph bitmap. Hinting is not used. jpegEncoderFormats.RenderingSettings.Text.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SystemDefault; // Rendering Settings resolution jpegEncoderFormats.RenderingSettings.Resolution.DPI = 96f; jpegEncoderFormats.RenderingSettings.Resolution.DpiX = 96f; jpegEncoderFormats.RenderingSettings.Resolution.DpiY = 69f; // Resolution Mode // 3 types of resolution modes // ResolutionMode.UseSource => use source resolution // ResolutionMode.UseDevice => use device resolution // ResolutionMode.UseSpecifiedDPI => use DPI specified in pngEncoderFormats.RenderingSettings.Resolution.DPI jpegEncoderFormats.RenderingSettings.Resolution.ResolutionMode = ResolutionMode.UseSource; // Resolution Settings jpegEncoderFormats.ResolutionSettings.DPI = 96f; jpegEncoderFormats.ResolutionSettings.DpiX = 96f; jpegEncoderFormats.ResolutionSettings.DpiY = 96f; // 3 types of resolution modes // ResolutionMode.UseSource => use source resolution // ResolutionMode.UseDevice => use device resolution // ResolutionMode.UseSpecifiedDPI => use DPI specified in pngEncoderFormats.RenderingSettings.Resolution.DPI jpegEncoderFormats.ResolutionSettings.ResolutionMode = ResolutionMode.UseSource; docConverter.ConvertToFile(inputFile, outputFormat, outputPath, "ConvertToJPEG_WithEncoderSettings", ConversionMode.ConvertToSingleFile, jpegEncoderFormats); #endregion }
protected virtual void ApplySettings(ConverterSettings settings) { settings.SimplifyTypeNames = false; settings.RemoveRedundantTypeReferences = false; }
protected virtual void ApplySettings(ConverterSettings settings) { settings.SimplifyTypeNames = false; settings.RemoveRedundantTypeReferences = false; }
static void Main(string[] args) { // Activate Gnostice product Framework.ActivateLicense("4AF4-263D-70A5-F5C8-57E6-045C-ED92-5369"); // Instantiate DocumentConverter DocumentConverter docConverter = new DocumentConverter(); // Subscribe to Error event docConverter.Error += docConverter_Error; // Input Directory string inputPath = @"../../../../../03. Sample Files/"; // Output Directory string outputPath = @"../../../../../04. Output/"; // Output Format string outputFormat = "html"; // List of files as input for the document Converter List <string> inputFiles = Directory.GetFiles(inputPath).ToList(); // Single input file string inputFile = inputPath + "input.docx"; // Single output file string outputFile = outputPath + "output." + outputFormat; #region Simple Conversion // Converting sample input file to HTML format docConverter.ConvertToFile(inputFile, outputFile); #endregion // public List<string> ConvertToFile( // object input, => accepts string (file name) or Stream (file stream) or List<string> or List<Stream> // string outputFileFormat, => expected output file format // string outputDir, => directory in which the output files are to be stored // string baseFileName = "", => name of the output converted file // ConversionMode conversionmode, => ConversionMode.ConvertToSeparateFiles to create a separated file for each converted input file // ConverterSettings converterSettings = null, => specifiy the range of pages to be converted // EncoderSettings encoderSettings = null, => set the information for encoding the document // string inputDocPassword = "" => password for the input document // ); #region One to One Conversion // Converts all // ConversionMode.ConvertToSeparateFiles=>Many to many conversion // Convert list of files in inputFiles into a single output file by specifying Conversion mode as ConversionMode.ConvertToSeperateFiles docConverter.ConvertToFile(inputFiles, outputFormat, outputPath, "ConvertToHTML_OneToOne_Multiple", ConversionMode.ConvertToSeperateFiles); #endregion #region Convert to single file // ConversionMode.ConverToSingleFile => Convert all the input files and merge it to a single file // Converts list of files in inputFiles into a single output file by specifying Conversion mode as ConversionMode.ConvertToSingleFile docConverter.ConvertToFile(inputFiles, outputFormat, outputPath, "ConvertToHTML_ManyToOne", ConversionMode.ConvertToSingleFile); #endregion #region Converting file using ConverterSettings // Instantiate ConverterSettings ConverterSettings cp = new ConverterSettings(); // Converter Parameter : PageRange // 4 different types of page ranges // PageRange.All => Converts all pages in input file // PageRange.Even => Converts Pages with even page number // PageRange.Odd => Converts Pages with odd page number // PageRange.Custom => Converts set of pages from input file. ** page range should be specified in CustomPageRange // Convert all even pages in input file cp.PageRange = PageRange.Even; docConverter.ConvertToFile(inputFile, outputFormat, outputPath, "ConvertToHTML_WithConverterSettings_Even", ConversionMode.ConvertToSeperateFiles, null, cp); // Convert specific pages from input file, say one need to convert 1,3,5,6,7,10 pages from input file cp.PageRange = PageRange.Custom; cp.CustomPageRange = "1,3,5-7,10"; // **PageRange should be set to PageRange.Custom docConverter.ConvertToFile(inputFile, outputFormat, outputPath, "ConvertToHTML_WithConverterSettings_Custom", ConversionMode.ConvertToSeperateFiles, null, cp); #endregion }
/// <summary> /// Builds the ConverterSettings object given by the xml element (XElement) /// </summary> /// <typeparam name="T">The type of object to create. In this case, it'll be ConverterSettings</typeparam> /// <param name="element">The xml node to generate the ConverterSettings object from</param> /// <returns>The generated convertersettings object</returns> protected override T OnBuildElement <T>(XElement element) { var name = XElementHelper.ReadStringValue(element, "name"); var friendlyName = XElementHelper.ReadStringValue(element, "friendlyName"); var defaultConfigurationFile = XElementHelper.ReadStringValue(element, "defaultConfigurationFile"); //var converterExeName = XElementHelper.ReadStringValue(element, "converterExeName"); //var userConfigurationFile = XElementHelper.ReadStringValue(element, "userConfigurationFile"); var additionalInformation = XElementHelper.ReadStringValue(element, "informationText", false); // Build game configuration models var sourceGameName = XElementHelper.ReadStringValue(element, "sourceGame"); var targetGameName = XElementHelper.ReadStringValue(element, "targetGame"); var sourceGame = GameConfigurations.FirstOrDefault(g => g.Name.Equals(sourceGameName)); var targetGame = GameConfigurations.FirstOrDefault(g => g.Name.Equals(targetGameName)); var requiredFolders = RequiredFolderFactory.BuildConfiguration <IRequiredFolder>(element); var requiredFiles = RequiredFileFactory.BuildConfiguration <IRequiredFile>(element); // Native export directory. //var nativeExportDirectory = XElementHelper.ReadStringValue(element, "nativeParadoxExportDirectory", false); //var nativeParadoxExportDirectoryLocationTypeAsString = XElementHelper.ReadStringValue(element, "nativeParadoxExportDirectoryLocationType", false); //var nativeParadoxExportDirectoryLocationType = nativeParadoxExportDirectoryLocationTypeAsString.Equals(RelativeFolderLocationRoot.SteamFolder.ToString()) ? RelativeFolderLocationRoot.SteamFolder : RelativeFolderLocationRoot.WindowsUsersFolder; //string nativeExportDirectoryTag = XElementHelper.ReadStringValue(element, "nativeParadoxExportDirectoryTag", false); //string nativeExportDirectoryAbsolutePath = string.Empty; //if (nativeParadoxExportDirectoryLocationType.Equals(RelativeFolderLocationRoot.WindowsUsersFolder)) //{ // nativeExportDirectoryAbsolutePath = DirectoryHelper.GetUsersFolder() + XElementHelper.ReadStringValue(element, "nativeParadoxExportDirectory", false); //} //else //{ // //HACK: This is bad, and needs fixing. // throw new NotSupportedException("The native export directory cannot be a steam subfolder."); //} var errorMessage = "Could not find game configuration for {0}. Could not find game in " + AbsoluteGameConfigurationPath + " with name {1}. "; // Build preference categories var categories = PreferenceCategoryFactory.BuildModels <IPreferenceCategory>(defaultConfigurationFile); if (sourceGame == null) { EventAggregator.PublishOnUIThread( new LogEntry(string.Format(errorMessage, "source game", sourceGameName), LogEntrySeverity.Error, LogEntrySource.UI, AbsoluteGameConfigurationPath)); } if (targetGame == null) { EventAggregator.PublishOnUIThread( new LogEntry(string.Format(errorMessage, "target game", targetGameName), LogEntrySeverity.Error, LogEntrySource.UI, AbsoluteGameConfigurationPath)); } //var relativeConverterPath = XElementHelper.ReadStringValue(element, "subfolderName"); var settings = new ConverterSettings(EventAggregator) { Name = name, FriendlyName = friendlyName, DefaultConfigurationFile = Path.Combine(Environment.CurrentDirectory, defaultConfigurationFile), //ConverterExeName = converterExeName, SourceGame = sourceGame, TargetGame = targetGame, //AbsoluteConverterPath = Path.Combine(Environment.CurrentDirectory, relativeConverterPath), /*NativeParadoxExportDirectoryTag = nativeExportDirectoryTag, * NativeParadoxExportDirectory = nativeExportDirectoryAbsolutePath,*/ //UserConfigurationFile = userConfigurationFile Categories = categories, AdditionalInformation = additionalInformation }; requiredFolders.ForEach(f => settings.RequiredItems.Add(f)); requiredFiles.ForEach(f => settings.RequiredItems.Add(f)); return(settings as T); }
static void Main(string[] args) { // Activate Gnostice product Framework.ActivateLicense("4AF4-263D-70A5-F5C8-57E6-045C-ED92-5369"); // Instantiate DocumentConverter DocumentConverter docConverter = new DocumentConverter(); // Subscribe to Error event docConverter.Error += docConverter_Error; // Input Directory string inputPath = @"../../../../../03. Sample Files/"; // Output Directory string outputPath = @"../../../../../04. Output/"; // Output Format string outputFormat = "pdf"; // List of files as input for the document Converter List<string> inputFiles = Directory.GetFiles(inputPath).ToList(); // public List<string> ConvertToFile( // object input, => accepts string (file name) or Stream (file stream) or List<string> or List<Stream> // string outputFileFormat, => expected output file format // string outputDir, => directory in which the output files are to be stored // string baseFileName = "", => name of the output converted file // ConversionMode conversionmode, => ConversionMode.ConvertToSeparateFiles to create a separated file for each converted input file // ConverterSettings converterSettings = null, => specifiy the range of pages to be converted // EncoderSettings encoderSettings = null, => set the information for encoding the document // string inputDocPassword = "" => password for the input document // ); #region PDF Encoder Settings // For encoding into PDF portfolios files PdfEncoderParams have to be specified PDFEncoderSettings pdfEncoderParams = new PDFEncoderSettings(); // 3 conditions of creating PDF portfolio // PortfolioCreationMode.Always => Always creates a portfolio // PortfolioCreationMode.Off => Does not create a portfolio // PortfolioCreationMode.OnlyWhenAttachmentsExist => Creates a portfolio only when there is more than one document // PortfolioCreationMode.WhenInputIsPortfolio => creates a portfolio when the input is a portfolio pdfEncoderParams.PDFPortfolioSettings.PortfolioCreationMode = PortfolioCreationMode.Always; // 3 views of the PDF portfolio // PortfolioLayoutMode.Details => Shows the details of the various files in the portfolio // PortfolioLayoutMode.Hide => Hides the details of the various files in the portfolio // PortfolioLayoutMode.Tile => Dispays the attached documents in the form of tiles pdfEncoderParams.PDFPortfolioSettings.PortfolioLayoutMode = PortfolioLayoutMode.Tile; #endregion #region Covert first file and attach remaining in their original forms // ConversionMode.ConvertFirstFileAndAttachRestAsOriginal => Converts first file and attaches remaining as originals docConverter.ConvertToFile(inputFiles, outputFormat, outputPath, "ConvertToPDFPortfolio_ConvertFirstFileAndAttachRestAsOriginal", ConversionMode.CreateNewFileAndAttachAllAsOriginal, pdfEncoderParams); #endregion #region Attach all originals //ConversionMode.ConverToSingleFile =>creates a new file and attaches all files in their original form without converting any file docConverter.ConvertToFile(inputFiles, outputFormat, outputPath, "ConvertToPDFPortfolio_CreateNewFileAndAttachAllAsOriginal", ConversionMode.CreateNewFileAndAttachAllAsOriginal, pdfEncoderParams); #endregion #region Converting file using ConverterSettings // Instantiate ConverterSettings ConverterSettings cp = new ConverterSettings(); // Converter Parameter : PageRange // 4 different types of page ranges // PageRange.All => Converts all pages in first input file // PageRange.Even => Converts Pages with even page number in the first input file // PageRange.Odd => Converts Pages with odd page number in the first input file // PageRange.Custom => Converts set of pages from first input file. ** page range should be specified in CustomPageRange // Convert all even pages in first input file cp.PageRange = PageRange.Even; docConverter.ConvertToFile(inputFiles, outputFormat, outputPath, "ConvertToPDFPortfolio_WithConverterSettings_Even", ConversionMode.ConvertFirstFileAndAttachRestAsOriginal, pdfEncoderParams, cp); // Convert specific pages from input file, say one need to convert 1,3,5,6,7,10 pages from input file cp.PageRange = PageRange.Custom; cp.CustomPageRange = "1,3,5-7,10"; // **PageRange should be set to PageRange.Custom docConverter.ConvertToFile(inputFiles, outputFormat, outputPath, "ConvertToPDFPortfolio_WithConverterSettings_Custom", ConversionMode.ConvertFirstFileAndAttachRestAsOriginal, pdfEncoderParams, cp); #endregion }
public void ToImc(FileInfo file, ConverterSettings settings) { // Don't knoww what format imc files are actually in, so for now we'll dump them to json. this.ToJson(file, settings); }
static void Main(string[] args) { // Activate Gnostice product Framework.ActivateLicense("4AF4-263D-70A5-F5C8-57E6-045C-ED92-5369"); // Instantiate DocumentConverter DocumentConverter docConverter = new DocumentConverter(); // Subscribe to Error event docConverter.Error += docConverter_Error; // Input Directory string inputPath = @"../../../../../03. Sample Files/"; // Output Directory string outputPath = @"../../../../../04. Output/"; // List of files as input for the document Converter List <string> inputFiles = Directory.GetFiles(inputPath).ToList(); // Output Format string outputFormat = "tiff"; // Single input file string inputFile = inputPath + "input.docx"; // Single output file string outputFile = outputPath + "output." + outputFormat; #region Simple Conversion // Converting sample input file to TIFF format docConverter.ConvertToFile(inputFile, outputFile); #endregion // public List<string> ConvertToFile( // object input, => accepts string (file name) or Stream (file stream) or List<string> or List<Stream> // string outputFileFormat, => expected output file format // string outputDir, => directory in which the output files are to be stored // string baseFileName = "", => name of the output converted file // ConversionMode conversionmode, => ConversionMode.ConvertToSeparateFiles to create a separated file for each converted input file // ConverterSettings converterSettings = null, => specifiy the range of pages to be converted // EncoderSettings encoderSettings = null, => set the information for encoding the document // string inputDocPassword = "" => password for the input document // ); #region One to One Conversion // Converts all //ConversionMode.ConvertToSeparateFiles=>Many to many conversion //Convert list of files in inputFiles into a single output file by specifying Conversion mode as ConversionMode.ConvertToSeperateFiles docConverter.ConvertToFile(inputFiles, outputFormat, outputPath, "ConvertToTIFF_OneToOne_Multiple", ConversionMode.ConvertToSeperateFiles); #endregion #region Convert to single file //ConversionMode.ConverToSingleFile => Convert all the input files and merge it to a single file //Converts list of files in inputFiles into a single output file by specifying Conversion mode as ConversionMode.ConvertToSingleFile docConverter.ConvertToFile(inputFiles, outputFormat, outputPath, "ConvertToTIFF_ManyToOne", ConversionMode.ConvertToSingleFile); #endregion #region Converting file using ConverterSettings // Instantiate ConverterSettings ConverterSettings cp = new ConverterSettings(); // Converter Parameter : PageRange // 4 different types of page ranges // PageRange.All => Converts all pages in input file // PageRange.Even => Converts Pages with even page number // PageRange.Odd => Converts Pages with odd page number // PageRange.Custom => Converts set of pages from input file. ** page range should be specified in CustomPageRange // Convert all odd pages in input file cp.PageRange = PageRange.Odd; docConverter.ConvertToFile(inputFile, outputFormat, outputPath, "ConvertToTIFF_WithConverterSettings_Even", ConversionMode.ConvertToSeperateFiles, null, cp); // Convert specific pages from input file, say one need to convert 1,3,5,6,7,10 pages from input file cp.PageRange = PageRange.Custom; cp.CustomPageRange = "1,3,5-7,10"; // **PageRange should be set to PageRange.Custom docConverter.ConvertToFile(inputFile, outputFormat, outputPath, "ConvertToTIFF_WithConverterSettings_Custom", ConversionMode.ConvertToSeperateFiles, null, cp); #endregion #region TIFF Encoder settings // TIFF encoder formats TIFFEncoderSettings tiffEncoderFormats = new TIFFEncoderSettings(); // Compression Type // 4 types // TiffCompressionType.None => No Compression // TiffCompressionType.CCIT3 => Group 3 compression // TiffCompressionType.CCIT4 => Group 4 compression // TiffCompressionType.Rle => Run length compression // TiffCompressionType.Lzw => Lempel–Ziv–Welch lossless data compression tiffEncoderFormats.CompressionType = TiffCompressionType.None; // Page Scaling // 2 types of page scaling // PageScaling.None => No page scaling // PageScalling.UseRenderingResolution => scaling to the rendering resolution tiffEncoderFormats.PageScalling = PageScalling.None; // Rendering Settings // The compositing mode CompositingMode determines whether pixels from a source image overwrite or are combined with background pixels. // 2 compositing modes // System.Drawing.Drawing2D.CompositingMode.SourceOver => Specifies that when a color is rendered, it is blended with the background color. The blend is determined by the alpha component of the color being rendered. // System.Drawing.Drawing2d.Compositing.SourceCopy => Specifies that when a color is rendered, it overwrites the background color. tiffEncoderFormats.RenderingSettings.Image.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy; //The composition quality CompositingQuality sets the rendering quality of composited images drawn // 6 compositing quality types // CompositingQuality.AssumeLinear => Assume linear values // CompositingQuality.Default => Default quality // CompositingQuality.GammaCorrected => Use Gamma correction // CompositingQuality.HighQuality => High quality low speed compositing // CompositingQuality.HighSpeed => High speed low quality compositing // CompositingQuality.Invalid => Invalid quality tiffEncoderFormats.RenderingSettings.Image.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.Default; // The Interpolation mode sets the interpolation mode associated with this image // 9 Interpolation modes // InterpolationMode.Bicubic => Specifies bicubic interpolation. No prefiltering is done. This mode is not suitable for shrinking an image below 25 percent of its original size. // InterpolationMode.Bilinear => Specifies bilinear interpolation. No prefiltering is done. This mode is not suitable for shrinking an image below 50 percent of its original size. // InterpolationMode.Default => Specifies default mode. // InterpolationMode.High => Specifies high quality interpolation. // InterpolationMode.HighQualityBicubic => Specifies high-quality, bicubic interpolation. Prefiltering is performed to ensure high-quality shrinking. This mode produces the highest quality transformed images. // InterpolationMode.HighQualityBilinear => Specifies high-quality, bilinear interpolation. Prefiltering is performed to ensure high-quality shrinking. // InterpolationMode.Invalid => Equivalent to the Invalid element of the QualityMode enumeration. // InterpolationMode.Low => Specifies low quality interpolation. // InterpolationMode.NearestNeighbor => Specifies nearest-neighbor interpolation. tiffEncoderFormats.RenderingSettings.Image.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Default; // The pixel offset mode sets a value specifying how pixels are offset during rendering of this image // 6 pixel offset modes // PixelOffsetMode.Half => Specifies that pixels are offset by -.5 units, both horizontally and vertically, for high speed antialiasing. // PixelOffsetMode.Default => Specifies the default mode // PixelOffsetMode.None => Specifies no pixel offset // PixelOffsetMode.HighQuality => High quality low speed rendering // PixelOffsetMode.HighSpeed => High speed low quality rendenring // PixelOffsetMode.Invalid => Specifies an invalid mode tiffEncoderFormats.RenderingSettings.Image.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Default; // The smoothing mode specifies whether lines, curves, and the edges of filled areas use smoothing (also called antialiasing) // 6 Line Smoothening modes for line art // System.Drawing.Drawing2D.SmoothingMode.AntiAlias => Specifies antialiased rendering. // System.Drawing.Drawing2D.SmoothingMode.Default => Specifies no antialiasing. // System.Drawing.Drawing2D.SmoothingMode.HighQuality => Specifies antialiased rendering. // System.Drawing.Drawing2D.SmoothingMode.HighSpeed => Specifies no antialiasing. // System.Drawing.Drawing2D.SmoothingMode.Invalid => Specifies an invalid mode. // System.Drawing.Drawing2D.SmoothingMode.None => Specifies no antialiasing. tiffEncoderFormats.RenderingSettings.LineArt.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.Default; // Text Contarst tiffEncoderFormats.RenderingSettings.Text.TextContrast = 5; // Text Rendering Hint // 6 types of text rendering hints // System.Drawing.Text.TextRenderingHint.SystemDefault => Each character is drawn using its glyph bitmap, with the system default rendering hint. The text will be drawn using whatever font-smoothing settings the user has selected for the system. // System.Drawing.Text.TextRenderingHint.AntiAlias => Each character is drawn using its antialiased glyph bitmap without hinting. Better quality due to antialiasing. Stem width differences may be noticeable because hinting is turned off. // System.Drawing.Text.TextRenderingHint.AntiAliasGridFit => Each character is drawn using its antialiased glyph bitmap with hinting. Much better quality due to antialiasing, but at a higher performance cost. // System.Drawing.Text.TextRenderingHint.ClearTypeGridFit => Each character is drawn using its glyph ClearType bitmap with hinting. The highest quality setting. Used to take advantage of ClearType font features. // System.Drawing.Text.TextRenderingHint.SingleBitPerPixelPerGridFit => Each character is drawn using its glyph bitmap. Hinting is used to improve character appearance on stems and curvature. // System.Drawing.Text.TextRenderingHint.SingleBitPerPixel => Each character is drawn using its glyph bitmap. Hinting is not used. tiffEncoderFormats.RenderingSettings.Text.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SystemDefault; // Rendering Settings resolution tiffEncoderFormats.RenderingSettings.Resolution.DPI = 96f; tiffEncoderFormats.RenderingSettings.Resolution.DpiX = 96f; tiffEncoderFormats.RenderingSettings.Resolution.DpiY = 96f; // Resolution Mode // 3 types of resolution modes // ResolutionMode.UseSource => use source resolution // ResolutionMode.UseDevice => use device resolution // ResolutionMode.UseSpecifiedDPI => use DPI specified in pngEncoderFormats.RenderingSettings.Resolution.DPI tiffEncoderFormats.RenderingSettings.Resolution.ResolutionMode = ResolutionMode.UseSource; // Resolution Settings resolution tiffEncoderFormats.ResolutionSettings.DPI = 96f; tiffEncoderFormats.ResolutionSettings.DpiX = 96f; tiffEncoderFormats.ResolutionSettings.DpiY = 96f; // Resolution Settings Resolution Mode // 3 types of resolution modes // ResolutionMode.UseSource => use source resolution // ResolutionMode.UseDevice => use device resolution // ResolutionMode.UseSpecifiedDPI => use DPI specified in pngEncoderFormats.RenderingSettings.Resolution.DPI tiffEncoderFormats.ResolutionSettings.ResolutionMode = ResolutionMode.UseSource; // Multipage TIFF conversion // MultiPage => convert and combine each page in a multipage file into a single file tiffEncoderFormats.MultiPage = true; docConverter.ConvertToFile(inputFile, outputFormat, outputPath, "ConvertToTIFF_WithEncoderSettings_into_MultiPageTIFFFile", ConversionMode.ConvertToSeperateFiles, tiffEncoderFormats); //Singlepage TIFF conversion //Converts a file containing multiple pages into separate files for each page tiffEncoderFormats.MultiPage = false; docConverter.ConvertToFile(inputFile, outputFormat, outputPath, "ConvertToTIFF_WithEncoderSettings_into_SinglePageTIFFFile", ConversionMode.ConvertToSeperateFiles, tiffEncoderFormats); #endregion }
static void Main(string[] args) { // Activate Gnostice product Framework.ActivateLicense("4AF4-263D-70A5-F5C8-57E6-045C-ED92-5369"); // Instantiate DocumentConverter DocumentConverter docConverter = new DocumentConverter(); // Subscribe to Error event docConverter.Error += docConverter_Error; // Input Directory string inputPath = @"../../../../../03. Sample Files/"; // Output Directory string outputPath = @"../../../../../04. Output/"; // Output Format string outputFormat = "txt"; // List of files as input for the document Converter List <string> inputFiles = Directory.GetFiles(inputPath).ToList(); // Single input file string inputFile = inputPath + "input.docx"; // Single output file string outputFile = outputPath + "output." + outputFormat; #region Simple Conversion // Converting sample input file to TXT format docConverter.ConvertToFile(inputFile, outputFile); #endregion // public List<string> ConvertToFile( // object input, => accepts string (file name) or Stream (file stream) or List<string> or List<Stream> // string outputFileFormat, => expected output file format // string outputDir, => directory in which the output files are to be stored // string baseFileName = "", => name of the output converted file // ConversionMode conversionmode, => ConversionMode.ConvertToSeparateFiles to create a separated file for each converted input file // ConverterSettings converterSettings = null, => specifiy the range of pages to be converted // EncoderSettings encoderSettings = null, => set the information for encoding the document // string inputDocPassword = "" => password for the input document // ); #region One to One Conversion // Converts all //ConversionMode.ConvertToSeparateFiles=>Many to many conversion //Convert list of files in inputFiles into a single output file by specifying Conversion mode as ConversionMode.ConvertToSeperateFiles docConverter.ConvertToFile(inputFiles, outputFormat, outputPath, "ConvertToTXT_OneToOne_Multiple", ConversionMode.ConvertToSeperateFiles); #endregion #region Convert to single file //ConversionMode.ConverToSingleFile => Convert all the input files and merge it to a single file //Converts list of files in inputFiles into a single output file by specifying Conversion mode as ConversionMode.ConvertToSingleFile docConverter.ConvertToFile(inputFiles, outputFormat, outputPath, "ConvertToTXT_ManyToOne", ConversionMode.ConvertToSingleFile); #endregion #region Converting file using ConverterSettings // Instantiate ConverterSettings ConverterSettings cp = new ConverterSettings(); // Converter Parameter : PageRange // 4 different types of page ranges // PageRange.All => Converts all pages in input file // PageRange.Even => Converts Pages with even page number // PageRange.Odd => Converts Pages with odd page number // PageRange.Custom => Converts set of pages from input file. ** page range should be specified in CustomPageRange // Convert all even pages in input file cp.PageRange = PageRange.Even; docConverter.ConvertToFile(inputFile, outputFormat, outputPath, "ConvertToTXT_WithConverterSettings_Even", ConversionMode.ConvertToSeperateFiles, null, cp); // Convert specific pages from input file, say one needs to convert pages 1,4,8,9,10,11,12 from input file cp.PageRange = PageRange.Custom; cp.CustomPageRange = "1,4,8-12"; // **PageRange should be set to PageRange.Custom docConverter.ConvertToFile(inputFile, outputFormat, outputPath, "ConvertToTXT_WithConverterSettings_Custom", ConversionMode.ConvertToSeperateFiles, null, cp); #endregion #region TXT Encoder Parameters // For encoding file into TXT textEncoderParams have to be specified TextEncoderSettings txtEncoderParams = new TextEncoderSettings(); txtEncoderParams.ByteOrderMarkBytes = new byte[0]; // Types of file Encoding Files 'FileEncoding' // FileEncoding.ISO_8859_1=> encoding files in ISO 8859-1 // FileEncoding.US_ASCII=>Encoding files in US ASCII // FileEncoding.UTF_16BE=> Encoding files in UTF 16BE // FileEncoding.UTF_16LE=> Encoding files in UTF 16LE // FileEncoding.UTF_8=> Encoding files in UTF 8 (default file encoding) txtEncoderParams.FileEncoding = FileEncoding.UTF_8; // 6 members of TextFormatter // TextFormatter.BreakLines=> break point at every line // TextFormatter.BreakPages=>break point at every page // TextFormatter.BreakParagraphs=>break point at every paragraph // TextFormatter.CustomPageBreak=>to enable cutom break point // TextFormatter.CustomPageBreakText=>set the custom break point // TextFormatter.FILE_SEPARATOR_CHAR=>set the file separator character // TextFormatter.PageBreakText=>set the page break text // For setting break point to every line txtEncoderParams.TextFormatter.CustomPageBreak = true; txtEncoderParams.TextFormatter.CustomPageBreakText = "<<Page Break>>"; // txtEncoderParams.UseByteOrderMark=>to use byte order mark txtEncoderParams.UseByteOrderMark = true; docConverter.ConvertToFile(inputFile, "txt", outputPath, "ConvertToTXT_WithEncoderSettings", ConversionMode.ConvertToSeperateFiles, txtEncoderParams, cp); #endregion }
protected override void ApplySettings(ConverterSettings settings) { base.ApplySettings(settings); settings.SimplifyTypeNames = true; settings.RemoveRedundantTypeReferences = true; }
protected override void ApplySettings(ConverterSettings settings) { base.ApplySettings(settings); settings.SimplifyTypeNames = true; settings.RemoveRedundantTypeReferences = true; }