我们可以使用 flutter 将 PDF 转换为图像以显示文件的缩略图吗?

jaz*_*bpn 5 html pdf image dart flutter

用例:为了在文件列表中显示 PDF 的缩略图。

问题2:我们可以将FPF转换为图像以在列表中显示缩略图吗?

jaz*_*bpn 1

正确答案:使用打印pdf插件,为了将 PDF 转换为图像,我们可以简单地通过以下方式实现:

// 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
}
Run Code Online (Sandbox Code Playgroud)