字符串转码 将文本转为PDF
@Test
public void testBasic64Code() throws Exception {
String strdata = new String("how are you".getBytes("UTF-8"));
BASE64Decoder decoder = new BASE64Decoder();
byte[] decodedBytes;
decodedBytes = decoder.decodeBuffer(strdata);
System.out.println(decodedBytes); }
1.转PDF test
public class Base64ConvertPDFTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
String encodedBytes = readFile("/home/wrightdeng/Desktop/test.txt", StandardCharsets.UTF_8);
BASE64Decoder decoder = new BASE64Decoder();
byte[] decodedBytes;
decodedBytes = decoder.decodeBuffer(encodedBytes);
File file = new File("/home/wrightdeng/Desktop/newfile.pdf");;
FileOutputStream fop = new FileOutputStream(file);
fop.write(decodedBytes);
fop.flush();
fop.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
static String readFile(String path, Charset encoding) throws IOException
{
byte[] encoded = Files.readAllBytes(Paths.get(path));
return new String(encoded, encoding);
}
}
工具类:
***************************************************************************/
public class Base64ConverterUtils {
private static final Logger LOGGER = LoggerFactory.getLogger(Base64ConverterUtils.class);
public static void Base64Converter(String encodedBytes, String tempPath) {
// BASE64Decoder decoder = new BASE64Decoder();
LOGGER.info("The file temp saved in :"+tempPath);
byte[] decodedBytes;
try {
decodedBytes = Base64.getDecoder().decode(encodedBytes); // decoder.decodeBuffer(encodedBytes);
File file = new File(tempPath);
FileOutputStream fop = new FileOutputStream(file);
fop.write(decodedBytes);
fop.flush();
fop.close();
} catch (IOException e) {
LOGGER.error("write file to server occurred exception,the reason: "+e.getMessage());
e.printStackTrace();
}
}
}
字符串转码 将文本转为PDF的更多相关文章
- 使用OpenOffice.org将各类文档转为PDF
http://blog.zhaojie.me/2010/05/convert-document-to-pdf-via-openoffice.html ————————————————————————— ...
- java转pdf(html转为pdf),解决中文乱码,标签不规范等问题
第一步,下载jar包以及建对应的文件夹.注意pd4ml的jar要选择pro版本.然后建一个pd4fonts.properties 里面对应的字体. SimSun = simsun.ttf 前面为变量名 ...
- Java 字符串转码工具类
StringConvertUtils.java package javax.utils; /** * 字符串转码工具类 * * @author Logan * @createDate 2019-04- ...
- Java 将Html转为PDF(二)
前面介绍了如何通过插件的方式将Html文件转为PDF,该方法需要使用Spire.PDF for Java 3.6.6或者之后的新版本,可根据自己的系统选择不同插件来实现转换.本文提供另外一种转换方法, ...
- Java实现windows,linux服务器word,excel转为PDF;aspose-words,Documents4j
Java实现windows,linux服务器word,excel转为PDF:aspose-words,Documents4j 一.通过aspose-words将word,Excel文档转为PDF 1. ...
- 办公利器!用Python快速将任意文件转为PDF
痛点: 相信大家都会遇到一种场景.老师/上司要求你把某个文件转为pdf,并且是一批(不止一个,一个的话手动就可以搞定),并且这种是枯燥无聊的工作,既没有什么技术含量又累. 试想一下,如果我把这些文件放 ...
- 将doc文件批量转为pdf文件
需要将不少doc文件转为pdf,WPS带有这种功能,但是鼠标点击次数太多以后整个人都变得很烦躁 用了一下午去搜这方面的工具软件,找到若干.有一些免费,有一些试用的,但总归就找到一个真正能用,虽说生成的 ...
- OpenOfice将offic转为pdf并且在web显示
1.将office首先要安装OpenOfice,傻瓜式安装就好了,之后可以使用下列代码将word转为pdf.这个需要导入jodconverter-2.2.2里的 ja r包 import java.i ...
- 《Netty5.0架构剖析和源码解读》【PDF】下载
<Netty5.0架构剖析和源码解读>[PDF]下载链接: https://u253469.pipipan.com/fs/253469-230062545 内容简介 Netty 是个异步的 ...
随机推荐
- WPF 动画 和 色彩 的随笔
1:善于用“Margin”做动画效果 2:色彩处理通常用:Brush,而Brush(如:SolidColorBrush)的实例化,通常需要载入“ System.Windows.Media.Color” ...
- **优化--后端**: 计数缓存counter_cache; rack-mini-profiler(2300🌟) ; bullet(5000✨):侦测N+1query
rack-mini-profiler 这个 gem,可以永远显示网页的加载时间.(2300✨)开发环境和产品环境都可以用.(生成非常详细的报告) development环境,直接使用gem 'rack ...
- ✅javascript 语法:附加子节点
received: function(data) { $("#notifications").prepend(data.html); } 如何用原生js写出jquery的功能: 先 ...
- IOS-更优雅地使用Static Cell
更优雅地使用Static Cell 在项目开发中,经常会用到static cell来实现一些固定的列表界面(如:个人中心等),在static cell被点击时,如何判断被点击的cell是哪一个,有什么 ...
- J2EE课程设计——企业人力资源管理系统
一.项目名称:企业人力资源管理系统 小组成员:冯雨倩 汤杰 二.项目需求: 随着现在计算机技术的不断完善,以及现代经济的不断发展,传统的管理技术不再满足企业的需要,越来越多的企业注重计算机信息管理系统 ...
- GPU Memory Usage占满而GPU-Util却为0的调试
最近使用github上的一个开源项目训练基于CNN的翻译模型,使用THEANO_FLAGS='floatX=float32,device=gpu2,lib.cnmem=1' python run_nn ...
- batchsize的选择
参考链接:http://www.zhihu.com/question/32673260 其中链接中提到,theano Python接口,支持RBM,DBN,MLP...等
- lua 二进制函数使用
由于 Lua 脚本语言本身不支持对数字的二进制操作(例如 与,或,非 等操作),MUSHclient 为此提供了一套专门用于二进制操作的函数,它们都定义在一个"bit"表中,使用时 ...
- mysql_use_result的使用
对于每个可以产生一个结果集的命令(比如select.show.describe, explain, check_table等等),发起mysql_query或者mysql_real_query之后,你 ...
- C# zedgraph 怎么设置初始时坐标轴的比例??
http://bbs.csdn.net/topics/390872329 已解决,,,我问是刷新图用的,,我以为mypane.YAxis.Scale.Min=0; mypane.YAxis.Scale ...