private OutputDevice GetCorrectOutputDevice(Job job) { OutputDevice device; switch (job.Profile.OutputFormat) { case OutputFormat.PdfA1B: case OutputFormat.PdfA2B: case OutputFormat.PdfA3B: case OutputFormat.PdfX: case OutputFormat.Pdf: device = new PdfDevice(job); break; case OutputFormat.Png: device = new PngDevice(job); break; case OutputFormat.Jpeg: device = new JpegDevice(job); break; case OutputFormat.Tif: device = new TiffDevice(job); break; case OutputFormat.Txt: device = new TextDevice(job); break; default: throw new Exception("Illegal OutputFormat specified"); } return(device); }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_Images(); //Open document Document pdfDocument = new Document(dataDir+ "PageToTIFF.pdf"); //Create Resolution object Resolution resolution = new Resolution(300); //Create TiffSettings object TiffSettings tiffSettings = new TiffSettings(); tiffSettings.Compression = CompressionType.None; tiffSettings.Depth = ColorDepth.Default; tiffSettings.Shape = ShapeType.Landscape; tiffSettings.SkipBlankPages = false; //Create TIFF device TiffDevice tiffDevice = new TiffDevice(resolution, tiffSettings); //Convert a particular page and save the image to stream tiffDevice.Process(pdfDocument, 1, 1, dataDir + "output.tif"); }
public static void Run() { // ExStart:BradleyAlgorithm // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_Images(); // Open document Document pdfDocument = new Document(dataDir + "PageToTIFF.pdf"); string outputImageFile = dataDir + "resultant_out.tif"; string outputBinImageFile = dataDir + "37116-bin_out.tif"; // Create Resolution object Resolution resolution = new Resolution(300); // Create TiffSettings object TiffSettings tiffSettings = new TiffSettings(); tiffSettings.Compression = CompressionType.LZW; tiffSettings.Depth = Aspose.Pdf.Devices.ColorDepth.Format1bpp; // Create TIFF device TiffDevice tiffDevice = new TiffDevice(resolution, tiffSettings); // Convert a particular page and save the image to stream tiffDevice.Process(pdfDocument, outputImageFile); using (FileStream inStream = new FileStream(outputImageFile, FileMode.Open)) { using (FileStream outStream = new FileStream(outputBinImageFile, FileMode.Create)) { tiffDevice.BinarizeBradley(inStream, outStream, 0.1); } } // ExEnd:BradleyAlgorithm System.Console.WriteLine("Conversion using bradley algorithm performed successfully!"); }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_Images(); //Open document Document pdfDocument = new Document(dataDir + "PageToTIFF.pdf"); //Create Resolution object Resolution resolution = new Resolution(300); //Create TiffSettings object TiffSettings tiffSettings = new TiffSettings(); tiffSettings.Compression = CompressionType.None; tiffSettings.Depth = ColorDepth.Default; tiffSettings.Shape = ShapeType.Landscape; tiffSettings.SkipBlankPages = false; //Create TIFF device TiffDevice tiffDevice = new TiffDevice(resolution, tiffSettings); //Convert a particular page and save the image to stream tiffDevice.Process(pdfDocument, 1, 1, dataDir + "output.tif"); }
public static void Run() { // ExStart:AllPagesToTIFF // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_Images(); // Open document Document pdfDocument = new Document(dataDir + "PageToTIFF.pdf"); // Create Resolution object Resolution resolution = new Resolution(300); // Create TiffSettings object TiffSettings tiffSettings = new TiffSettings(); tiffSettings.Compression = CompressionType.None; tiffSettings.Depth = ColorDepth.Default; tiffSettings.Shape = ShapeType.Landscape; tiffSettings.SkipBlankPages = false; // Create TIFF device TiffDevice tiffDevice = new TiffDevice(resolution, tiffSettings); // Convert a particular page and save the image to stream tiffDevice.Process(pdfDocument, dataDir + "AllPagesToTIFF_out_.tif"); // ExEnd:AllPagesToTIFF System.Console.WriteLine("PDF all pages converted to one tiff file successfully!"); }
public static void Run() { // ExStart:AllPagesToTIFF // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_Images(); // Open document Document pdfDocument = new Document(dataDir+ "PageToTIFF.pdf"); // Create Resolution object Resolution resolution = new Resolution(300); // Create TiffSettings object TiffSettings tiffSettings = new TiffSettings(); tiffSettings.Compression = CompressionType.None; tiffSettings.Depth = ColorDepth.Default; tiffSettings.Shape = ShapeType.Landscape; tiffSettings.SkipBlankPages = false; // Create TIFF device TiffDevice tiffDevice = new TiffDevice(resolution, tiffSettings); // Convert a particular page and save the image to stream tiffDevice.Process(pdfDocument, dataDir + "AllPagesToTIFF_out.tif"); // ExEnd:AllPagesToTIFF System.Console.WriteLine("PDF all pages converted to one tiff file successfully!"); }
public static void Main(string[] args) { // The path to the documents directory. string dataDir = Path.GetFullPath("../../../Data/"); //Open document Document pdfDocument = new Document(dataDir + "input.pdf"); //Create Resolution object Resolution resolution = new Resolution(300); //Create TiffSettings object TiffSettings tiffSettings = new TiffSettings(); tiffSettings.Compression = CompressionType.None; tiffSettings.Depth = ColorDepth.Default; tiffSettings.Shape = ShapeType.Landscape; tiffSettings.SkipBlankPages = false; //Create TIFF device TiffDevice tiffDevice = new TiffDevice(resolution, tiffSettings); //Convert a particular page and save the image to stream tiffDevice.Process(pdfDocument, 1, 1, dataDir + "output.tif"); }
public static void Run() { // ExStart:BradleyAlgorithm // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_Images(); // Open document Document pdfDocument = new Document(dataDir+ "PageToTIFF.pdf"); string outputImageFile = dataDir + "resultant_out.tif"; string outputBinImageFile = dataDir + "37116-bin_out.tif"; // Create Resolution object Resolution resolution = new Resolution(300); // Create TiffSettings object TiffSettings tiffSettings = new TiffSettings(); tiffSettings.Compression = CompressionType.LZW; tiffSettings.Depth = Aspose.Pdf.Devices.ColorDepth.Format1bpp; // Create TIFF device TiffDevice tiffDevice = new TiffDevice(resolution, tiffSettings); // Convert a particular page and save the image to stream tiffDevice.Process(pdfDocument, outputImageFile); using (FileStream inStream = new FileStream(outputImageFile, FileMode.Open)) { using (FileStream outStream = new FileStream(outputBinImageFile, FileMode.Create)) { tiffDevice.BinarizeBradley(inStream, outStream, 0.1); } } // ExEnd:BradleyAlgorithm System.Console.WriteLine("Conversion using bradley algorithm performed successfully!"); }
///<Summary> /// ConvertPdfToTiff method to convert PDF to TIFF ///</Summary> public Response ConvertPdfToTiff(string fileName, string folderName) { return(ProcessTask(fileName, folderName, ".tiff", false, "", false, delegate(string inFilePath, string outPath, string zipOutFolder) { Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(inFilePath); Resolution resolution = new Resolution(300); TiffDevice tiffDevice = new TiffDevice(resolution); tiffDevice.Process(pdfDocument, outPath); })); }
public static OutputDevice GenerateDevice(OutputFormat outputFormat, IFile fileWrap = null) { var jobStub = GenerateJobStub(outputFormat); var fileStub = fileWrap ?? Substitute.For <IFile>(); var osHelperStub = Substitute.For <IOsHelper>(); osHelperStub.WindowsFontsFolder.Returns(WindowsFontsFolderDummie); var commandLineUtilStub = Substitute.For <ICommandLineUtil>(); OutputDevice device = null; switch (outputFormat) { case OutputFormat.Jpeg: device = new JpegDevice(jobStub, fileStub, osHelperStub, commandLineUtilStub); break; case OutputFormat.Pdf: case OutputFormat.PdfA1B: case OutputFormat.PdfA2B: case OutputFormat.PdfX: device = new PdfDevice(jobStub, fileStub, osHelperStub, commandLineUtilStub); break; case OutputFormat.Png: device = new PngDevice(jobStub, fileStub, osHelperStub, commandLineUtilStub); break; case OutputFormat.Tif: device = new TiffDevice(jobStub, fileStub, osHelperStub, commandLineUtilStub); break; case OutputFormat.Txt: device = new TextDevice(jobStub, fileStub, osHelperStub, commandLineUtilStub); break; } return(device); }
public static OutputDevice GenerateDevice(OutputFormat outputFormat) { var jobStub = GenerateJobStub(outputFormat); var fileStub = MockRepository.GenerateStub <IFile>(); var osHelperStub = MockRepository.GenerateStub <IOsHelper>(); osHelperStub.Stub(x => x.WindowsFontsFolder).Return(WindowsFontsFolderDummie); var commandLineUtilStub = MockRepository.GenerateStub <ICommandLineUtil>(); OutputDevice device = null; switch (outputFormat) { case OutputFormat.Jpeg: device = new JpegDevice(jobStub, fileStub, osHelperStub, commandLineUtilStub); break; case OutputFormat.Pdf: case OutputFormat.PdfA1B: case OutputFormat.PdfA2B: case OutputFormat.PdfX: device = new PdfDevice(jobStub, fileStub, osHelperStub, commandLineUtilStub); break; case OutputFormat.Png: device = new PngDevice(jobStub, fileStub, osHelperStub, commandLineUtilStub); break; case OutputFormat.Tif: device = new TiffDevice(jobStub, fileStub, osHelperStub, commandLineUtilStub); break; case OutputFormat.Txt: device = new TextDevice(jobStub, fileStub, osHelperStub, commandLineUtilStub); break; } return(device); }
private OutputDevice GetOutputDevice(Job job, ConversionMode conversionMode) { OutputDevice device; if (conversionMode == ConversionMode.IntermediateConversion) { return(new PdfIntermediateDevice(job)); } switch (job.Profile.OutputFormat) { case OutputFormat.PdfA1B: case OutputFormat.PdfA2B: case OutputFormat.PdfA3B: case OutputFormat.PdfX: case OutputFormat.Pdf: device = new PdfDevice(job, conversionMode); break; case OutputFormat.Png: device = new PngDevice(job, conversionMode); break; case OutputFormat.Jpeg: device = new JpegDevice(job, conversionMode); break; case OutputFormat.Tif: device = new TiffDevice(job, conversionMode); break; case OutputFormat.Txt: device = new TextDevice(job, conversionMode); break; default: throw new Exception("Illegal OutputFormat specified"); } return(device); }
public static void Main(string[] args) { // The path to the documents directory. string dataDir = Path.GetFullPath("../../../Data/"); //Open document Document pdfDocument = new Document(dataDir+ "input.pdf"); //Create Resolution object Resolution resolution = new Resolution(300); //Create TiffSettings object TiffSettings tiffSettings = new TiffSettings(); tiffSettings.Compression = CompressionType.None; tiffSettings.Depth = ColorDepth.Default; tiffSettings.Shape = ShapeType.Landscape; tiffSettings.SkipBlankPages = false; //Create TIFF device TiffDevice tiffDevice = new TiffDevice(resolution, tiffSettings); //Convert a particular page and save the image to stream tiffDevice.Process(pdfDocument, 1, 1, dataDir + "output.tif"); }
/// <summary> /// Run the Job /// </summary> protected override JobState RunJobWork() { try { if (string.IsNullOrEmpty(Thread.CurrentThread.Name)) { Thread.CurrentThread.Name = "JobWorker"; } } catch (InvalidOperationException) { } try { _ghostScript.Output += Ghostscript_Output; OnJobCompleted += (sender, args) => _ghostScript.Output -= Ghostscript_Output; OutputFiles.Clear(); Logger.Trace("Setting up actions"); SetUpActions(); Logger.Debug("Starting Ghostscript Job"); OutputDevice device; switch (Profile.OutputFormat) { case OutputFormat.PdfA1B: case OutputFormat.PdfA2B: case OutputFormat.PdfX: case OutputFormat.Pdf: device = new PdfDevice(this); break; case OutputFormat.Png: device = new PngDevice(this); break; case OutputFormat.Jpeg: device = new JpegDevice(this); break; case OutputFormat.Tif: device = new TiffDevice(this); break; case OutputFormat.Txt: device = new TextDevice(this); break; default: throw new Exception("Illegal OutputFormat specified"); } Logger.Trace("Output format is: {0}", Profile.OutputFormat.ToString()); _ghostScript.Output += Ghostscript_Logging; var success = _ghostScript.Run(device, JobTempFolder); _ghostScript.Output -= Ghostscript_Logging; Logger.Trace("Finished Ghostscript execution"); if (!success) { var errorMessage = ExtractGhostscriptErrors(GhostscriptOutput); Logger.Error("Ghostscript execution failed: " + errorMessage); ErrorMessage = errorMessage; JobState = JobState.Failed; return(JobState); } ProcessOutput(); Logger.Trace("Moving output files to final location"); MoveOutputFiles(); Logger.Trace("Finished Ghostscript Job"); JobState = JobState.Succeeded; return(JobState); } catch (ProcessingException) { JobState = JobState.Failed; throw; } catch (DeviceException) { JobState = JobState.Failed; throw; } catch (Exception ex) { JobState = JobState.Failed; Logger.Error("There was an error while converting the Job {0}: {1}", JobInfo.InfFile, ex); throw; } }