我的應用程式使用此代碼創建 pdf
public void createPdf(String dest, int pageNum, int pageHeight, int pageWidth) throws IOException, DocumentException {
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream(dest));
document.open();
document.setPageCount(pageNum);
for (Uri image : allSelectedImages) {
Image img = Image.getInstance(image.getPath());
document.setPageSize(new Rectangle(pageHeight, pageWidth));
document.newPage();
document.add(img);
document.addAuthor("PDF Reader Osdifa's User");
document.addCreator("PDF Reader Osdifa");
}
document.close();
}
問題是當用戶選擇比頁面尺寸更小的影像時,它會移動到左上角

我試過了
img.setAbsolutePosition(pageHeight/2, pageWidth/2);
如果影像大于頁面大小,它會超出頁面我想將影像大小縮小到頁面大小

uj5u.com熱心網友回復:
我已將此影像位置更改為
img.setAbsolutePosition(pageHeight/2, pageWidth/2);
這和它的作業原理
img.setAbsolutePosition(pageHeight / 2 - img.getWidth() / 2, pageWidth / 2 - img.getHeight() / 2);
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/311218.html
上一篇:我可以使用訊息代理將PDF或MSWord檔案內容作為XML流式傳輸嗎?
下一篇:瀏覽器擴展清單權限V3
