|
Okay, I figured out part of my problem is
that I had hard coded an image that I was using in onOpenDocument
and since it wasn’t there it wasn’t creating any of the pdf. Now that’s taken care of I only have
one other problem. I can’t seem to generate 2 pdf’s
without reopening the program. When I try to create a second pdf the compiler tells me “The document has been
closed. You can't add any Elements.” I am using JFileChooser
to choose the filename. Here is the code I use to open the file. I am closing
it too otherwise I wouldn’t be able to open the pdf.
Thanks Dominic //
created globally PdfWriter writer; Document document = new Document(PageSize.LETTER); /// // inside
my printpdf
method
//display file dialog, so user can choose file to open JFileChooser fileChooser = new JFileChooser(); fileChooser.addFocusListener(chooserFocusListener); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
int result = fileChooser.showSaveDialog(this); //if
user clicked cancel button on dialog, return if(result == fileChooser.CANCEL_OPTION)
return;
File
fileName = fileChooser.getSelectedFile(); // get selected file
//display error if invalid if(fileName == null || fileName.getName().equals(""))
JOptionPane.showMessageDialog(this,"Invalid File Name","Invalid File Name",
JOptionPane.ERROR_MESSAGE); // create
pdf report try{
writer = PdfWriter.getInstance(document,
new FileOutputStream(fileName + ".pdf"));
MyPageEvent event = new MyPageEvent();
writer.setPageEvent(event);
// step 3: we open the document
document.open(); //blab
la bla add stuff to document document.close(); } catch(DocumentException de){
System.err.println(de.getMessage()); } catch (IOException ioe) {
System.err.println(ioe.getMessage()); } -----Original Message----- I have my program in a jar and have
itext in the same directory. I then run it using javaw from an icon on my
desktop. On my personal computer my program creates the pdf’s perfectly.
I have the full 1.4.2 jdk installed. I tried the exact same setup on several
other windows xp machines but the pdf’s always say there was an error
opening and that the file is damaged, a few times it said the files
wasn’t closed and I noticed I couldn’t delete it. The pdf size is 0
and the pdf is created instantaneously rather than 2-3 seconds like on my
machines. I really can’t figure out what’s wrong and I wonder if
anyone else has had a similar experience? I downloaded the 1.4.2 jre and
installed in on the other computers, and even tried installing the jdk after
that didn’t work. The only difference is that I have netbeans installed
on my computer but since I’m compiling from an icon not netbeans that
shouldn’t matter. I’d appreciate any advice.
Thanks! Dominic |
- RE: [iText-questions] Pdf Corruption Dominic Maricic
- Re: [iText-questions] Pdf Corruption bruno
- RE: [iText-questions] Pdf Corruption Dominic Maricic
