public override ConversionEngine ConstructFileEngine(string fileName, byte[] file, UnsupportedTypeHandlingEnum unsupportedHandling) { if (string.IsNullOrEmpty(fileName)) { throw new MissingSourceException("File not specified."); } ConversionEngine engine = null; switch (Path.GetExtension(fileName).ToLower()) { case ".pdf": engine = new PdfEngine(file); break; case ".png": case ".gif": case ".jpeg": case ".jpg": case ".bmp": engine = new WebKitImageEngine(fileName, file); break; case ".html": case ".htm": engine = new WebKitFileEngine(fileName, file); break; case ".odt": case ".doc": case ".docx": case ".xls": case ".xlsx": case ".ppt": case ".pptx": case ".txt": case ".rtf": engine = new LibreOfficeConversionEngine(fileName, file); break; default: switch (unsupportedHandling) { case UnsupportedTypeHandlingEnum.Error: throw new UnsupportedSourceException("Unsupported file type.", Path.GetExtension(fileName)); case UnsupportedTypeHandlingEnum.NoPage: engine = new NullEngine(); break; case UnsupportedTypeHandlingEnum.PageWithErrorText: engine = new UnsupportedTypeEngine(fileName); break; default: throw new InvalidEnumArgumentException("unsupportedHandling", (int)unsupportedHandling, typeof(UnsupportedTypeHandlingEnum)); } break; } return engine; }
private UnsupportedTypeHandlingEnum GetUnsupportedHandlingFromOptions(ConversionOptions options) { UnsupportedTypeHandlingEnum handling = UnsupportedTypeHandlingEnum.Error; if (!options.SilentFailOnUnsupportedType) { handling = UnsupportedTypeHandlingEnum.Error; } else if (options.UsePlaceholderPageOnUnsupportedType) { handling = UnsupportedTypeHandlingEnum.PageWithErrorText; } else { handling = UnsupportedTypeHandlingEnum.NoPage; } return(handling); }
public byte[] ConvertFiles(Dictionary <string, byte[]> files, ConversionOptions options) { if (files == null || files.Count == 0) { throw new MissingSourceException("No files were specified."); } List <byte[]> converted = new List <byte[]>(); foreach (KeyValuePair <string, byte[]> file in files) { UnsupportedTypeHandlingEnum unsupportedHandling = GetUnsupportedHandlingFromOptions(options); using (ConversionEngine engine = m_engineFactory.ConstructFileEngine(file.Key, file.Value, unsupportedHandling)) { engine.ConvertToPdf(options); byte[] result = engine.OutputFile; converted.Add(result); } } return(CombinePdfs(converted, options)); }
public abstract ConversionEngine ConstructFileEngine(string fileName, byte[] file, UnsupportedTypeHandlingEnum unsupportedHandling);
public override ConversionEngine ConstructFileEngine(string fileName, byte[] file, UnsupportedTypeHandlingEnum unsupportedHandling) { if (string.IsNullOrEmpty(fileName)) { throw new MissingSourceException("File not specified."); } ConversionEngine engine = null; switch (Path.GetExtension(fileName).ToLower()) { case ".pdf": engine = new PdfEngine(file); break; case ".png": case ".gif": case ".jpeg": case ".jpg": case ".bmp": engine = new WebKitImageEngine(fileName, file); break; case ".html": case ".htm": engine = new WebKitFileEngine(fileName, file); break; case ".odt": case ".doc": case ".docx": case ".xls": case ".xlsx": case ".ppt": case ".pptx": case ".txt": case ".rtf": engine = new LibreOfficeConversionEngine(fileName, file); break; default: switch (unsupportedHandling) { case UnsupportedTypeHandlingEnum.Error: throw new UnsupportedSourceException("Unsupported file type.", Path.GetExtension(fileName)); case UnsupportedTypeHandlingEnum.NoPage: engine = new NullEngine(); break; case UnsupportedTypeHandlingEnum.PageWithErrorText: engine = new UnsupportedTypeEngine(fileName); break; default: throw new InvalidEnumArgumentException("unsupportedHandling", (int)unsupportedHandling, typeof(UnsupportedTypeHandlingEnum)); } break; } return(engine); }