此代码用于水平显示pdf文本,如何在pdf页面上将其垂直更改
private void stampPdf(InputStream source, OutputStream dest) throws Exception {
PdfDocument pdfDoc = new PdfDocument(new PdfReader(source), new PdfWriter(dest));
Document doc = new Document(pdfDoc);
Paragraph header = new Paragraph("Received by on")
.setFont(PdfFontFactory.createFont(FontConstants.HELVETICA))
.setFontSize(14)
.setFontColor(Color.RED).setRotationAngle(90);
for (int i = 1; i <= pdfDoc.getNumberOfPages(); i++) {
float x = pdfDoc.getPage(i).getPageSize().getLeft();
float y = pdfDoc.getPage(i).getPageSize().getTop() -30;
doc.showTextAligned(header.setFontColor(Color.RED), x, y, i,
TextAlignment.RIGHT, VerticalAlignment.TOP, 0);
}
doc.close();
}
最佳答案
更换
doc.showTextAligned(header.setFontColor(Color.RED), x, y, i,
TextAlignment.RIGHT, VerticalAlignment.TOP, 0);
与
doc.showTextAligned(header.setFontColor(Color.RED), x, y, i,
TextAlignment.RIGHT, VerticalAlignment.TOP, 90);
关于java - 此代码用于水平显示pdf文本,如何在pdf页面上将其垂直更改,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49401008/