12/24/2022 0 Comments Pdfwriter getinstance![]() ![]() The code is a bit more complex than the JTable example. Click on thumbnail to view full-sized image. A simple editor with a JTextPane that is drawn onto a PDF file. It's a simple text editor that allows you to write text in a JTextPane and print it to PDF.įigure 2 shows this application in action. The next example was posted to the iText mailing list by Bill Ensley (), one of the more experienced iText users on the mailing list. PdfTemplate tp = cb.createTemplate(500, 500) PdfContentByte cb = writer.getDirectContent() New FileOutputStream("my_jtable_fonts.pdf")) New FileOutputStream("my_jtable_shapes.pdf")) The code to achieve this is amazingly simple: /* chapter12/MyJTable.java */ If you select a row, the background of the row is shown in a different color in the Java applications as well as in the PDF. If you run this example, try changing the content of the JTable the changes are reflected in the PDF. ![]() A Swing application with a JTable that is printed to PDF two different ways. If you have any questions or suggestions regarding the video or the code, then do let me know.Figure 1. Also check out the video above to see the code in action.Don’t forget to share the article with your friends on social media. ![]() If you like this short tutorial, then do let me know. In future I may cover some of the examples for the iText library that may include styling and the form handling along with the database export options. In this case however I suggest you to check out the documentation of the iText PDF library. There are styles that you can apply to the document. Alternatively you can use it to export the database tables to the PDF document. And there are many other things that can you do with the document. And the file is stored in the same folder to that of the project files. When you run the code, eclipse tries to export the PDF using iText. Make that change and any other change in the output that you want. Just watch out with the classname in this code, and change it to your project’s classname. You can copy the code given above and paste it inside your Eclipse project class. We have placed this code inside try and catch block to avoid file exceptions. In next statement we have added the content inside the pdf document. In second statement we have opened the created document. PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(“demo.pdf”)) ĭocument.add(new Paragraph(“This is Demo PDF”)) Ĭode: In first statement, we have created pdfwriter instance and created pdf document. So let’s see how this can be done with the code. This helps us to properly format before exporting that document to PDF format. After creating a document we have to push the content inside the document. Once you have created the Eclipse Java project and added itext jar files. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |