Hello,
 
I want to use a .pdf file as a log file, which means I want to add a few paragraphs to the same file on different application sessions. This is an example of the code I use:
 

String Home = "C:\\log\\";

String fileName = "logfile.pdf";

String absFileName = Home + fileName;

File file = new File(absFileName);

Document report = new Document(PageSize.A4.rotate());

FileOutputStream fos;

try{

if(file.exists()){

fos = new FileOutputStream(absFileName,true);

PdfWriter writer = PdfWriter.getInstance(report, fos);

}

else{

fos = new FileOutputStream(absFileName);

PdfWriter writer = PdfWriter.getInstance(report, fos);

}

}

catch(FileNotFoundException fe){

fe.printStackTrace();

}

catch(DocumentException de){

de.printStackTrace();

}

report.open();

try{

report.add(new Phrase("test line"));

}

catch(DocumentException de){

de.printStackTrace();

}

report.close();

The result I get is that my document always contains just one phrase "test line" - i.e. when I run this program again the content of the file is overwritten!

Can you please help me with some advice.

Thank you in advance,

Ljupka Doncevska

Reply via email to