htmlimagepdfflutterdart

Can we convert PDF into image using flutter in order to show thumbnail of the file?


Use-Case: In order to show thumbnail of the PDF in file list.

Question 2: Can we convert FPF to image to show thumbnail in the list?


Solution

  • Correct Answer: Using Printing and pdf plugin, In order to convert PDF to image we can simply achieve this by:

    // send pdfFile as params
    imageFromPdfFile(File pdfFile) async {
        final document = await lib.PDFDocument.openFile(pdfFile.path);
        final page = await document.getPage(1);
        final pageImage = await page.render(width: page.width, height: page.height);
        await page.close();
        print(pageImage.bytes);
    
        //... now convert 
        // .... pageImage.bytes to image
    }