Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package pipe; /** * * @author meteor */ import com.itextpdf.text.BadElementException; import java.io.FileNotFoundException; import java.io.FileOutputStream; import com.itextpdf.text.Document; import com.itextpdf.text.DocumentException; import com.itextpdf.text.Element; import com.itextpdf.text.Font; import com.itextpdf.text.FontFactory; import com.itextpdf.text.Image; import com.itextpdf.text.PageSize; import com.itextpdf.text.Paragraph; import com.itextpdf.text.Phrase; import com.itextpdf.text.pdf.PdfPCell; import com.itextpdf.text.pdf.PdfPTable; import com.itextpdf.text.pdf.PdfWriter; import java.io.File; import java.io.IOException; import java.net.MalformedURLException; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.ImageIcon; public class PdfMaker { private static PdfMaker instance; private final Font arial; private final Font arialSmall; private final Font arialMini; private final Font courier; private static Font catFont = new Font(Font.FontFamily.TIMES_ROMAN, 24, Font.BOLD); Document document = new Document(PageSize.A4); private ResultSet rs; /** * Private constructor, since this is a singleton. Fonts are initialized in * the constructor. */ public PdfMaker() { arial = FontFactory.getFont("Arial", 8); arial.setStyle(Font.BOLD); arialSmall = FontFactory.getFont("Arial", 6); arialSmall.setStyle(Font.BOLD); courier = FontFactory.getFont("Courier", 10); arialMini = FontFactory.getFont("Arial", 5); } /** * Provides an access to the service instance * * @return */ public static PdfMaker getInstance() { if (instance == null) { instance = new PdfMaker(); } return instance; } private void addTitlePage(Document document) throws DocumentException { Paragraph preface = new Paragraph(); // We add one empty line addEmptyLine(preface, 1); // Lets write a big header Paragraph para = new Paragraph("Meine Pfeifensammlung", catFont); para.setAlignment(Element.ALIGN_CENTER); preface.add(para); addEmptyLine(preface, 1); // Will create: Report generated by: _name, _date preface.add(new Paragraph("Erstellt von: " + System.getProperty("user.name"), arialSmall)); addEmptyLine(preface, 7); Image image = null; String frontpic = "db" + File.separator + "pipe-frontpage.jpg"; try { ImageIcon icon = new ImageIcon(frontpic.toString()); java.awt.Image img = icon.getImage(); java.awt.Image newimg = img.getScaledInstance(500, -1, java.awt.Image.SCALE_SMOOTH); image = Image.getInstance(newimg, null); } catch (BadElementException e) { } catch (MalformedURLException e) { } catch (IOException e) { } Paragraph picture = new Paragraph(""); picture.setAlignment(Element.ALIGN_CENTER); picture.add(image); preface.add(picture); addEmptyLine(preface, 10); preface.add(new Paragraph( "Dieser Katalog wurde mit Mat's pipe-manager erstellt.\nDie Software ist frei verfgbar und herunterladbar ber das Forum von www.komm-zur-pfeife.de.", arialSmall)); document.add(preface); // Start a new page document.newPage(); } private void addEmptyLine(Paragraph paragraph, int number) { for (int i = 0; i < number; i++) { paragraph.add(new Paragraph(" ")); } } /** * Creates the PDF document. * * @throws java.sql.SQLException */ public void createDocument() throws SQLException, ClassNotFoundException { /** * Assign the domainObject to an instance variable so that it can be * used to populate the fields in the form */ try { document.setMargins(30, 30, 30, 30); FileOutputStream fos; fos = new FileOutputStream("Pfeifenkatalog.pdf"); PdfWriter.getInstance(document, fos); document.open(); document.newPage(); addTitlePage(document); ResultSet rs = getDBVals(); int i = 1; while (rs.next()) { // Get all values into Array ArrayList values = new ArrayList(); values.add(rs.getString("id")); values.add(rs.getString("hersteller")); values.add(rs.getString("modell")); values.add(rs.getString("land")); values.add(rs.getString("edition")); values.add(rs.getString("jahr")); values.add(rs.getString("grundform")); values.add(rs.getString("mundstck")); values.add(rs.getString("kopfmat")); values.add(rs.getString("mundmat")); values.add(rs.getString("applikation")); values.add(rs.getString("tabak")); values.add(rs.getString("einstandspreis")); values.add(rs.getString("gekauft_bei")); values.add(rs.getString("kaufdatum")); values.add(rs.getString("verkaufspreis")); values.add(rs.getString("verkauft_an")); values.add(rs.getString("verkaufdatum")); values.add(rs.getString("oberflaeche")); values.add(rs.getString("bohrung")); values.add(rs.getString("filter")); values.add(rs.getString("laenge")); values.add(rs.getString("kopfhoehe")); values.add(rs.getString("kopfdurchmesser")); values.add(rs.getString("gewicht")); values.add(rs.getString("farbe")); values.add(rs.getString("zustand")); values.add(rs.getString("lagerort")); values.add(rs.getString("besonderes")); values.add(rs.getString("filter")); values.add(rs.getString("status")); Paragraph paragraph = new Paragraph("\n\n\n"); document.add(paragraph); addContent(document, values); if ((i) % 2 == 0) { document.newPage(); } i++; } document.close(); } catch (FileNotFoundException | DocumentException e) { } } public void addContent(Document document, ArrayList values) throws BadElementException, DocumentException { /** * Only adding one element to the document. The element contains the * entire form (which is just a table). */ Element mainElement = mainElement(values); document.add(mainElement); } /** * Builds and returns the main table. * * @return */ Element mainElement(ArrayList values) throws BadElementException { PdfPTable table = new PdfPTable(2); table.setWidthPercentage(100f); table.getDefaultCell().setBorderWidth(0.5f); Element element; PdfPCell cell; element = this.firstElement((String) values.get(0)); cell = this.createCell(1, 1); cell.setBorder(15); cell.setPadding(2f); cell.addElement(element); table.addCell(cell); String dirString = "pictures" + File.separator + (String) values.get(0) + "_" + (String) values.get(1) + "_" + (String) values.get(2) + File.separator + "01.jpg"; element = this.fourthLogoElement(dirString); // You need to pass the image to the constructor. // If you add the image, it will be stretched to fill the cell. cell = new PdfPCell((Image) element); cell.setPadding(2); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_CENTER); cell.setBorderWidth(0.3f); cell.setRowspan(4); table.addCell(cell); element = this.thirdElement((String) values.get(1), (String) values.get(2)); cell = this.createCell(1, 1); cell.addElement(element); table.addCell(cell); element = this.fifthElement((String) values.get(3), (String) values.get(4), (String) values.get(5)); cell = this.createCell(1, 1); cell.addElement(element); table.addCell(cell); element = this.sixthElement((String) values.get(6), (String) values.get(7)); cell = this.createCell(1, 1); cell.addElement(element); cell.setBorderWidth(0.3f); table.addCell(cell); element = this.seventhElement((String) values.get(8), (String) values.get(9)); cell = this.createCell(1, 1); cell.addElement(element); table.addCell(cell); element = this.eightthElement((String) values.get(10), (String) values.get(11)); cell = this.createCell(2, 1); cell.setBorderWidth(0.3f); cell.addElement(element); table.addCell(cell); element = this.ninethElement((String) values.get(12), (String) values.get(13), (String) values.get(14)); cell = this.createCell(1, 1); cell.setBorderWidth(0.3f); cell.addElement(element); table.addCell(cell); element = this.tenthElement((String) values.get(15), (String) values.get(16), (String) values.get(17)); cell = this.createCell(1, 1); cell.setBorderWidth(0.3f); cell.addElement(element); table.addCell(cell); element = this.eleventhElement((String) values.get(18), (String) values.get(19), (String) values.get(20)); cell = this.createCell(1, 1); cell.setBorderWidth(0.3f); cell.addElement(element); table.addCell(cell); element = this.twelvethElement((String) values.get(21), (String) values.get(22), (String) values.get(23)); cell = this.createCell(1, 1); cell.setBorderWidth(0.3f); cell.addElement(element); table.addCell(cell); element = this.thirteenthElement((String) values.get(24), (String) values.get(25)); cell = this.createCell(1, 1); cell.setBorderWidth(0.3f); cell.addElement(element); table.addCell(cell); element = this.fourteenthElement((String) values.get(26), (String) values.get(27)); cell = this.createCell(1, 1); cell.setBorderWidth(0.3f); cell.addElement(element); table.addCell(cell); element = this.fifteenthElement((String) values.get(28)); cell = this.createCell(2, 1); cell.setBorderWidth(0.3f); cell.addElement(element); table.addCell(cell); return table; } /** * Creates new cells * * @param colspan * @param rowspan * @return */ private PdfPCell createCell(int colspan, int rowspan) { PdfPCell cell = new PdfPCell(); cell.setPadding(0); cell.setBorderWidth(0.3f); cell.setColspan(colspan); cell.setRowspan(rowspan); return cell; } private Element firstElement(String value) { float leading = 9f; Phrase label = new Phrase("Pfeife Nr. ", this.arial); Phrase ref = new Phrase(value, courier); Paragraph info = new Paragraph(); info.setLeading(leading); info.add(label); info.add(ref); return info; } private Element thirdElement(String hersteller, String modell) { float leading = 9f; PdfPTable table = new PdfPTable(2); table.setWidthPercentage(100f); PdfPCell cell; cell = new PdfPCell(new Paragraph("Hersteller", arialSmall)); cell.setPadding(2); cell.setGrayFill(0.85f); cell.setBorderWidth(0.3f); table.addCell(cell); cell = new PdfPCell(new Paragraph("Modell", arialSmall)); cell.setPadding(2); cell.setBorderWidth(0.3f); cell.setGrayFill(0.85f); table.addCell(cell); cell = new PdfPCell(); cell.setPadding(2); cell.setBorderWidth(0.3f); cell.setFixedHeight(30f); Paragraph herstellerInfo = new Paragraph(hersteller, courier); herstellerInfo.setLeading(leading); cell.addElement(herstellerInfo); table.addCell(cell); cell = new PdfPCell(); cell.setPadding(2); cell.setBorderWidth(0.3f); cell.setFixedHeight(30f); Paragraph modellInfo = new Paragraph(modell, courier); modellInfo.setLeading(leading); cell.addElement(modellInfo); table.addCell(cell); return table; } private Image fourthLogoElement(String path) throws BadElementException { //String path = "/home/meteor/pipe-manager/pictures/1_Vauen_Basic/03.jpg"; Image image = null; try { ImageIcon icon = new ImageIcon(path.toString()); java.awt.Image img = icon.getImage(); java.awt.Image newimg = img.getScaledInstance(154, -1, java.awt.Image.SCALE_SMOOTH); image = Image.getInstance(newimg, null); } catch (BadElementException e) { } catch (MalformedURLException e) { } catch (IOException e) { } return image; } private Element fifthElement(String land, String edition, String jahr) { float leading = 9f; PdfPTable table = new PdfPTable(3); table.setWidthPercentage(100f); PdfPCell cell; //Hier die Header zuerst cell = new PdfPCell(new Paragraph("Land", arialSmall)); cell.setPadding(2); cell.setGrayFill(0.85f); cell.setBorderWidth(0.3f); table.addCell(cell); cell = new PdfPCell(new Paragraph("Edition", arialSmall)); cell.setPadding(2); cell.setGrayFill(0.85f); cell.setBorderWidth(0.3f); table.addCell(cell); cell = new PdfPCell(new Paragraph("Jahr", arialSmall)); cell.setPadding(2); cell.setGrayFill(0.85f); cell.setBorderWidth(0.3f); table.addCell(cell); //Ab hier die Werte cell = new PdfPCell(); cell.setPadding(2); cell.setBorderWidth(0.3f); Paragraph herkunftInfo = new Paragraph(land, courier); herkunftInfo.setLeading(leading); cell.addElement(herkunftInfo); table.addCell(cell); cell = new PdfPCell(); cell.setPadding(2); cell.setBorderWidth(0.3f); Paragraph editionInfo = new Paragraph(edition, courier); editionInfo.setLeading(leading); cell.addElement(editionInfo); table.addCell(cell); cell = new PdfPCell(); cell.setBorderWidth(0.3f); cell.setFixedHeight(30f); Paragraph yearInfo = new Paragraph(jahr, courier); yearInfo.setLeading(leading); cell.addElement(yearInfo); table.addCell(cell); return table; } private Element sixthElement(String grundform, String mundstck) { float leading = 9f; PdfPTable table = new PdfPTable(2); table.setWidthPercentage(100f); PdfPCell cell; cell = new PdfPCell(new Paragraph("Grundform", arialSmall)); cell.setPadding(2); cell.setGrayFill(0.85f); cell.setBorderWidth(0.3f); table.addCell(cell); cell = new PdfPCell(new Paragraph("Mundstck", arialSmall)); cell.setPadding(2); cell.setBorderWidth(0.3f); cell.setGrayFill(0.85f); table.addCell(cell); cell = new PdfPCell(); cell.setPadding(2); cell.setBorderWidth(0.3f); cell.setFixedHeight(30f); Paragraph herstellerInfo = new Paragraph(grundform, courier); herstellerInfo.setLeading(leading); cell.addElement(herstellerInfo); table.addCell(cell); cell = new PdfPCell(); cell.setPadding(2); cell.setBorderWidth(0.3f); cell.setFixedHeight(30f); Paragraph modellInfo = new Paragraph(mundstck, courier); modellInfo.setLeading(leading); cell.addElement(modellInfo); table.addCell(cell); return table; } private Element seventhElement(String kopfmat, String mundmat) { float leading = 9f; PdfPTable table = new PdfPTable(2); table.setWidthPercentage(100f); PdfPCell cell; cell = new PdfPCell(new Paragraph("Kopfmaterial", arialSmall)); cell.setPadding(2); cell.setGrayFill(0.85f); cell.setBorderWidth(0.3f); table.addCell(cell); cell = new PdfPCell(new Paragraph("Material Mundstck", arialSmall)); cell.setPadding(2); cell.setBorderWidth(0.3f); cell.setGrayFill(0.85f); table.addCell(cell); cell = new PdfPCell(); cell.setPadding(2); cell.setBorderWidth(0.3f); cell.setFixedHeight(30f); Paragraph mundMatInfo = new Paragraph(kopfmat, courier); mundMatInfo.setLeading(leading); cell.addElement(mundMatInfo); table.addCell(cell); cell = new PdfPCell(); cell.setPadding(2); cell.setBorderWidth(0.3f); cell.setFixedHeight(30f); Paragraph modellInfo = new Paragraph(mundmat, courier); modellInfo.setLeading(leading); cell.addElement(modellInfo); table.addCell(cell); return table; } private Element eightthElement(String applikation, String tabak) { float leading = 9f; PdfPTable table = new PdfPTable(2); table.setWidthPercentage(100f); PdfPCell cell; cell = new PdfPCell(new Paragraph("Applikation", arialSmall)); cell.setPadding(2); cell.setGrayFill(0.85f); cell.setBorderWidth(0.3f); table.addCell(cell); cell = new PdfPCell(new Paragraph("Eingerauchter Tabak", arialSmall)); cell.setPadding(2); cell.setBorderWidth(0.3f); cell.setGrayFill(0.85f); table.addCell(cell); cell = new PdfPCell(); cell.setPadding(2); cell.setBorderWidth(0.3f); cell.setFixedHeight(30f); Paragraph mundMatInfo = new Paragraph(applikation, courier); mundMatInfo.setLeading(leading); cell.addElement(mundMatInfo); table.addCell(cell); cell = new PdfPCell(); cell.setPadding(2); cell.setBorderWidth(0.3f); cell.setFixedHeight(30f); Paragraph modellInfo = new Paragraph(tabak, courier); modellInfo.setLeading(leading); cell.addElement(modellInfo); table.addCell(cell); return table; } private Element ninethElement(String kaufpreis, String gekauft_bei, String datum) { float leading = 9f; PdfPTable table = new PdfPTable(3); table.setWidthPercentage(100f); PdfPCell cell; //Hier die Header zuerst cell = new PdfPCell(new Paragraph("Einstandspreis", arialSmall)); cell.setPadding(2); cell.setGrayFill(0.85f); cell.setBorderWidth(0.3f); table.addCell(cell); cell = new PdfPCell(new Paragraph("Gekauft bei / von", arialSmall)); cell.setPadding(2); cell.setGrayFill(0.85f); cell.setBorderWidth(0.3f); table.addCell(cell); cell = new PdfPCell(new Paragraph("Kaufdatum", arialSmall)); cell.setPadding(2); cell.setGrayFill(0.85f); cell.setBorderWidth(0.3f); table.addCell(cell); //Ab hier die Werte cell = new PdfPCell(); cell.setPadding(2); cell.setBorderWidth(0.3f); Paragraph herkunftInfo = new Paragraph(kaufpreis, courier); herkunftInfo.setLeading(leading); cell.addElement(herkunftInfo); table.addCell(cell); cell = new PdfPCell(); cell.setPadding(2); cell.setBorderWidth(0.3f); Paragraph editionInfo = new Paragraph(gekauft_bei, courier); editionInfo.setLeading(leading); cell.addElement(editionInfo); table.addCell(cell); cell = new PdfPCell(); cell.setBorderWidth(0.3f); cell.setFixedHeight(30f); Paragraph yearInfo = new Paragraph(datum, courier); yearInfo.setLeading(leading); cell.addElement(yearInfo); table.addCell(cell); return table; } private Element tenthElement(String verkaufspreis, String verkauft_an, String datum) { float leading = 9f; PdfPTable table = new PdfPTable(3); table.setWidthPercentage(100f); PdfPCell cell; //Hier die Header zuerst cell = new PdfPCell(new Paragraph("Verkaufspreis", arialSmall)); cell.setPadding(2); cell.setGrayFill(0.85f); cell.setBorderWidth(0.3f); table.addCell(cell); cell = new PdfPCell(new Paragraph("Verkauft an", arialSmall)); cell.setPadding(2); cell.setGrayFill(0.85f); cell.setBorderWidth(0.3f); table.addCell(cell); cell = new PdfPCell(new Paragraph("Verkaufsdatum", arialSmall)); cell.setPadding(2); cell.setGrayFill(0.85f); cell.setBorderWidth(0.3f); table.addCell(cell); //Ab hier die Werte cell = new PdfPCell(); cell.setPadding(2); cell.setBorderWidth(0.3f); Paragraph herkunftInfo = new Paragraph(verkaufspreis, courier); herkunftInfo.setLeading(leading); cell.addElement(herkunftInfo); table.addCell(cell); cell = new PdfPCell(); cell.setPadding(2); cell.setBorderWidth(0.3f); Paragraph editionInfo = new Paragraph(verkauft_an, courier); editionInfo.setLeading(leading); cell.addElement(editionInfo); table.addCell(cell); cell = new PdfPCell(); cell.setBorderWidth(0.3f); cell.setFixedHeight(30f); Paragraph yearInfo = new Paragraph(datum, courier); yearInfo.setLeading(leading); cell.addElement(yearInfo); table.addCell(cell); return table; } private Element eleventhElement(String oberflaeche, String bohrung, String filter) { float leading = 9f; PdfPTable table = new PdfPTable(3); table.setWidthPercentage(100f); PdfPCell cell; //Hier die Header zuerst cell = new PdfPCell(new Paragraph("Oberflche", arialSmall)); cell.setPadding(2); cell.setGrayFill(0.85f); cell.setBorderWidth(0.3f); table.addCell(cell); cell = new PdfPCell(new Paragraph("Bohrung", arialSmall)); cell.setPadding(2); cell.setGrayFill(0.85f); cell.setBorderWidth(0.3f); table.addCell(cell); cell = new PdfPCell(new Paragraph("Filter", arialSmall)); cell.setPadding(2); cell.setGrayFill(0.85f); cell.setBorderWidth(0.3f); table.addCell(cell); //Ab hier die Werte cell = new PdfPCell(); cell.setPadding(2); cell.setBorderWidth(0.3f); Paragraph herkunftInfo = new Paragraph(oberflaeche, courier); herkunftInfo.setLeading(leading); cell.addElement(herkunftInfo); table.addCell(cell); cell = new PdfPCell(); cell.setPadding(2); cell.setBorderWidth(0.3f); Paragraph editionInfo = new Paragraph(bohrung, courier); editionInfo.setLeading(leading); cell.addElement(editionInfo); table.addCell(cell); cell = new PdfPCell(); cell.setBorderWidth(0.3f); cell.setFixedHeight(18f); Paragraph yearInfo = new Paragraph(filter, courier); yearInfo.setLeading(leading); cell.addElement(yearInfo); table.addCell(cell); return table; } private Element twelvethElement(String laenge, String kopfhoehe, String kopfdurchmesser) { float leading = 9f; PdfPTable table = new PdfPTable(3); table.setWidthPercentage(100f); PdfPCell cell; //Hier die Header zuerst cell = new PdfPCell(new Paragraph("Lnge", arialSmall)); cell.setPadding(2); cell.setGrayFill(0.85f); cell.setBorderWidth(0.3f); table.addCell(cell); cell = new PdfPCell(new Paragraph("Kopfhhe", arialSmall)); cell.setPadding(2); cell.setGrayFill(0.85f); cell.setBorderWidth(0.3f); table.addCell(cell); cell = new PdfPCell(new Paragraph("Kopfdurchmesser", arialSmall)); cell.setPadding(2); cell.setGrayFill(0.85f); cell.setBorderWidth(0.3f); table.addCell(cell); //Ab hier die Werte cell = new PdfPCell(); cell.setPadding(2); cell.setBorderWidth(0.3f); Paragraph herkunftInfo = new Paragraph(laenge, courier); herkunftInfo.setLeading(leading); cell.addElement(herkunftInfo); table.addCell(cell); cell = new PdfPCell(); cell.setPadding(2); cell.setBorderWidth(0.3f); Paragraph editionInfo = new Paragraph(kopfhoehe, courier); editionInfo.setLeading(leading); cell.addElement(editionInfo); table.addCell(cell); cell = new PdfPCell(); cell.setBorderWidth(0.3f); cell.setFixedHeight(18f); Paragraph yearInfo = new Paragraph(kopfdurchmesser, courier); yearInfo.setLeading(leading); cell.addElement(yearInfo); table.addCell(cell); return table; } private Element thirteenthElement(String gewicht, String farbe) { float leading = 9f; PdfPTable table = new PdfPTable(2); table.setWidthPercentage(100f); PdfPCell cell; cell = new PdfPCell(new Paragraph("Gewicht", arialSmall)); cell.setPadding(2); cell.setGrayFill(0.85f); cell.setBorderWidth(0.3f); table.addCell(cell); cell = new PdfPCell(new Paragraph("Farbe", arialSmall)); cell.setPadding(2); cell.setBorderWidth(0.3f); cell.setGrayFill(0.85f); table.addCell(cell); cell = new PdfPCell(); cell.setPadding(2); cell.setBorderWidth(0.3f); cell.setFixedHeight(18f); Paragraph mundMatInfo = new Paragraph(gewicht, courier); mundMatInfo.setLeading(leading); cell.addElement(mundMatInfo); table.addCell(cell); cell = new PdfPCell(); cell.setPadding(2); cell.setBorderWidth(0.3f); cell.setFixedHeight(18f); Paragraph modellInfo = new Paragraph(farbe, courier); modellInfo.setLeading(leading); cell.addElement(modellInfo); table.addCell(cell); return table; } private Element fourteenthElement(String zustand, String lagerort) { float leading = 9f; PdfPTable table = new PdfPTable(2); table.setWidthPercentage(100f); PdfPCell cell; cell = new PdfPCell(new Paragraph("Zustand", arialSmall)); cell.setPadding(2); cell.setGrayFill(0.85f); cell.setBorderWidth(0.3f); table.addCell(cell); cell = new PdfPCell(new Paragraph("Lagerort", arialSmall)); cell.setPadding(2); cell.setBorderWidth(0.3f); cell.setGrayFill(0.85f); table.addCell(cell); cell = new PdfPCell(); cell.setPadding(2); cell.setBorderWidth(0.3f); cell.setFixedHeight(18f); Paragraph mundMatInfo = new Paragraph(zustand, courier); mundMatInfo.setLeading(leading); cell.addElement(mundMatInfo); table.addCell(cell); cell = new PdfPCell(); cell.setPadding(2); cell.setBorderWidth(0.3f); cell.setFixedHeight(18f); Paragraph modellInfo = new Paragraph(lagerort, courier); modellInfo.setLeading(leading); cell.addElement(modellInfo); table.addCell(cell); return table; } private Element fifteenthElement(String besonderes) { float leading = 9f; PdfPTable table = new PdfPTable(1); table.setWidthPercentage(100f); PdfPCell cell; cell = new PdfPCell(new Paragraph("Besonderes", arialSmall)); cell.setPadding(2); cell.setGrayFill(0.85f); cell.setBorderWidth(0.3f); table.addCell(cell); cell = new PdfPCell(); cell.setPadding(2); cell.setBorderWidth(0.3f); cell.setFixedHeight(30f); Paragraph herstellerInfo = new Paragraph(besonderes, courier); herstellerInfo.setLeading(leading); cell.addElement(herstellerInfo); table.addCell(cell); return table; } private Element FinalElement() { String legal = "Dieses Dokument wurde mit Mat's pipe-manager erstellt."; Paragraph element = new Paragraph(legal, this.arialMini); element.setAlignment(Element.ALIGN_JUSTIFIED); return element; } private ResultSet getDBVals() { try { try { Class.forName("org.sqlite.JDBC"); } catch (ClassNotFoundException ex) { Logger.getLogger(PipeView.class.getName()).log(Level.SEVERE, null, ex); } String dbFileName = "db" + File.separator + "pipedb.db"; String jdbcURL = "jdbc:sqlite:" + dbFileName; Connection conn = DriverManager.getConnection(jdbcURL); Statement statement = conn.createStatement(); statement.setQueryTimeout(30); // set timeout to 30 sec. String queryString = "select * from pipes";// where id = 2"; ResultSet rs = statement.executeQuery(queryString); return rs; } catch (SQLException ex) { Logger.getLogger(PipeView.class.getName()).log(Level.SEVERE, null, ex); } return rs; } }