我在Eclipse中使用iTextpdf库将图像转换为pdf,但是只有图像的特定部分转换为pdf,而不是整个图像。该怎么办?
import java.io.FileOutputStream;
import com.itextpdf.text.Document;
import com.itextpdf.text.pdf.PdfWriter;
import com.itextpdf.text.Image;
public class ImageToPDF {
public static void main(String ... args) {
Document document = new Document();
String input = "D:/download.png";
String output = "D:/capture.pdf";
try {
FileOutputStream fos = new FileOutputStream(output);
PdfWriter writer = PdfWriter.getInstance(document, fos);
writer.open();
document.open();
document.add(Image.getInstance(input));
document.close();
writer.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
}