html转pdf

//import com.fasterxml.jackson.annotation.JsonFormat;
//import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
//import com.fasterxml.jackson.annotation.JsonInclude;
//import com.fasterxml.jackson.databind.ObjectMapper;
//import com.fasterxml.jackson.dataformat.xml.XmlMapper;
//import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlCData;
//import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
//import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
//import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
//import java.io.BufferedOutputStream;
//import java.io.BufferedReader;
//import java.io.ByteArrayInputStream;
//import java.io.FileOutputStream;
//import java.io.IOException;
//import java.io.InputStream;
//import java.io.InputStreamReader;
//import java.io.OutputStream;
//import java.nio.charset.StandardCharsets;
//import java.nio.file.Files;
//import java.nio.file.LinkOption;
//import java.nio.file.Path;
//import java.nio.file.Paths;
//import java.time.LocalDate;
//import java.time.LocalDateTime;
//import java.util.ArrayList;
//import java.util.List;
//import javax.xml.transform.Result;
//import javax.xml.transform.Source;
//import javax.xml.transform.Transformer;
//import javax.xml.transform.TransformerFactory;
//import javax.xml.transform.sax.SAXResult;
//import javax.xml.transform.stream.StreamSource;
//import lombok.Data;
//import lombok.experimental.Accessors;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.fop.apps.FOUserAgent;
//import org.apache.fop.apps.Fop;
//import org.apache.fop.apps.FopFactory;
//import org.apache.fop.apps.MimeConstants;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.stereotype.Component;
//
//@Slf4j
//@Component
//public class HtmlToPDF {
//
// //方式一:使用Apache FOP
// //方式二:使用Wkhtmltopdf工具
//
// //模板文件路径
// @Value(" p d f . f o p . t e m p . p a t h " ) / / p r i v a t e f i n a l S t r i n g t e m p l a t e F i l e P a t h = " G : I D E A A N H U A N y a n g z i t a r g e t c l a s s e s f o p t e m p " ; / / / / P D F 文 件 输 出 路 径 / / @ V a l u e ( " {pdf.fop.temp.path}") // private final String templateFilePath = "G:\\IDEA\\ANHUAN\\yangzi\\target\\classes\\fop\\temp\\"; // //PDF文件输出路径 // @Value(" pdf.fop.temp.path")//privatefinalStringtemplateFilePath="G:IDEAANHUANyangzitargetclassesfoptemp";////PDF//@Value("{pdf.out.path}")
// private final String outFilePath = “G:\”;
//
// //private final FopFactory fopFactory;
// public HtmlToPDF() {
// //fopFactory = FopFactory.newInstance(Paths.get(configFile).toFile());
// }
//
// //配置文件路径
// @Value(" p d f . f o p . c o n f . f i l e " ) / / p r i v a t e f i n a l S t r i n g c o n f i g F i l e = " G : I D E A A N H U A N y a n g z i t a r g e t c l a s s e s f o p c o n f f o p . x c o n f " ; / / / / / ∗ ∗ / / ∗ 使 用 A p a c h e F O P / / ∗ / / ∗ @ p a r a m t e m p D e f F i l e N a m e 模 板 定 义 文 件 名 称 / / ∗ @ p a r a m o u t F i l e N a m e 输 出 的 P D F 文 件 名 称 / / ∗ @ p a r a m s o u r c e 模 板 填 充 内 容 / / ∗ @ t h r o w s E x c e p t i o n 异 常 / / ∗ / / / p u b l i c v o i d c o n v e r t ( S t r i n g t e m p D e f F i l e N a m e , S t r i n g o u t F i l e N a m e , S t r i n g s o u r c e ) / / t h r o w s E x c e p t i o n / / f i n a l F o p F a c t o r y f o p F a c t o r y = F o p F a c t o r y . n e w I n s t a n c e ( P a t h s . g e t ( c o n f i g F i l e ) . t o F i l e ( ) ) ; / / F O U s e r A g e n t f o U s e r A g e n t = f o p F a c t o r y . n e w F O U s e r A g e n t ( ) ; / / t r y ( O u t p u t S t r e a m o u t = n e w B u f f e r e d O u t p u t S t r e a m ( / / n e w F i l e O u t p u t S t r e a m ( o u t F i l e P a t h + o u t F i l e N a m e ) ) ) / / F o p f o p = f o p F a c t o r y . n e w F o p ( M i m e C o n s t a n t s . M I M E P D F , f o U s e r A g e n t , / / o u t ) ; / / C o n s t r u c t f o p w i t h d e s i r e d o u t p u t f o r m a t / / T r a n s f o r m e r F a c t o r y f a c t o r y = T r a n s f o r m e r F a c t o r y . n e w I n s t a n c e ( ) ; / / T r a n s f o r m e r t r a n s f o r m e r = f a c t o r y / / . n e w T r a n s f o r m e r ( n e w S t r e a m S o u r c e ( t e m p l a t e F i l e P a t h + t e m p D e f F i l e N a m e ) ) ; / / S e t u p X S L T / / t r a n s f o r m e r / / . s e t P a r a m e t e r ( " v e r s i o n P a r a m " , " 2.0 " ) ; / / S e t t h e v a l u e o f a < p a r a m > i n t h e s t y l e s h e e t / / I n p u t S t r e a m i n p u t S t r e a m = n e w B y t e A r r a y I n p u t S t r e a m ( s o u r c e . g e t B y t e s ( ) ) ; / / S o u r c e s r c = n e w S t r e a m S o u r c e ( i n p u t S t r e a m ) ; / / S e t u p i n p u t f o r X S L T t r a n s f o r m a t i o n / / R e s u l t r e s = n e w S A X R e s u l t ( / / f o p . g e t D e f a u l t H a n d l e r ( ) ) ; / / R e s u l t i n g S A X e v e n t s ( t h e g e n e r a t e d F O ) m u s t b e p i p e d t h r o u g h t o F O P / / t r a n s f o r m e r . t r a n s f o r m ( s r c , r e s ) ; / / S t a r t X S L T t r a n s f o r m a t i o n a n d F O P p r o c e s s i n g / / / / / / / / p r i v a t e S t r i n g b u i l d P D F S o u r c e ( ) t h r o w s E x c e p t i o n / / O b j e c t M a p p e r o b j e c t M a p p e r = n e w O b j e c t M a p p e r ( ) ; / / o b j e c t M a p p e r . f i n d A n d R e g i s t e r M o d u l e s ( ) ; / / X m l M a p p e r x m l M a p p e r = n e w X m l M a p p e r ( ) ; / / x m l M a p p e r . f i n d A n d R e g i s t e r M o d u l e s ( ) ; / / / / x m l M a p p e r . c o n f i g u r e ( D e s e r i a l i z a t i o n F e a t u r e . F A I L O N U N K N O W N P R O P E R T I E S , f a l s e ) ; / / / / x m l M a p p e r . c o n f i g u r e ( S e r i a l i z a t i o n F e a t u r e . W R A P R O O T V A L U E , f a l s e ) ; / / / / x m l M a p p e r . s e t S e r i a l i z a t i o n I n c l u s i o n ( J s o n I n c l u d e . I n c l u d e . N O N N U L L ) ; / / / / x m l M a p p e r . s e t P r o p e r t y N a m i n g S t r a t e g y ( P r o p e r t y N a m i n g S t r a t e g y . U P P E R C A M E L C A S E ) ; / / / / x m l M a p p e r . e n a b l e ( M a p p e r F e a t u r e . U S E S T D B E A N N A M I N G ) ; / / P D F D e m o p d f D e m o = n e w P D F D e m o ( ) . s e t D e m o N o ( " X T 00001 " ) . s e t D e m o D a t e ( L o c a l D a t e . n o w ( ) ) ; / / D e m o d e m o ; / / L i s t < D e m o > l i s t = n e w A r r a y L i s t < > ( ) ; / / f o r ( i n t i = 10 ; i < 12 ; i + + ) / / d e m o = n e w D e m o ( ) . s e t I d ( i ) . s e t N a m e ( " m e m b e r " + i ) . s e t L o c a l D a t e ( L o c a l D a t e . n o w ( ) ) / / . s e t L o c a l D a t e T i m e ( L o c a l D a t e T i m e . n o w ( ) ) ; / / l i s t . a d d ( d e m o ) ; / / / / p d f D e m o . s e t D e m o L i s t ( l i s t ) ; / / / / S t r i n g r e s u l t F o r J s o n = o b j e c t M a p p e r . w r i t e V a l u e A s S t r i n g ( p d f D e m o ) ; / / l o g . d e b u g ( r e s u l t F o r J s o n ) ; / / S t r i n g r e s u l t = x m l M a p p e r . w r i t e V a l u e A s S t r i n g ( p d f D e m o ) ; / / l o g . d e b u g ( r e s u l t ) ; / / r e t u r n r e s u l t ; / / / / / / p u b l i c v o i d k k k ( ) / / S y s t e m . o u t . p r i n t l n ( t h i s . g e t C l a s s ( ) . g e t R e s o u r c e ( / / " " ) ) ; / / f i l e : / G : / I D E A / A N H U A N / y a n g z i / t a r g e t / c l a s s e s / c o m / l c / y a n g z i / f r a m e w o r k / u t i l i t y / / / S y s t e m . o u t / / . p r i n t l n ( t h i s . g e t C l a s s ( ) . g e t R e s o u r c e ( " / " ) ) ; / / f i l e : / G : / I D E A / A N H U A N / y a n g z i / t a r g e t / c l a s s e s / / / / / R e s o u r c e r e s o u r c e = n e w C l a s s P a t h R e s o u r c e ( " r e s o u r c e . p r o p e r t i e s " ) ; / / / / / / p u b l i c s t a t i c v o i d m a i n ( S t r i n g [ ] a r g s ) t h r o w s E x c e p t i o n / / H t m l T o P D F h t m l T o P D F = n e w H t m l T o P D F ( ) ; / / / / h t m l T o P D F . c o n v e r t ( " e x a m p l e T e m p D e f . x s l " , " P D F D e m o . p d f " , h t m l T o P D F . b u i l d P D F S o u r c e ( ) ) ; / / / / h t m l T o P D F . c o n v e r t ( " e x a m p l e T e m p D e f 1. x s l " , " P D F D e m o . p d f " , h t m l T o P D F . b u i l d P D F S o u r c e ( ) ) ; / / / / h t m l T o P D F . k k k ( ) ; / / / / h t m l T o P D F . c o n v e r t ( " h t t p : / / w w w . b a i d u . c o m " , " b a i d u . p d f " ) ; / / / / h t m l T o P D F . c o n v e r t ( " F : / p d f / x x x . h t m l " , " x x x . p d f " ) ; / / / / / / @ D a t a / / @ A c c e s s o r s ( c h a i n = t r u e ) / / @ J s o n I g n o r e P r o p e r t i e s ( i g n o r e U n k n o w n = t r u e ) / / @ J s o n I n c l u d e ( J s o n I n c l u d e . I n c l u d e . N O N E M P T Y ) / / @ J a c k s o n X m l R o o t E l e m e n t ( l o c a l N a m e = " D e m o " ) / / s t a t i c c l a s s D e m o / / / / p r i v a t e l o n g i d ; / / @ J a c k s o n X m l C D a t a / / p r i v a t e S t r i n g n a m e ; / / @ J s o n F o r m a t ( p a t t e r n = " y y y y − M M − d d " , t i m e z o n e = " G M T + 8 " ) / / p r i v a t e L o c a l D a t e l o c a l D a t e ; / / @ J s o n F o r m a t ( s h a p e = J s o n F o r m a t . S h a p e . S T R I N G , p a t t e r n = " y y y y − M M − d d H H : m m : s s " , t i m e z o n e = " G M T + 8 " ) / / p r i v a t e L o c a l D a t e T i m e l o c a l D a t e T i m e ; / / / / / / @ J a c k s o n X m l E l e m e n t W r a p p e r ( l o c a l N a m e = " D E M O − M A P " ) / / / / p r i v a t e M a p < S t r i n g , D e m o > m a p ; / / / / @ J a c k s o n X m l P r o p e r t y ( l o c a l N a m e = " e l e m e n t S t r i n g " ) / / / / p r i v a t e S t r i n g e l e m e n t S t r i n g ; / / / / @ J a c k s o n X m l P r o p e r t y ( l o c a l N a m e = " a t t r i b u t e S t r i n g " , i s A t t r i b u t e = t r u e ) / / / / p r i v a t e S t r i n g a t t r i b u t e S t r i n g ; / / / / / / @ D a t a / / @ A c c e s s o r s ( c h a i n = t r u e ) / / @ J s o n I g n o r e P r o p e r t i e s ( i g n o r e U n k n o w n = t r u e ) / / @ J s o n I n c l u d e ( J s o n I n c l u d e . I n c l u d e . N O N E M P T Y ) / / @ J a c k s o n X m l R o o t E l e m e n t ( l o c a l N a m e = " P D F D e m o " ) / / s t a t i c c l a s s P D F D e m o / / / / p r i v a t e S t r i n g d e m o N o ; / / @ J s o n F o r m a t ( p a t t e r n = " y y y y − M M − d d " , t i m e z o n e = " G M T + 8 " ) / / p r i v a t e L o c a l D a t e d e m o D a t e ; / / @ J a c k s o n X m l E l e m e n t W r a p p e r ( l o c a l N a m e = " D E M O − L I S T " , u s e W r a p p i n g = f a l s e ) / / @ J a c k s o n X m l P r o p e r t y ( l o c a l N a m e = " D E M O − L I S T − E L E M E N T " ) / / p r i v a t e L i s t < D e m o > d e m o L i s t ; / / / / / / / / − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − w k h t m l t o p d f − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − / / / / 下 载 地 址 : h t t p s : / / w k h t m l t o p d f . o r g / d o w n l o a d s . h t m l / / / / w k h t m l t o p d f 在 系 统 中 的 路 径 / / @ V a l u e ( " {pdf.fop.conf.file}") // private final String configFile = "G:\\IDEA\\ANHUAN\\yangzi\\target\\classes\\fop\\conf\\fop.xconf"; // // /** // * 使用Apache FOP // * // * @param tempDefFileName 模板定义文件名称 // * @param outFileName 输出的PDF文件名称 // * @param source 模板填充内容 // * @throws Exception 异常 // */ // public void convert(String tempDefFileName, String outFileName, String source) // throws Exception { // final FopFactory fopFactory = FopFactory.newInstance(Paths.get(configFile).toFile()); // FOUserAgent foUserAgent = fopFactory.newFOUserAgent(); // try (OutputStream out = new BufferedOutputStream( // new FileOutputStream(outFilePath + outFileName))) { // Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, // out);// Construct fop with desired output format // TransformerFactory factory = TransformerFactory.newInstance(); // Transformer transformer = factory // .newTransformer(new StreamSource(templateFilePath + tempDefFileName));// Setup XSLT // transformer // .setParameter("versionParam", "2.0");// Set the value of a <param> in the stylesheet // InputStream inputStream = new ByteArrayInputStream(source.getBytes()); // Source src = new StreamSource(inputStream);// Setup input for XSLT transformation // Result res = new SAXResult( // fop.getDefaultHandler());// Resulting SAX events (the generated FO) must be piped through to FOP // transformer.transform(src, res);// Start XSLT transformation and FOP processing // } // } // // private String buildPDFSource() throws Exception { // ObjectMapper objectMapper = new ObjectMapper(); // objectMapper.findAndRegisterModules(); // XmlMapper xmlMapper = new XmlMapper(); // xmlMapper.findAndRegisterModules(); // //xmlMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); // //xmlMapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false); // //xmlMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); // //xmlMapper.setPropertyNamingStrategy(PropertyNamingStrategy.UPPER_CAMEL_CASE); // //xmlMapper.enable(MapperFeature.USE_STD_BEAN_NAMING); // PDFDemo pdfDemo = new PDFDemo().setDemoNo("XT00001").setDemoDate(LocalDate.now()); // Demo demo; // List<Demo> list = new ArrayList<>(); // for (int i = 10; i < 12; i++) { // demo = new Demo().setId(i).setName("member" + i).setLocalDate(LocalDate.now()) // .setLocalDateTime(LocalDateTime.now()); // list.add(demo); // } // pdfDemo.setDemoList(list); // // String resultForJson = objectMapper.writeValueAsString(pdfDemo); // log.debug(resultForJson); // String result = xmlMapper.writeValueAsString(pdfDemo); // log.debug(result); // return result; // } // // public void kkk() { // System.out.println(this.getClass().getResource( // ""));//file:/G:/IDEA/ANHUAN/yangzi/target/classes/com/lc/yangzi/framework/utility/ // System.out // .println(this.getClass().getResource("/"));//file:/G:/IDEA/ANHUAN/yangzi/target/classes/ // //Resource resource = new ClassPathResource("resource.properties"); // } // // public static void main(String[] args) throws Exception { // HtmlToPDF htmlToPDF = new HtmlToPDF(); // //htmlToPDF.convert("exampleTempDef.xsl","PDFDemo.pdf", htmlToPDF.buildPDFSource()); // //htmlToPDF.convert("exampleTempDef1.xsl","PDFDemo.pdf", htmlToPDF.buildPDFSource()); // //htmlToPDF.kkk(); // // htmlToPDF.convert("http://www.baidu.com", "baidu.pdf"); // //htmlToPDF.convert("F:/pdf/xxx.html", "xxx.pdf"); // } // // @Data // @Accessors(chain = true) // @JsonIgnoreProperties(ignoreUnknown = true) // @JsonInclude(JsonInclude.Include.NON_EMPTY) // @JacksonXmlRootElement(localName = "Demo") // static class Demo { // // private long id; // @JacksonXmlCData // private String name; // @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") // private LocalDate localDate; // @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") // private LocalDateTime localDateTime; // @JacksonXmlElementWrapper(localName = "DEMO-MAP") private Map<String,Demo> map; @JacksonXmlProperty(localName = "elementString") private String elementString; @JacksonXmlProperty(localName = "attributeString",isAttribute = true) private String attributeString; // } // // @Data // @Accessors(chain = true) // @JsonIgnoreProperties(ignoreUnknown = true) // @JsonInclude(JsonInclude.Include.NON_EMPTY) // @JacksonXmlRootElement(localName = "PDFDemo") // static class PDFDemo { // // private String demoNo; // @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") // private LocalDate demoDate; // @JacksonXmlElementWrapper(localName = "DEMO-LIST", useWrapping = false) // @JacksonXmlProperty(localName = "DEMO-LIST-ELEMENT") // private List<Demo> demoList; // } // ---------------------------------------- wkhtmltopdf ---------------------------------------- // //下载地址:https://wkhtmltopdf.org/downloads.html // //wkhtmltopdf在系统中的路径 // @Value(" pdf.fop.conf.file")//privatefinalStringconfigFile="G:IDEAANHUANyangzitargetclassesfopconffop.xconf";///////使ApacheFOP////@paramtempDefFileName//@paramoutFileNamePDF//@paramsource//@throwsException/////publicvoidconvert(StringtempDefFileName,StringoutFileName,Stringsource)//throwsException//finalFopFactoryfopFactory=FopFactory.newInstance(Paths.get(configFile).toFile());//FOUserAgentfoUserAgent=fopFactory.newFOUserAgent();//try(OutputStreamout=newBufferedOutputStream(//newFileOutputStream(outFilePath+outFileName)))//Fopfop=fopFactory.newFop(MimeConstants.MIMEPDF,foUserAgent,//out);//Constructfopwithdesiredoutputformat//TransformerFactoryfactory=TransformerFactory.newInstance();//Transformertransformer=factory//.newTransformer(newStreamSource(templateFilePath+tempDefFileName));//SetupXSLT//transformer//.setParameter("versionParam","2.0");//Setthevalueofa<param>inthestylesheet//InputStreaminputStream=newByteArrayInputStream(source.getBytes());//Sourcesrc=newStreamSource(inputStream);//SetupinputforXSLTtransformation//Resultres=newSAXResult(//fop.getDefaultHandler());//ResultingSAXevents(thegeneratedFO)mustbepipedthroughtoFOP//transformer.transform(src,res);//StartXSLTtransformationandFOPprocessing////////privateStringbuildPDFSource()throwsException//ObjectMapperobjectMapper=newObjectMapper();//objectMapper.findAndRegisterModules();//XmlMapperxmlMapper=newXmlMapper();//xmlMapper.findAndRegisterModules();////xmlMapper.configure(DeserializationFeature.FAILONUNKNOWNPROPERTIES,false);////xmlMapper.configure(SerializationFeature.WRAPROOTVALUE,false);////xmlMapper.setSerializationInclusion(JsonInclude.Include.NONNULL);////xmlMapper.setPropertyNamingStrategy(PropertyNamingStrategy.UPPERCAMELCASE);////xmlMapper.enable(MapperFeature.USESTDBEANNAMING);//PDFDemopdfDemo=newPDFDemo().setDemoNo("XT00001").setDemoDate(LocalDate.now());//Demodemo;//List<Demo>list=newArrayList<>();//for(inti=10;i<12;i++)//demo=newDemo().setId(i).setName("member"+i).setLocalDate(LocalDate.now())//.setLocalDateTime(LocalDateTime.now());//list.add(demo);////pdfDemo.setDemoList(list);////StringresultForJson=objectMapper.writeValueAsString(pdfDemo);//log.debug(resultForJson);//Stringresult=xmlMapper.writeValueAsString(pdfDemo);//log.debug(result);//returnresult;//////publicvoidkkk()//System.out.println(this.getClass().getResource(//""));//file:/G:/IDEA/ANHUAN/yangzi/target/classes/com/lc/yangzi/framework/utility///System.out//.println(this.getClass().getResource("/"));//file:/G:/IDEA/ANHUAN/yangzi/target/classes/////Resourceresource=newClassPathResource("resource.properties");//////publicstaticvoidmain(String[]args)throwsException//HtmlToPDFhtmlToPDF=newHtmlToPDF();////htmlToPDF.convert("exampleTempDef.xsl","PDFDemo.pdf",htmlToPDF.buildPDFSource());////htmlToPDF.convert("exampleTempDef1.xsl","PDFDemo.pdf",htmlToPDF.buildPDFSource());////htmlToPDF.kkk();////htmlToPDF.convert("http://www.baidu.com","baidu.pdf");////htmlToPDF.convert("F:/pdf/xxx.html","xxx.pdf");//////@Data//@Accessors(chain=true)//@JsonIgnoreProperties(ignoreUnknown=true)//@JsonInclude(JsonInclude.Include.NONEMPTY)//@JacksonXmlRootElement(localName="Demo")//staticclassDemo////privatelongid;//@JacksonXmlCData//privateStringname;//@JsonFormat(pattern="yyyyMMdd",timezone="GMT+8")//privateLocalDatelocalDate;//@JsonFormat(shape=JsonFormat.Shape.STRING,pattern="yyyyMMddHH:mm:ss",timezone="GMT+8")//privateLocalDateTimelocalDateTime;//////@JacksonXmlElementWrapper(localName="DEMOMAP")////privateMap<String,Demo>map;////@JacksonXmlProperty(localName="elementString")////privateStringelementString;////@JacksonXmlProperty(localName="attributeString",isAttribute=true)////privateStringattributeString;//////@Data//@Accessors(chain=true)//@JsonIgnoreProperties(ignoreUnknown=true)//@JsonInclude(JsonInclude.Include.NONEMPTY)//@JacksonXmlRootElement(localName="PDFDemo")//staticclassPDFDemo////privateStringdemoNo;//@JsonFormat(pattern="yyyyMMdd",timezone="GMT+8")//privateLocalDatedemoDate;//@JacksonXmlElementWrapper(localName="DEMOLIST",useWrapping=false)//@JacksonXmlProperty(localName="DEMOLISTELEMENT")//privateList<Demo>demoList;////////wkhtmltopdf////https://wkhtmltopdf.org/downloads.html////wkhtmltopdf//@Value("{pdf.wkhtmltopdf.path}")
// private String wkhtmltopdfPath=“C:\Users\LiuYang\Desktop\wkhtmltox\bin\wkhtmltopdf.exe”;
//
// /**
// *
// * 使用Wkhtmltopdf工具
// * 有个见鬼的地方是:子进程的信息输出竟然是从getErrorStream得到的!!!!!
// *
// * @param srcPath 要转换的文件
// * @param pdfFileName 转换的pdf文件名称
// * @return boolean
// * @throws Exception exception
// */
// public boolean convert(String srcPath,String pdfFileName) throws Exception {
// Path outPath=Paths.get(outFilePath);
// if(!Files.exists(outPath, LinkOption.NOFOLLOW_LINKS)){
// Files.createDirectories(outPath);
// }
// StringBuilder cmd = new StringBuilder();
// //if (!System.getProperty(“os.name”).contains(“Windows”)) wkhtmltopdfPath = “”; //非windows 系统
// cmd.append(wkhtmltopdfPath).append(" “”).append(srcPath).append("" “).append(outFilePath).append(pdfFileName);
// log.info(“运行命令={}”,cmd);
// try {
// Process proc = Runtime.getRuntime().exec(cmd.toString());
// log.info(“Begin PDF conver[{}]”,System.currentTimeMillis());
// new ProcessStreamRunable(proc.getInputStream(),“output”).start();//得到进程的标准输出信息流,对你没看错是输出流!
// new ProcessStreamRunable(proc.getErrorStream(),“error”).start();//得到进程的错误输出信息流
// int result=proc.waitFor();
// log.info(“End PDF conver[{}],转换进程运行结果={}”,System.currentTimeMillis(),result);
// } catch (Exception e) {
// log.error(e.getMessage(),e);
// return false;
// }
// return true;
// }
//
//
// static class ProcessStreamRunable extends Thread {
// private final InputStream inputStream;
// private final String streamName;
// public ProcessStreamRunable(InputStream inputStream,String streamName) {
// this.inputStream = inputStream;
// this.streamName= streamName;
// }
// @Override
// public void run() {
// try {
// InputStreamReader inputStreamReader = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
// BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
// String line ;
// while ((line = bufferedReader.readLine()) != null) {
// log.info(”{}:{}",streamName,line);
// }
// } catch (IOException e) {
// log.error(String.format("%s:%s",streamName,e.getMessage()),e);
// }
// }
// }
//
//}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值