使用从数据库中获取的名称创建 PDF 文件
我是 Java 新手。 我能够生成一个 PDF,其目录名称为常量。
但我的方案是用我从数据库中获取的值来命名该 PDF 文件。 我将在下面解释我的情况。
当我使用此语句创建 PDF 时,它的创建名称为 test.pdf
。
String file = "C://test.pdf";
System.out.println("creating");
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document,
new FileOutputStream(file));
但是,当我尝试使用从数据库获取的字符串来命名该 PDF 时,它并未创建。
考虑 name 是否是我从数据库中获取的列。如果数据库中的name = raja
,我需要创建文件名为raja.pdf
的pdf文件。
我该怎么做呢?
I am new to Java.
I was able to generate a PDF with a constant name to my directory.
But my scenario is to name that PDF file by a value which I am fetching from the DB.
I'll explain my scenario below.
When I use to create that PDF with this statement, it's created with name test.pdf
.
String file = "C://test.pdf";
System.out.println("creating");
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document,
new FileOutputStream(file));
But when I am trying to name that PDF with a string which I am getting from DB it's not created.
Consider if name is a column I am fetching from DB. If name = raja
in db, I need to create that pdf file with file name as raja.pdf
.
How would I do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据您的描述:
您应该创建一个具有严格写入权限的文件夹并将其放置在那里。如果它不起作用,你应该得到一个例外。也许您的 System.out.println 应该包含文件名:
According to your description:
You should create a folder with write permissions tough and place it there. If its not working you should get an exception. Maybe your
System.out.println
should include the file name: