Skip to content

Instantly share code, notes, and snippets.

@desireesantos
Created August 11, 2013 13:08
Show Gist options
  • Save desireesantos/6204824 to your computer and use it in GitHub Desktop.
Save desireesantos/6204824 to your computer and use it in GitHub Desktop.
Pdffactory
package com.trailblazers.freewheelers.model;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.pdf.PdfWriter;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.OutputStream;
public class PdfFactory {
public static final String FILE_PATH = "./src/main/webapp/pdf/order";
public static final String PDF = ".pdf";
private PdfWriter pdfWriter;
public PdfWriter getPdfWriter() {
return pdfWriter;
}
public void create(Document pdf, ReserveOrder orderId) throws FileNotFoundException, DocumentException {
String nameFile = generateFileNameWithTypePDF(orderId.getOrder_id());
pdfWriter = PdfWriter.getInstance(pdf, createOutPutStream(nameFile));
}
private OutputStream createOutPutStream(String nameFile) throws FileNotFoundException {
return new FileOutputStream(FILE_PATH + nameFile);
}
private String generateFileNameWithTypePDF(Long orderId) {
return orderId + PDF;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment