如何在旋转pdf中添加文本Stamp注释

时间:2016-04-22 05:58:02

标签: rotation annotations stamp

我想将带有文本的图章注释添加到pdf中。 pdf的轮换是270。

我写的代码,但邮票轮换错误。

PdfReader reader = new PdfReader(file.getAbsolutePath(), "PDF".getBytes());
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(outFile));
int i = 1;
PdfContentByte content = stamper.getOverContent(i);
Rectangle pageRect = reader.getPageSizeWithRotation(i);
float pageWidth = pageRect.getWidth();
float pageHeight = pageRect.getHeight();
float rectWidth = 700;
float rectHeight = 500;
float fontsize = 40;
content.setFontAndSize(font, fontsize);
rectWidth = content.getEffectiveStringWidth(stampLabel,false);
Rectangle rectangle = new Rectangle(0,0,rectWidth, rectHeight);
PdfAppearance appearance = content.createAppearance(rectWidth,rectHeight);
appearance.setColorFill(BaseColor.RED);
appearance.setFontAndSize(font, fontsize);      
rectangle.setBorder(Rectangle.BOX);
rectangle.setBorderColor(BaseColor.RED);
rectangle.setBorderWidth(2);
appearance.rectangle(rectangle);
appearance.saveState();
appearance.beginText();
appearance.showText(stampLabel);
appearance.restoreState();
PdfAnnotation stampAnnot =   PdfAnnotation.createStamp(content.getPdfWriter(),    rectangle,stampLabel,"STATUA_STAMP");
stampAnnot.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, appearance);
stampAnnot.setFlags(PdfAnnotation.FLAGS_PRINT);         
stamper.addAnnotation(stampAnnot, i);

0 个答案:

没有答案