我需要使用 Java 将一些文本写入 PDF 文档。我为此写了一个代码。但我无法打开文件。如果你们有什么想法,请与我分享。
public class WritPDF
{
public static void main(String[] args)
{
Writer writer = null;
try
{
String text = "This is a text file";
File file = new File("C:/Users/PrinterTest/Hi1.pdf");
writer = new BufferedWriter(new FileWriter(file));;
writer.write(text);
} catch (FileNotFoundException e)
{
e.printStackTrace();
} catch (IOException e)
{
e.printStackTrace();
} finally
{
try
{
if (writer != null)
{
}
} catch (IOException e)
{}
}
}
}