Scanned image after converting it to PDF is blurry

0 votes
asked Sep 13, 2017 by hrsha-ro

I'm scanning a document to an image stored in a ByteArrayOutputStream.

Then from the ByteArrayOutputStream, I create a PDF using iText, but the image in that PDF is blurred and not visible at all. If we scan small document, it's OK, but when we scan a sheet of size , it gets saved as a blurred image inside the PDF.

We tried various way to improve the quality but nothing improved the quality. I tried converting the image to a print stream, but that made it even more blurred than before.

Component[] comps = MainPanel.this.getComponents();
List<ImagePanel> scannedImages = new ArrayList<ImagePanel>();
for (Component c : comps) {
    if (c instanceof ImagePanel) {
        scannedImages.add((ImagePanel) c);
    }
}
ByteArrayOutputStream output = new ByteArrayOutputStream();
Document document = new Document(PageSize.A4, 0, 0, 0, 0);
try {
    PdfWriter.getInstance(document, output);
    document.open();
    for (ImagePanel p : scannedImages) {
        com.lowagie.text.Image iTextImage = com.lowagie.text.Image.getInstance(p.getImage().getScaledInstance(documentWidth, documentHeight, Image.SCALE_DEFAULT), null);
        document.add(iTextImage);
        document.newPage();
    }
}
catch(Exception e) {
} 
    document.close();
 DocumentUploadInfo.setDocumentStream(output.toByteArray());
 DocumentUploadInfo.setDocumentMIMEType("application/pdf");

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.
Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter

...