Hi,
I am developing an application where I need to print tickets for the customers. In order to do this, I have created a PDF template file and copied that file along with java source files. I have to access this template file and fill the template fields with new values and open a new PDF file in browser which will be printed.
But the problem is, I am not able to access this template file. I am using iText PDF API. I am trying to read the template file, but it gives an exception that, in the given path is not found as a File or Resource.
If I give the complete path it reads with no problem. But I am not able to read it with a reference path.
This is my code:
//String templatePath=VaadinService.getCurrent().getStaticFileLocation(VaadinService.getCurrentRequest()) + File.separator+ “psv-ticket-template.pdf”;
//String templatePath=VaadinServlet.getCurrent().getServletConfig().getServletContext().getContextPath() + File.separator+ "psv-ticket-template.pdf";
//String templatePath= "./psv-ticket-template.pdf";
String templatePath=VaadinServletService.getCurrent().getBaseDirectory().getAbsoluteFile() + File.separator+"member"+File.separator+"psv-ticket-template.pdf";
PdfReader reader = new PdfReader([b]
templatePath
[/b]); //This is where I am getting Exception
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfStamper stamper = new PdfStamper(reader, baos);
stamper.setFormFlattening(true);
stamper.close();
reader = new PdfReader(baos.toByteArray());
Document document = new Document(reader.getPageSizeWithRotation(1));
PdfCopy writer = new PdfCopy(document,new FileOutputStream("psv_ticket.pdf"));
document.open();
PushbuttonField pushbuttonField=null;
for(BookingDetail bookingDetail:bookingHeader.getBookingDetailSet()){
reader = new PdfReader(templatePath);
baos = new ByteArrayOutputStream();
//.................and so on.
If it is not possible to store a file like that, then where can I store it?
Someone please help me,
Thanks,
Kishor