java使用spire.pdf去除水印


最近項目中要實現將PDF文件轉換成image圖片,以便pc端和移動端預覽,網上搜索很久后發現spire.pdf很好用。

如何通過maven引用:https://www.cnblogs.com/Yesi/p/10483565.html

 

如果PDF文件頁數小於10張,可以使用官方提供的免費版,非免費版的在轉換成的圖片中頂部會存在 Evaluation Warning : The document was created with Spire.PDF for .NET. 水印

去除方式:

public class SpirePdfUtil {
    protected static Log log = LogFactory.getLog(SpirePdfUtil.class);

    public static int aspPdfToJpg(String sourPath ,String savePath){
        int flag = 0;
        PdfDocument pdfDocument = new PdfDocument();
        pdfDocument.loadFromFile(sourPath);
        BufferedImage bufferedImage = null;
        try{
            for (int i=0;i<pdfDocument.getPages().getCount();i++){
                bufferedImage = pdfDocument.saveAsImage(i);
                bufferedImage = bufferedImage.getSubimage(bufferedImage.getMinX(),15,bufferedImage.getWidth(),bufferedImage.getHeight()-15);
                File saveFile = new File(savePath+i+".jpg");
                if(!saveFile.exists()){
                    saveFile.mkdirs();
                }
                ImageIO.write(bufferedImage,"jpg",saveFile);
                bufferedImage.flush();
            }
           flag = 1;
        }catch (Exception e){
            e.printStackTrace();
        }finally {

        }

        return flag;
    }
}

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM