使用java将pdf转换为.tiff

使用java将pdf转换为.tiff,java,pdf,pdfbox,Java,Pdf,Pdfbox,我创建了一个web服务,它有一个方法,该方法接受DataHandler的参数。此方法的目的是读入通过DataHandler发送的内容并将其写入文件(.tiff)。当我传入一个.tiff文件时,我可以轻松地进行转换,但是如何使用Java将pdf文件转换为.tiff文件呢 因此,如果用户使用DataHandler传入pdf文件,我如何将其转换为.tiff文件?PDDocument doc=PDDocument.loadNonSeq(新文件(文件名),null); PDDocument doc

我创建了一个web服务,它有一个方法,该方法接受DataHandler的参数。此方法的目的是读入通过DataHandler发送的内容并将其写入文件(.tiff)。当我传入一个.tiff文件时,我可以轻松地进行转换,但是如何使用Java将pdf文件转换为.tiff文件呢

因此,如果用户使用DataHandler传入pdf文件,我如何将其转换为.tiff文件?

PDDocument doc=PDDocument.loadNonSeq(新文件(文件名),null);
    PDDocument doc = PDDocument.loadNonSeq(new File(filename), null);
    boolean b;
    List<PDPage> pages = doc.getDocumentCatalog().getAllPages();
    for (int p = 0; p < pages.size(); ++p)
    {
        // RGB image with 300 dpi
        BufferedImage bim = pages.get(p).convertToImage(BufferedImage.TYPE_INT_RGB, 300);

        // alternatively: B/W image with 300 dpi
        bim = pages.get(p).convertToImage(BufferedImage.TYPE_BYTE_BINARY, 300);

        // save as TIF with dpi in the metadata
        // PDFBox will choose the best compression for you
        // you need to add jai_imageio to your classpath for this to work
        b = ImageIOUtil.writeImage(bim, "page-" + (p+1) + ".tif", 300);
        if (!b)
        {
            // error handling
        }
    }
布尔b; 列表页面=doc.getDocumentCatalog().getAllPages(); 对于(int p=0;p
如果您的问题是关于转换为多页TIFF,请这样说,我也有一个解决方案