@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. OOP的感悟

    不要认为你关心的东西就是对象的全部或对象的核心,相对于对象的成员家族而言,它仅仅是其中的一个‘很小的成员而已’

  2. CC工具列表

    QuasarRAT   Adwind Adzok Arcom Babylon Blacknix Blue Banana Bozok Coringa DarkComet DRAT Gh0st Huige ...

  3. 什么是API?我们常说调用API

    如果你不知道 API 是什么,说明你英语真的很差. API 就是 Application Programming Interface 三个单词,如果你不能顾名思义的话,我就举例说明. 1. DOM A ...

  4. TextView上下滑动

    LocationResult = (TextView) findViewById(R.id.textView1);LocationResult.setMovementMethod(ScrollingM ...

  5. jstree 取消选中父节点

    问题说明: 当选择子节点时,它的父节点只有一个子节点的情况下,默认会选中父节点. 当前应用场景: 不需要选中当前的父节点 实验截图: 修改部分: jstree.js 信息

  6. iOS笔记之文件读写

    最近做的项目中要存储一组图片数据,图片带有name,date等属性,处理办法是讲image图片直接存在沙盒documents文件中,再使用plist文件存储图片属性和image路径. 存入图片: - ...

  7. [批处理]NetstatFilter快速查找端口被占用问题

    前言 准确的说,他是一个网络连接端口查看器,可以根据进程查端口,也可以根据端口查进程.期初是因在使用Fiddler的时候发现无法启动,提示端口被占用,但是由不知道用什么方法才能找到是哪个程序占用的Fi ...

  8. vue.js 源代码学习笔记 ----- helpers.js

    /* @flow */ import { parseFilters } from './parser/filter-parser' export function baseWarn (msg: str ...

  9. busybox microcom Segmentation fault

    /********************************************************************************* * busybox microco ...

  10. Android GPS GPSBasics project hacking

    一.参考源码: GPS Basic Example - Android Example http://androidexample.com/GPS_Basic__-__Android_Example/ ...