0

I am writing a text editor much like wordpad and I want my users to export my jtextpane to a PDF. I don't want to use a external library if I can help it. I only want to export as PDF, I don't want to overwrite, read, or edit any current PDFs. I can post code If I need to but I think the question Is clearly defined.

I am a beginner at java so maybe I missed something.

Thanks.

  • Have you looked at the possible duplicates of this question? [Q:-Create-PDF-with-java](http://stackoverflow.com/questions/7355025/create-pdf-with-java) – byxor Sep 01 '16 at 13:13
  • I did, all the answers there use external library(s), I was hoping for something built in. – onelittleprogrammer Sep 01 '16 at 13:49
  • As far as I'm aware there's no built-in way to do it. You'd have to write your own implementation (which I advise against) if you _really_ don't want to use an external library. – byxor Sep 01 '16 at 13:50
  • @onelittleprogrammer Check this and draw your own conclusions [link](http://stackoverflow.com/questions/18739953/how-to-create-pdf-file-using-java-without-using-any-external-libraries) – TimeToCode Sep 01 '16 at 13:51
  • thanks for the link @TimeToCode, have you guys ever used Apache PDFBox? I'd rather not use iText because of licensing. – onelittleprogrammer Sep 01 '16 at 14:36
  • @onelittleprogrammer I've never used before Apache PDFBox , but I think it isn't difficult to use , there are many examples for use. – TimeToCode Sep 01 '16 at 14:49
  • 1
    Ok, thanks. make your comment into an answer and I will accept it – onelittleprogrammer Sep 01 '16 at 14:51

2 Answers2

0

Create a PDF file with no external libraries is very complicated, you can check the following link and create your own conclusions.

It is best to use an external library to deploy Java.

How to create pdf file using Java without using any external libraries?

Community
  • 1
  • 1
TimeToCode
  • 901
  • 2
  • 16
  • 34
0

Just some ideas on how to do it:

You need to create your own Graphics2D. Then you paint your JTextPane on it. If you use a library, you can make it easier to write this part, but if not, you will need to implements the PDF specifications. You can inspire from existing libraries like VectorGraphics2D

However, the real issue remains the fonts management. But if you don't mind using the default PDF fonts, it might be feasible.

Sharcoux
  • 5,546
  • 7
  • 45
  • 78