jar: itext-4.2.1.jar
Absolute positioning is required for the signing of many official documents, so record this code as follows:
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream( "test.pdf" ));
PdfContentByte cb = writer.getDirectContent();
BaseFont bf = BaseFont.createFont( "STSong-Light" , "UniGB-UCS2-H" ,BaseFont.EMBEDDED);
cb .beginText();
cb .setFontAndSize(bf, 12 );
cb .showTextAligned(PdfContentByte.ALIGN_CENTER, text + "This text is centered" , 250 , 700 , 0 );
cb .endText();
Sometimes the absolute positioning of the picture (official seal) is also needed:
Image image = Image.getInstance(request.getSession().getServletContext().getRealPath( "/" )+ "common/images/starpilot/signet.png" );
image .scaleAbsolute(mmTopx( 40 ), mmTopx( 39 ));
image .setAbsolutePosition( 400 , flagHeight);
document .add(image);
Read More:
- JAVA: How to Convert PDF from Color to Grayscale
- JAVA: How to use the third-party font library method (using the third-party TTF / TTC font library method)
- Java will convert Excel to list set or JSON, export excel file to local, excel import and export, easyexcel tool class
- JAVA: How to Use Minio to upload pictures
- Java implementation of inputsteam to Base64
- JAVA: How to Use Multipartfile to upload Files
- OpenFeignClient Use Object to Receive text/plain Type Return Error
- [PROJECT] itdage java to get the weather and send text messages
- Java: How to Find the Minimum Value from a Random Array by Bubble Sort Method
- Linux: How to Solve jdk11+easy poi Export Excel Error
- The thread implementation of timer in Java
- Implementation of retrial mechanism in Java
- Java callback function implementation case
- Abstract method and static method of java interface
- How to Solve java server error (java application Run Normally)
- How to Use filechannel to copy files
- [Solved] Java POI export error: Invalid row number (65536) outside allowable range
- How to Converte Java objects to jsonnode in Jackson (Four Methods)
- How to Solve Springboot use thymeleaf template error
- JAVA 8: How to Convert List to Map