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 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
import com.aspose.imaging.Color; | |
import com.aspose.imaging.Image; | |
import com.aspose.imaging.IntRange; | |
import com.aspose.imaging.ResolutionSetting; | |
import com.aspose.imaging.fileformats.djvu.DjvuImage; | |
import com.aspose.imaging.fileformats.djvu.DjvuPage; | |
import com.aspose.imaging.imagefilters.filteroptions.GaussianBlurFilterOptions; | |
import com.aspose.imaging.imageoptions.DjvuMultiPageOptions; | |
import com.aspose.imaging.imageoptions.PdfOptions; | |
import java.util.Random; | |
static String templatesFolder = "c:\\templates\\"; | |
public static void run() | |
{ | |
Random random = new Random(); | |
// Path to input djvu file | |
String input = templatesFolder + "sample.djvu"; | |
try (DjvuImage image = (DjvuImage) Image.load(input)) | |
{ | |
int documentPageCount = image.getPageCount(); | |
final DjvuPage[] djvuPages = image.getDjvuPages(); | |
// Apply scanner effects | |
for (int i = 0; i < documentPageCount; i++) | |
{ | |
djvuPages[i].rotate(-0.5f + random.nextInt() % 2, true, Color.getWhite()); | |
djvuPages[i].filter(djvuPages[i].getBounds(), new GaussianBlurFilterOptions(5, 5)); | |
} | |
// Export to Pdf | |
int DefaultPagePpi = 300; | |
PdfOptions exportOptions = new PdfOptions(); | |
exportOptions.setResolutionSettings(new ResolutionSetting(DefaultPagePpi, DefaultPagePpi)); | |
exportOptions.setPdfDocumentInfo(new com.aspose.imaging.fileformats.pdf.PdfDocumentInfo()); | |
IntRange range = new IntRange(0, documentPageCount); | |
exportOptions.setMultiPageOptions(new DjvuMultiPageOptions(range)); | |
image.save(input.replace(".djvu", ".pdf"), exportOptions); | |
} | |
} |
|
|
---|---|
Input image before application of scan effect | Looking like scanned result |