我一直在使用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