将文本转换为PDF [英] Convert text into PDF

查看:81
本文介绍了将文本转换为PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有大量文本字符串,这些文本显然是PDF文件的原始数据,我需要将其重新制作为PDF.

I have a huge string of text that is apparently raw data for a PDF file, and I need to make it back into a PDF.

当前,我正在将字符串读取到StringBuffer中,但是如果需要,可以更改它.从那开始,我尝试将其写到文件中并更改扩展名(我真的希望这样做能起作用,但我有点不知道),我尝试将其带入String,然后从中取出byte [].并将其写入文件,或使用DataOutputStream将字节放入文件中.这些似乎都不起作用.

Currently I'm reading the string into a StringBuffer but if I need to I can change that. From there I have tried just writing it out to a file and changing the extension (I really hoped that worked, but I kinda knew it wouldn't), I've tried taking it to a String then getting a byte[] out of it and writing that to the file or using a DataOutputStream to put the bytes into the file. None of these has seemed to work.

我也尝试过使用iText插件,尝试通过该插件将其写入pdf,还尝试将文本阅读为pdf,然后将其逐页复制到新的pdf.这些都没有返回很好的结果.

I've also tried using the iText plugin, I tried just writing it to a pdf through that and I also tried reading the text as a pdf and then copying it page by page to a new pdf. Neither of these have returned very good results.

今天是星期五下午,我被轻拍了,任何建议都会有很大帮助!

It's Friday afternoon, I'm tapped, any suggestions will be a huge help!

推荐答案

好吧,经过大量研究,我发现保留字符串中的二进制数据通常会将其转换为Base64编码.完全猜出来,我从Base64中解码出了字符串,并将字节放到了pdf文件中,瞧,我有一个可以打开的pdf!

Okay, well after a lot of research I found out that to preserve the binary data in the string that typically you convert it to Base64 encoding. On a complete guess I decoded the string out of Base64 and dropped the bytes into the pdf file, and lo and behold I had a pdf that could be opened!

感谢您的回答,希望以后对您有所帮助!

Thanks for the answers and I hope this helps someone in the future!

这篇关于将文本转换为PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆