简体   繁体   English

在Android中将备忘录(文本)文件转换为PDF文件

[英]Convert memo (text) file into pdf file in android

I need to convert memo file(text) to pdf in my android application. 我需要在我的Android应用程序中将备忘录文件(文本)转换为pdf。 I went through few tutorials related to iText, but all of them added content to the pdf in their code. 我浏览了一些与iText相关的教程,但所有教程均在其代码中为pdf添加了内容。 But what I need is convert the memo file exact as it is. 但是我需要的是完全转换备忘录文件。 Can I do this using iText or is their any other way to do this? 我可以使用iText还是其他方式来做到这一点?

Get the string out of text file and use this method to write string to pdf. 从文本文件中获取字符串,然后使用此方法将字符串写入pdf。

String s="text to be written";
 byte[] bytes= javax.xml.bind.DatatypeConverter.parseBase64Binary(s);
 FileOutputStream fos = new FileOutputStream("pathname.pdf"); 
 try{
 fos.write(bytes); 
 }catch(Exception e){}
 finally{
 fos.close();
  }

or, you may use external libraries like : 或者,您可以使用外部库,例如:

http://code.google.com/p/xspdf/ http://code.google.com/p/xspdf/

and use it as 并用作

  String s="text to be writen";
  XSPDF .getInstance (). print ( s). createPdf ( "pdf/Example 002.pdf" );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM