【发布时间】:2014-10-29 20:59:44
【问题描述】:
我一直在使用 PDFBox 生成 pdf 文件,想知道是否可以在图像周围添加边框。如果没有,是否有一些算法可以让您有效地在图像周围精确地画线?我有以下代码允许自己将图像添加到 pdf 页面:
//image for page 2
public File processPDF()
{
//creating pdf
PDDocument document = new PDDocument();
File file = new File("NWProofReference.pdf");
//adding first page to pdf, blank
PDPage page = new PDPage();
PDPageContentStream contentStream;
try {
BufferedImage awtImage = ImageIO.read(new File(PDFProcessing.image));
PDXObjectImage ximage = new PDPixelMap(document, awtImage);
float scale = 1.0f; // alter this value to set the image size
contentStream.drawXObject(ximage,100,400,
(ximage.getWidth()*scale,ximage.getHeight()*scale);
contentStream.close();
document.save(file);
document.close();
} catch (Exception e)
{
e.printStackTrace();
}
return file;
}
使用此代码或任何代码,有没有办法在通过 PDFBox API 提供的图像本身周围实际添加边框?
【问题讨论】: