first post ever in any forum with regard to programming… i usually just search until i find the answer… but this time im really stuck…
here’s the problem…
i have a JPanel, and recently discovered that itext provides you with a way to export Java GUI to PDF…
i cant seem to understand itext’s language nor how to add a simple JPanel to a document then export that document to a PDF… this is all i have at the moment…
import java.io.FileOutputStream;
import com.itextpdf.text.*;
import com.itextpdf.text.pdf.*;
import java.awt.Color;
import javax.swing.*;
public class HelloWorld {
public static void main(String[] args) {
try
{
//Panel creation and setup
JPanel panel = new JPanel();
//just to ensure that the panel has content...
JLabel label = new JLabel("i am a label");
panel.add(label);
panel.setSize(100,100);
//so that even if the label doesnt get added...
//i can see that the panel does
panel.setBackground(Color.red);
//my understanding of the code below: the virtual document
Document document = new Document();
//my interpretation just writes the virtual pdf document to the hdd
PdfWriter writer = PdfWriter.getInstance
(document, new FileOutputStream("C:/test.pdf"));
//begin editing the vpdf
document.open();
//i wanna do something like this
//document.add(panel);
//end editing the vpdf
document.close();
} catch (Exception e)
{
System.out.println(e);
}
}
please please help… i tried to make the code as short as possible to avoid useless stuff…
thanks in advance…
Craig
ok what i’ve done is add the WHOLE class document for the code in which i used the export to PDF… its very simple in the sense that it just exports the WHOLE panel as a Graphics2D image then that too PDF… im still working on it as i intend to export the document as a FDF PDF… but for now this document exports fine…
here it is:
if you need help, i’ll be more than willing to assist you:
its alot of code, however its very easy… just a whole bunch of easy stuff… im not the most advanced programmer…
anyway… lemme know if you need help Boro