@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的更多相关文章

  1. 使用OpenOffice.org将各类文档转为PDF

    http://blog.zhaojie.me/2010/05/convert-document-to-pdf-via-openoffice.html ————————————————————————— ...

  2. java转pdf(html转为pdf),解决中文乱码,标签不规范等问题

    第一步,下载jar包以及建对应的文件夹.注意pd4ml的jar要选择pro版本.然后建一个pd4fonts.properties 里面对应的字体. SimSun = simsun.ttf 前面为变量名 ...

  3. Java 字符串转码工具类

    StringConvertUtils.java package javax.utils; /** * 字符串转码工具类 * * @author Logan * @createDate 2019-04- ...

  4. Java 将Html转为PDF(二)

    前面介绍了如何通过插件的方式将Html文件转为PDF,该方法需要使用Spire.PDF for Java 3.6.6或者之后的新版本,可根据自己的系统选择不同插件来实现转换.本文提供另外一种转换方法, ...

  5. Java实现windows,linux服务器word,excel转为PDF;aspose-words,Documents4j

    Java实现windows,linux服务器word,excel转为PDF:aspose-words,Documents4j 一.通过aspose-words将word,Excel文档转为PDF 1. ...

  6. 办公利器!用Python快速将任意文件转为PDF

    痛点: 相信大家都会遇到一种场景.老师/上司要求你把某个文件转为pdf,并且是一批(不止一个,一个的话手动就可以搞定),并且这种是枯燥无聊的工作,既没有什么技术含量又累. 试想一下,如果我把这些文件放 ...

  7. 将doc文件批量转为pdf文件

    需要将不少doc文件转为pdf,WPS带有这种功能,但是鼠标点击次数太多以后整个人都变得很烦躁 用了一下午去搜这方面的工具软件,找到若干.有一些免费,有一些试用的,但总归就找到一个真正能用,虽说生成的 ...

  8. OpenOfice将offic转为pdf并且在web显示

    1.将office首先要安装OpenOfice,傻瓜式安装就好了,之后可以使用下列代码将word转为pdf.这个需要导入jodconverter-2.2.2里的 ja r包 import java.i ...

  9. 《Netty5.0架构剖析和源码解读》【PDF】下载

    <Netty5.0架构剖析和源码解读>[PDF]下载链接: https://u253469.pipipan.com/fs/253469-230062545 内容简介 Netty 是个异步的 ...

随机推荐

  1. PrestaShop 1.7 用户付款的时候无法支付错误

    用户付款的时候出现错误,错误的信息是没有支付方式. 这个有可能是你后台支付的国家限制没有选择. 请确定你已经选择了支付国家限制已经选择了. 当选择成功后,你应该可以看到下面的选择项.

  2. IOS-工程师Mac上的必备软件

      前言   iOS工程师一直都是那么的高逼格,用的是Mac电脑,耍的是iPhone手机,哇咔咔~~  但是,作为一名iOS开发工程师,我们除了高逼格外,还必须是全能的.你不会点UI设计.不会点后台语 ...

  3. IOS-网络(发送JSON数据给服务器和多值参数)

    三步走: 1.使用POST请求 2.设置请求头 [request setValue:@"application/json" forHTTPHeaderField:@"Co ...

  4. Java9新特性

    转载:http://blog.csdn.net/qq_32524177/article/details/77014757 写在前面的话:Java9来了,搜索了很多关于Java9的新特性,但文献不多,特 ...

  5. UVALive 4639 && SPOJ SPOINTS && POJ 3805 && AOJ 1298 Separate Points 求两个凸包是否相交 难度:3

    https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...

  6. 快速切题 sgu136. Erasing Edges

    136. Erasing Edges time limit per test: 0.25 sec. memory limit per test: 4096 KB Little Johnny paint ...

  7. 关于CMD/DOS中的短文件名规则

    最近在制作一个批处理的过程中发现一个很郁闷的问题,就是有些时候搜索到的结果不是我们想要的

  8. 20181009-8 选题 Scrum立会报告+燃尽图 07

    Scrum立会报告+燃尽图(07)选题 此作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2197 一.小组介绍 组长:刘莹莹 ...

  9. L203 词汇题

    Conditions for the growth of this plant are optimum in early summer.we will live as free people, not ...

  10. 转:MyISAM 和 InnoDB 讲解

    InnoDB和MyISAM是许多人在使用MySQL时最常用的两个表类型,这两个表类型各有优劣,视具体应用而定.基本的差别为:MyISAM类型不支持事务处理等高级处理,而InnoDB类型支持.MyISA ...