List of usage examples for com.itextpdf.text Document Document
public Document(Rectangle pageSize)
Document
-object. From source file:com.incosyz.sms.pdfcontroller.ChequePDF.java
public void generateOrderPdf(ArrayList<CheckModel> checkModels, String filepath, String chequeDescription) throws FileNotFoundException, DocumentException { try {//from w w w .j a v a2s . c o m String html = getHTML(checkModels, chequeDescription); Document document = new Document(PageSize.A4.rotate()); File f = new File(filepath); FileOutputStream fileOutputStream = new FileOutputStream(f); PdfWriter pdfWriter = PdfWriter.getInstance(document, fileOutputStream); document.open(); StringReader fileReader = new StringReader(html); XMLWorkerHelper.getInstance().parseXHtml(pdfWriter, document, fileReader); document.close(); fileOutputStream.close(); } catch (IOException ex) { Logger.getLogger(ChequePDF.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.incosyz.sms.pdfcontroller.OrderPDF.java
public void sendPdf(ArrayList<GETOrderModel> gETOrderModels, String orderDescription) throws DocumentException, MessagingException { try {/* w w w . j av a 2 s.co m*/ String html = getHTML(gETOrderModels, orderDescription); Document document = new Document(PageSize.A4.rotate()); String path = "./src/com/incosyz/sms/temp/tmporders.pdf"; File f = new File(path); FileOutputStream fileOutputStream = new FileOutputStream(f); PdfWriter pdfWriter = PdfWriter.getInstance(document, fileOutputStream); document.open(); StringReader fileReader = new StringReader(html); XMLWorkerHelper.getInstance().parseXHtml(pdfWriter, document, fileReader); document.close(); fileOutputStream.close(); MailSender mailSender = new MailSender(); MimeBodyPart body = (MimeBodyPart) mailSender.getBody(); body.setText(html, "utf-8", "html"); mailSender.setAttachmentPath(path); mailSender.setSubject(orderDescription); mailSender.sendMail(); } catch (IOException ex) { Logger.getLogger(OrderPDF.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.incosyz.sms.pdfcontroller.OrderPDF.java
public void generateOrderPdf(ArrayList<GETOrderModel> gETOrderModels, String filepath, String orderDescription) throws FileNotFoundException, DocumentException { try {/*from w w w . j av a2s . c om*/ String html = getHTML(gETOrderModels, orderDescription); Document document = new Document(PageSize.A4.rotate()); File f = new File(filepath); FileOutputStream fileOutputStream = new FileOutputStream(f); PdfWriter pdfWriter = PdfWriter.getInstance(document, fileOutputStream); document.open(); StringReader fileReader = new StringReader(html); XMLWorkerHelper.getInstance().parseXHtml(pdfWriter, document, fileReader); document.close(); fileOutputStream.close(); } catch (IOException ex) { Logger.getLogger(OrderPDF.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.incosyz.sms.pdfcontroller.SalePdf.java
public String createPdf(String pathTo) throws FileNotFoundException, DocumentException, IOException { String html = getHtml();//from w ww. j ava 2 s. c o m Document document = new Document(PageSize.A3.rotate()); String path = pathTo; f = new File(path); FileOutputStream fileOutputStream = new FileOutputStream(f); PdfWriter pdfWriter = PdfWriter.getInstance(document, fileOutputStream); document.open(); StringReader fileReader = new StringReader(html); XMLWorkerHelper.getInstance().parseXHtml(pdfWriter, document, fileReader); document.close(); fileOutputStream.close(); return path; }
From source file:com.isdemu.controller.BarCode128.java
public static void main(String[] args) throws FileNotFoundException, DocumentException { Document document = new Document(new Rectangle(PageSize.A4)); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("c:/Java4s_BarCode_128.pdf")); document.open();// w w w. j av a 2 s . co m document.add(new Paragraph("Code_128 Format_Java4s.com")); Barcode128 code128 = new Barcode128(); code128.setGenerateChecksum(true); code128.setCode("1234554321"); document.add(code128.createImageWithBarcode(writer.getDirectContent(), null, null)); document.close(); System.out.println("Document Generated...!!!!!!"); }
From source file:com.iucosoft.eavertizare.util.Export.java
public static void toPdf(JFrame frame, JTable jTableClients, String firma) { Document document = new Document(PageSize.A4.rotate()); try {/*w w w. j a v a 2 s. co m*/ JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle("Specify a file to save"); int userSelection = fileChooser.showSaveDialog(frame); if (userSelection == JFileChooser.APPROVE_OPTION) { File fileToSave = fileChooser.getSelectedFile(); System.out.println("Save as file: " + fileToSave.getAbsolutePath()); PdfWriter.getInstance(document, new FileOutputStream(fileToSave.getAbsolutePath() + ".pdf")); } document.open(); DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); Date date = new Date(); if (firma.equals("All firms")) { addTitle(document, "Raport pentru toate firmele cu toti clienti \n din " + dateFormat.format(date)); } else { addTitle(document, "Raport pentru " + firma + " \n din " + dateFormat.format(date)); } addEmptyLine(document, new Paragraph(), 2); PdfPTable table = new PdfPTable(jTableClients.getColumnCount()); table.setTotalWidth(jTableClients.getColumnCount() + 780); table.setLockedWidth(true); table.setHorizontalAlignment(Element.ALIGN_LEFT); for (int i = 0; i < table.getNumberOfColumns(); i++) { if (jTableClients.getColumnName(i).equals("")) { table.addCell("Trimis"); } else { table.addCell(jTableClients.getColumnName(i)); } } Object value; for (int i = 0; i < jTableClients.getRowCount(); i++) { for (int j = 0; j < table.getNumberOfColumns(); j++) { value = jTableClients.getValueAt(i, j); table.addCell(value.toString()); } } document.add(table); document.close(); } catch (DocumentException ex) { Logger.getLogger(MainJFrame.class.getName()).log(Level.SEVERE, null, ex); } catch (FileNotFoundException ex) { Logger.getLogger(MainJFrame.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.khepry.frackhem.fxml.FracKhemGUIController.java
License:Apache License
private void saveTextAsPDF(String content, File file) throws FileNotFoundException, DocumentException, IOException, InterruptedException { Document document = new Document(PageSize.A4.rotate()); PdfWriter pdfWriter = PdfWriter.getInstance(document, new FileOutputStream(file)); document.open();// www . j a va 2 s. c om document.addAuthor("Author of the Doc"); document.addCreator("Creator of the Doc"); document.addSubject("Subject of the Doc"); document.addCreationDate(); document.addTitle(file.getName()); String html = htmlHeader.concat(markdown4jProcessor.process(content.trim())); // XMLWorkerHelper.getInstance().parseXHtml(pdfWriter, document, new ByteArrayInputStream(html.getBytes("UTF-8")), this.getClass().getResourceAsStream(cssFileFullPath)); XMLWorkerHelper.getInstance().parseXHtml(pdfWriter, document, new ByteArrayInputStream(html.getBytes("UTF-8"))); document.close(); pdfWriter.close(); displayFile(file.getAbsolutePath(), sleepMillis); }
From source file:com.microware.intrahealth.Createpdf2.java
@SuppressLint("SdCardPath") public boolean write(Context context, String fname, String[] Header, ArrayList<HashMap<String, String>> data, String[] Page2, int Flag) throws Exception { try {/* ww w .j a v a 2 s . c om*/ // file = new File(Environment.getExternalStorageDirectory()+IIHSPdf+ "/"+fname+".pdf"); this.context = context; g = (Global) context.getApplicationContext(); BaseFont urName = BaseFont.createFont("assets/FreeSans.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); urFontName = new Font(urName, 12); urName1 = FontFactory.getFont("assets/mangal.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); // urFontName = new Font(urName, 12); sHeader[0] = context.getResources().getString(R.string.hrpreport); sHeader[1] = context.getResources().getString(R.string.anmname) + " " + g.getsGlobalANMName() + " " + context.getResources().getString(R.string.distname); sHeader[2] = context.getResources().getString(R.string.Identificationcode); sHeader2[0] = context.getResources().getString(R.string.Identificationcode1); sHeader2[1] = context.getResources().getString(R.string.totalhrp); sHeader2[2] = context.getResources().getString(R.string.totalcheckup); sHeader2[3] = context.getResources().getString(R.string.anmsign); catFont2 = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD, new BaseColor(0, 85, 133)); if (Flag == 2) { catFont = new Font(urName, 16, Font.BOLD); catFont1 = new Font(urName, 16, Font.BOLD, new BaseColor(0, 85, 133)); subFont = new Font(urName, 14); smallBold = new Font(urName, 12, Font.BOLD, BaseColor.WHITE); } else { catFont = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD); catFont1 = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD, new BaseColor(0, 85, 133)); subFont = new Font(Font.FontFamily.TIMES_ROMAN, 14); smallBold = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD, BaseColor.WHITE); } String fpath = "/sdcard/msakhi/Pdf"; File path = new File(fpath); File file = new File(path, fname + ".pdf"); if (!path.exists()) { path.mkdirs(); if (!file.exists()) { file.createNewFile(); } } else { if (!file.exists()) { file.createNewFile(); } } // Font bfBold12 = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD, new BaseColor(0, 0, 0)); // Font bf12 = new Font(Font.FontFamily.TIMES_ROMAN, 12); Document document = new Document(A4.rotate()); PdfWriter.getInstance(document, new FileOutputStream(file.getAbsoluteFile())); document.open(); // addMetaData(document); // addTitlePage(document); addContent(document, Header, data, sHeader2, Flag); document.close(); return true; } catch (IOException e) { e.printStackTrace(); return false; } catch (DocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); return false; } }
From source file:com.miraflorescarwash.controller.PdfController.java
@RequestMapping(value = "/cliente.html", method = RequestMethod.GET) public void doGetPdfCliente(@RequestParam("id") Long id, HttpServletResponse response) { Cliente cliente;/*from w ww . ja va2 s . com*/ ByteArrayOutputStream baos; Document document; OutputStream os; cliente = clienteService.findById(id); if (cliente != null) { clienteService.iniciarRelacionesLazy(cliente); try { document = new Document(PageSize.A4); baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); // document.open(); // Escribimos crearPdfCliente(document, cliente); // Cerramos // document.close(); //No cerrar ni abrir porque se hace en el metodo arriba // Hay que configurar las cabeceras para que //el navegador detecte que es un <strong>PDF</strong> response.setHeader("Expires", "0"); response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0"); response.setHeader("Pragma", "public"); // Configuramos el content type response.setContentType("application/pdf"); // Tamao response.setContentLength(baos.size()); // Esccribir el ByteArrayOutputStream a el ServletOutputStream os = response.getOutputStream(); baos.writeTo(os); os.flush(); os.close(); } catch (DocumentException | IOException ex) { Logger.getLogger(PdfController.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:com.miraflorescarwash.controller.PdfController.java
@RequestMapping(value = "/credito.html", method = RequestMethod.GET) public void doGetPdfClienteCredito(@RequestParam("id") Long id, HttpServletResponse response) { List<CreditoDisponibleCliente> reporteCredito; ByteArrayOutputStream baos;// w w w . ja v a 2 s .c o m Document document; OutputStream os; reporteCredito = clienteService.verCreditoDisponible(id); if (reporteCredito != null) { try { document = new Document(PageSize.A4); baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); // Escribimos crearPdfClienteCreditoDisponible(document, reporteCredito); // Cerramos // Hay que configurar las cabeceras para que //el navegador detecte que es un <strong>PDF</strong> response.setHeader("Expires", "0"); response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0"); response.setHeader("Pragma", "public"); // Configuramos el content type response.setContentType("application/pdf"); // Tamao response.setContentLength(baos.size()); // Escribir el ByteArrayOutputStream a el ServletOutputStream os = response.getOutputStream(); baos.writeTo(os); os.flush(); os.close(); } catch (DocumentException | IOException ex) { Logger.getLogger(PdfController.class.getName()).log(Level.SEVERE, null, ex); } } }