Java使用itextpdf的v7.1.11将一个长图分页转为pdf的示例
package com.elan.career.utils;
import com.itextpdf.io.IOException;
import com.itextpdf.io.image.ImageData;
import com.itextpdf.io.image.ImageDataFactory;
import com.itextpdf.kernel.geom.PageSize;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.AreaBreak;
import com.itextpdf.layout.element.Image;
import lombok.extern.slf4j.Slf4j;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.net.URL;
@Slf4j
public class Pdf2Util {
/**
* 图片文件转为pdf文件及路径
*
* @param inputImagePath
* @return
*/
public static String convertImageToPdf(String inputImagePath, String outputPdfPath) {
String returnPdfUrl = "&