itext html 生成pdf

String urlPath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath() +"/ssl/test.htm";
			 URL url = new URL(urlPath);  
	         URLConnection rulConnection = url.openConnection();  
	         HttpURLConnection httpUrlConnection = (HttpURLConnection) rulConnection; 
			
			 // step 1
	        Document document = new Document();
	        // step 2
	        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("D:/TEST.pdf"));
	        // step 3
	        document.open();
	        // step 4
	        XMLWorkerHelper.getInstance().parseXHtml(writer, document,httpUrlConnection.getInputStream(), Charset.forName("UTF-8"));
	        // step 5
	        document.close();

 

Maven:

<dependency>
		  <groupId>com.itextpdf</groupId>
		  <artifactId>itext-xtra</artifactId>
		  <version>5.5.3</version>
		</dependency>
		<dependency>
		  <groupId>com.itextpdf</groupId>
		  <artifactId>itextpdf</artifactId>
		  <version>5.5.3</version>
		</dependency>
		<dependency>
		  <groupId>com.itext</groupId>
		  <artifactId>itext-pdfa</artifactId>
		  <version>5.5.3</version>
		</dependency>
		<dependency>
		  <groupId>com.itext</groupId>
		  <artifactId>itext-asian</artifactId>
		  <version>5.1.1</version>
		</dependency>
		<dependency>
		  <groupId>com.itextpdf</groupId>
		  <artifactId>xmlworker</artifactId>
		  <version>5.5.3</version>
		</dependency>

 

你可能感兴趣的:(itext)