I have written a code to generate bar codes and saved them to a pdf file . The code executes successfylly but the PDF file does not open saying giving an error whome picture I am uploading. Please see my code and Picture with the error.
public void createPDF(String pdfFileName,String myString) throws FileNotFoundException{
Document doc = new Document() ;
PdfWriter docwriter = null;
try{
docwriter = PdfWriter.getInstance(doc, new FileOutputStream("C:\\Users\\hp430\\Desktop\\barcodes\\"+pdfFileName));
doc.addAuthor("Saboor Siddique");
doc.addCreationDate();
doc.addProducer();
doc.addCreator("SunSoftTechnologies");
doc.addTitle("Barcode Test");
doc.setPageSize(PageSize.LETTER);
doc.open();
PdfContentByte cb= docwriter.getDirectContent();
Barcode128 code128 = new Barcode128();
code128.setCode(myString.trim());
code128.setCodeType(Barcode128.CODE128);
code128.setBarHeight(5f);
code128.setX(0.1f);
Image code128Image = code128.createImageWithBarcode(cb, null, null);
code128Image.setAbsolutePosition(10, 700);
code128Image.scalePercent(125);
doc.add(code128Image);
}
catch(DocumentException dex){
System.out.println(dex);
}
}