Java PDF는 레이어를 추가하고 다음과 같이 다중 페이지 레이어 첨가를 지원합니다.
암호:
가져 오기 java.io.file; import java.io.fileoutputStream; import java.io.ioexception; import java.util.list; import com.ithtpdf.text.documentexception; import com.text.image; import com.ithtpdf.text.pdf.pdfcontbyte; com.ithtpdf.text.pdf.pdfreader; import com.ithtpdf.text.pdf.pdfstamper; public class pdfutils { /** * pdfadd layer * * @param srcpdf * 원래 pdf 파일 경로 * @param distpdf * @param puteR * @paramer pather * @paramer pather * @param distpdf * @param distpdf * 이름은 숫자 (이미지 이름 및 숫자 순서대로 PDF에 해당하는 페이지 수에 결합되어 있어야합니다) * @return * @Throws IOException * @throws documentException */ public static string Marklocalimage42dist (String Srcpdf, String Distpdf, List <string> layerPatharr) IoException, doccordexception {file srcc {file src v { 파일 (srcpdf); if (! srcpdffile.exists ()) {new new OregalArgumentException ( "레이어에 추가 해야하는 PDF 파일을 찾을 수 없습니다"); } pdfreader reader = new pdfreader (srcpdf); int n = reader.getNumberOfPages (); // pdf 페이지 수 pdfstamper stamp = new PdfStamper (Reader, New FileOutputStream (distpdf)); pdfcontentByte Over; for (String LayerPath : LayerPatharr) {File LayerFile = 새 파일 (LayerPath); 문자열 currentpageno = layerfile.getname (). substring (0, layerfile.getname (). lastIndexof ( ".")); // 이미지 이름 (페이지 수에 해당) 부울 isnum = currentpageno.matches ( "[0-9]+"); if (! isnum) {새로운 불법 불법 행위 렉싱 ( "레이어 이름은 숫자"); } image img = image.getInstance (LayerPath); img.setabsoluteposition (0, 0); if (n> 0 && n> = integer.parseint (currentpageno)) {over = stamp.getOverContent (integer.pageno (currentpageno)); Over.addimage (IMG); }} stamp.close (); reader.close (); return distpdf; }}시험:
public static void main (String [] args)은 ioexception, documentException {list <string> imgurllist = new ArrayList <> (); imgurllist.add ( "d : /ts/testpdf/1.png"); //imgurllist.add("d:/ts/testpdf/2.png "); imgurllist.add ( "d : /ts/testpdf/3.png"); marklocalimage42dist ( "d : /ts/testpdf/testpdf.pdf", "d : /ts/testpdf/testpdf2.pdf", imgurllist); }결과:
원래 PDF :
합성 후 PDF :
위는이 기사의 모든 내용입니다. 모든 사람의 학습에 도움이되기를 바랍니다. 모든 사람이 wulin.com을 더 지원하기를 바랍니다.