注意我这里只是将word字节替换成pdf字节,如果是文件根据自己实际情况来做
1、所需jar包
< dependency>
< groupId> com. aspose< / groupId>
< artifactId> aspose- words< / artifactId>
< version> 15.8 .0 < / version>
< / dependency>
2、去除水印配置文件,此文件放到resource文件夹下,如图
3、license配置文件
< License >
< Data >
< Products >
< Product > Aspose. Total for Java < / Product >
< Product > Aspose. Words for Java < / Product >
< / Products >
< EditionType > Enterprise < / EditionType >
< SubscriptionExpiry > 20991231 < / SubscriptionExpiry >
< LicenseExpiry > 20991231 < / LicenseExpiry >
< SerialNumber > 8 bfe198c- 7f 0 c- 4 ef8- 8f f0- acc3237bf0d7< / SerialNumber >
< / Data >
< Signature >
sNLLKGMUdF0r8O1kKilWAGdgfs2BvJb/ 2 Xp8p5iuDVfZXmhppo+ d0Ran1P9TKdjV4ABwAgKXxJ3jcQTqE/ 2 IRfqwnPf8itN8aFZlV3TJPYeD3yWE7IT55Gz6EijUpC7aKeoohTb4w2fpox58wWoF3SNp6sK6jDfiAUGEHYJ9pjU=
< / Signature >
< / License >
4、核心代码
@Componet
@Slf4j
public class FileUtil {
@Autowired
private ResourceLoader resourceLoader;
public boolean getLicense ( ) {
boolean result = false ;
try {
Resource resource = resourceLoader. getResource ( "classpath:/license.xml" ) ;
License aposeLic = new License ( ) ;
aposeLic. setLicense ( is) ;
result = true ;
} catch ( Exception e) {
e. printStackTrace ( ) ;
}
return result;
}
public byte [ ] wordBytes2PdfBytes ( byte [ ] wordBytes) throws Exception {
boolean license = getLicense ( ) ;
log. info ( "验证结果:{}" , license) ;
Document document = new Document ( new ByteArrayInputStream ( wordBytes) ) ;
ByteArrayOutputStream outputStream = new ByteArrayOutputStream ( ) ;
document. save ( outputStream, SaveFormat . PDF ) ;
return outputStream. toByteArray ( ) ;
}
}