我一直在使用PDFBox生成PDF文件并想知道是否可以在图像周围添加边框。如果没有,是否有一些算法可以让您有效地在图像周围绘制线条?我有以下的代码,使自己的图像添加到PDF页面:在PDFBox中制作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?
哇,更少的代码,甚至比我更尖锐的角落。真棒回答。谢谢。 – antihero989 2014-10-30 18:46:34
谢谢......作为奖励,您还可以看看setLineCapStyle和setLineJoinStyle,以查看边缘/线条末端中的不同样式。 – 2014-10-30 19:28:03
我一定会考虑一下。 – antihero989 2014-10-30 20:00:57