In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "java how to convert word into pdf and customize the watermark", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how java converts word into pdf and customizes the watermark.
1. Rely on jar package and license.xml
Link: https://pan.baidu.com/s/1xvxXA6Wr_HKdvTis8z1FKw
Extraction code: 790o
2. Code implementation: public class Word2PdfUtil {public static void main (String [] args) {doc2pdf ("E:\\ test.doc", "E:\\ test.pdf");} / * word to pdf * / public static void doc2pdf (String inPath, String outPath) {/ / verify License if (! getLicense ()) {return } FileOutputStream os = null; try {System.out.println ("start conversion..."); / / create a new blank pdf document File file = new File (outPath); os = new FileOutputStream (file) / / for the file to be converted, add watermark Document doc = new Document (inPath); insertWatermarkText (doc, "I am the watermark"); / / fully support DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, EPUB, XPS, SWF conversion doc.save (os, SaveFormat.PDF) System.out.println ("conversion completed...");} catch (Exception e) {e.printStackTrace ();} finally {if (os! = null) {try {os.close () } catch (IOException e) {e.printStackTrace ();}} / * * verify signature * * / private static boolean getLicense () {boolean result = false; try {InputStream is = Word2PdfUtil.class.getClassLoader () .getResourceAsStream ("license.xml") License aposeLic = new License (); aposeLic.setLicense (is); result = true;} catch (Exception e) {e.printStackTrace ();} return result } / * generate watermarks for pdf * / private static void insertWatermarkText (Document doc, String watermarkText) throws Exception {System.out.println ("start adding watermarks..."); Shape watermark = new Shape (doc, ShapeType.TEXT_PLAIN_TEXT); / / watermark content watermark.getTextPath (). SetText (watermarkText) / / Watermark font watermark.getTextPath (). SetFontFamily ("Song style"); / / Watermark width watermark.setWidth (500); / / Watermark height watermark.setHeight (100); / / rotate watermark watermark.setRotation (- 40); / / Watermark color watermark.getFill (). SetColor (Color.lightGray) Watermark.setStrokeColor (Color.lightGray); watermark.setRelativeHorizontalPosition (RelativeHorizontalPosition.PAGE); watermark.setRelativeVerticalPosition (RelativeVerticalPosition.PAGE); watermark.setWrapType (WrapType.NONE); watermark.setVerticalAlignment (VerticalAlignment.CENTER); watermark.setHorizontalAlignment (HorizontalAlignment.CENTER); Paragraph watermarkPara = new Paragraph (doc); watermarkPara.appendChild (watermark) For (Section sect: doc.getSections ()) {insertWatermarkIntoHeader (watermarkPara, sect, HeaderFooterType.HEADER_PRIMARY); insertWatermarkIntoHeader (watermarkPara, sect, HeaderFooterType.HEADER_FIRST); insertWatermarkIntoHeader (watermarkPara, sect, HeaderFooterType.HEADER_EVEN);} System.out.println ("end adding watermark.") } private static void insertWatermarkIntoHeader (Paragraph watermarkPara, Section sect, int headerType) throws Exception {HeaderFooter header = sect.getHeadersFooters () .getByHeaderFooterType (headerType); if (header = = null) {header = new HeaderFooter (sect.getDocument (), headerType); sect.getHeadersFooters (). Add (header);} header.appendChild (watermarkPara.deepClone (true)) } 3. Note: if you prompt javaSoft to register for permission issues
Open the registry (regedit), find HKEY_LOCAL_MACHINE\ SOFTWARE\ JavaSoft, and right-click to change the permission to full license.
At this point, I believe you have a deeper understanding of "java how to convert word into pdf and customize the watermark". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.