txt转pdf
引入pom
<!--https://mvnrepository.com/artifact/com.itextpdf/itextpdf-->
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.5.13</version>
</dependency>
demo
package pdf;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Font;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfWriter;
import java.io.*;
/**
* @author Demon-HY
* @date 2019-5-23
*/
public class TxtToPDF {
private static final String FONT = "C:\\windows\\Fonts\\simhei.ttf";
public static void text2pdf(String text, String pdf) throws DocumentException, IOException {
Document document = new Document();
outputstream os = new FileOutputStream(new File(pdf));
PdfWriter.getinstance(document, os);
document.open();
//方法一:使用Windows系统字体(TrueType)
BaseFont baseFont = BaseFont.createFont(FONT, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
Font font = new Font(baseFont);
inputstreamreader isr = new InputStreamReader(new fileinputstream(new File(text)), "GBK");
// InputStreamReader isr = new InputStreamReader(new FileInputStream(new File(text)), "UTF-8");
BufferedReader bufferedReader = new BufferedReader(isr);
String str = "";
while ((str = bufferedReader.readLine()) != null) {
System.out.println(str);
document.add(new Paragraph(str, font));
}
document.close();
}
public static void main(String[] args) throws Exception {
String PDFTIMEDIR = "E:/Books/";
String text = PDFTIMEDIR + "A.txt";
String pdf = PDFTIMEDIR + "A.pdf";
text2pdf(text, pdf);
}
}
相关阅读
来源-作者@聚优致成&:https://blog.csdn.net/qq_29350001/article/details/51781419建议读者阅读原文,确保获得完整的信息,侵权请联
Eigen库 矩阵基本操作:转置矩阵,逆矩阵,伴随矩阵,特征值
#include <iostream>#include "Eigen\Dense"using namespace Eigen;using namespace std;int main(){ Matrix3d Mat1; M
使用目的目前数据交互大多以 JSON 字符串为信息传输,主要格式有 {"age":"22","name":"李四"} [{"age":"21","name":"张三"}] 最常
怎么将录音转成文字。关于语音转文字和音频转文字,不管是在会议纪要,还是演讲采访,又或是音频文件整理,都有这样的需求。那么如何在线
java mybatis XML文件中不允许出现">"、"<"之类的符号。需要转义 "="是可以正常使用的 字段 符号