{"id":2283,"date":"2024-01-24T21:56:42","date_gmt":"2024-01-24T13:56:42","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=2283"},"modified":"2024-01-24T21:56:53","modified_gmt":"2024-01-24T13:56:53","slug":"java-itext-watermark","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2024\/01\/24\/java-itext-watermark\/","title":{"rendered":"Java\u7684itext\u5e38\u89c1\u65b9\u6cd5\u603b\u7ed3&#8211;3\uff08\u6c34\u5370\uff09"},"content":{"rendered":"<pre><code class=\"language-java\">Document document = new Document();\n\nPdfWriter pdfWriter = PdfWriter.getInstance(document,new FileOutputStream(PDF\u6587\u4ef6\u7684\u5730\u5740));\n\n\/\/\u83b7\u53d6PDF\u7684\u5185\u5bb9\u5b57\u8282\nPdfContentByte waterMar =\u00a0pdfWriter.getDirectContent();\n\n\/\/\u52a0\u8f7d\u6587\u672c\nwaterMar.beginText();\n\nPdfGState gs = new PdfGState();\n\/\/\u8bbe\u7f6e\u7b14\u89e6\u5b57\u4f53\u4e0d\u900f\u660e\u5ea6\u4e3a 1f\ngs.setStrokeOpacity(1f);\n\nwaterMar.setGState(gs);\n\n\/\/\u8bbe\u7f6e\u6c34\u5370\u989c\u8272\u4e3a\u9ed1\u8272\nwaterMar.setColorFill(BaseColor.BLACK);\n\n\/\/\u8bbe\u7f6e\u5b57\u4f53\nwaterMar.setFontAndSize(BaseFont.createFont(\u5b57\u4f53\u6587\u4ef6\u5730\u5740, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED), \u5b57\u4f53\u5927\u5c0f);\n\n\/\/\u6c34\u5370\u7684\u4f4d\u7f6e\u5750\u6807\nwaterMar.setTextMatrix(115, 630);\n\n\/\/\u6c34\u5370\u7684\u5185\u5bb9\nwaterMar.showText(text);<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Document document = new Document(); PdfWriter pdfWriter [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43],"tags":[574],"class_list":["post-2283","post","type-post","status-publish","format-standard","hentry","category-java-basic","tag-itext"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/2283","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=2283"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/2283\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=2283"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=2283"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=2283"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}