Convert image to pdf, which looks like a scanned
Contents
[
Hide
]
Convert image to pdf, which looks like a scanned
Issue : How to emulate scanned document from your image
Tips : Appose.Imaging allows convert your single page or multi page images into pdf, which looks like a scanned document.
Example of conversion of image to pdf, which looks like a scanned
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using Aspose.Imaging; | |
using Aspose.Imaging.FileFormats.Djvu; | |
using Aspose.Imaging.ImageFilters.FilterOptions; | |
using Aspose.Imaging.ImageOptions; | |
string templatesFolder = @"c:\Users\USER\Downloads\templates\"; | |
Run(); | |
void Run() | |
{ | |
Random random = new Random(); | |
// Path to input djvu file | |
string input = Path.Combine(templatesFolder,"template.djvu"); | |
using (DjvuImage image = (DjvuImage)Image.Load(input)) | |
{ | |
int documentPageCount = image.Pages.Length; | |
// Apply scanner effects | |
for (int i = 0; i < documentPageCount; i++) | |
{ | |
image.DjvuPages[i].Rotate(-0.5f + random.Next() % 2, true, Color.White); | |
image.DjvuPages[i].Filter(image.DjvuPages[i].Bounds, new GaussianBlurFilterOptions(5, 5)); | |
} | |
// Export to Pdf | |
int DefaultPagePpi = 300; | |
PdfOptions exportOptions = new PdfOptions(); | |
exportOptions.ResolutionSettings = new ResolutionSetting(DefaultPagePpi, DefaultPagePpi); | |
exportOptions.PdfDocumentInfo = new Aspose.Imaging.FileFormats.Pdf.PdfDocumentInfo(); | |
IntRange range = new IntRange(0, 1); | |
exportOptions.MultiPageOptions = new DjvuMultiPageOptions(range); | |
image.Save(Path.Combine(templatesFolder,"result.pdf"), | |
exportOptions); | |
} | |
File.Delete(Path.Combine(templatesFolder,"result.pdf")); | |
} |
|
|
---|---|
Input image before application of scan effect | Looking like scanned result |