List of usage examples for org.apache.pdfbox.pdmodel PDPage PDPage
public PDPage(COSDictionary pageDictionary)
From source file:pptxtopdf.TestPptxToPdf.java
public static void main(String[] args) throws FileNotFoundException, IOException, COSVisitorException, OpenXML4JException { // TODO code application logic here String filepath = "/home/sagar/Desktop/Shareback/test.pptx"; FileInputStream is = new FileInputStream(filepath); XMLSlideShow pptx = new XMLSlideShow(is); Dimension pgsize = pptx.getPageSize(); int idx = 1;/*from ww w . j a v a 2 s. c o m*/ for (XSLFSlide slide : pptx.getSlides()) { BufferedImage img = new BufferedImage(pgsize.width, pgsize.height, BufferedImage.TYPE_INT_RGB); Graphics2D graphics = img.createGraphics(); // clear the drawing area graphics.setPaint(Color.white); graphics.fill(new Rectangle2D.Float(0, 0, pgsize.width, pgsize.height)); // render slide.draw(graphics); // save the output FileOutputStream out = new FileOutputStream("/home/sagar/Desktop/Shareback/img/slide-" + idx + ".jpg"); javax.imageio.ImageIO.write(img, "jpg", out); out.close(); idx++; } String someimg = "/home/sagar/Desktop/Shareback/pptx/img/"; PDDocument document = new PDDocument(); File file = new File(someimg); if (!file.exists()) file.mkdir(); if (file.isDirectory()) { for (File f : file.listFiles()) { InputStream in = new FileInputStream(f); BufferedImage bimg = ImageIO.read(in); float width = bimg.getWidth(); float height = bimg.getHeight(); PDPage page = new PDPage(new PDRectangle(width + 10, height + 10)); document.addPage(page); PDXObjectImage img = new PDJpeg(document, new FileInputStream(f)); PDPageContentStream contentStream = new PDPageContentStream(document, page); contentStream.drawImage(img, 0, 0); contentStream.close(); in.close(); } document.save("/home/sagar/Desktop/Shareback/test-generated-pptx.pdf"); document.close(); } else { System.out.println(someimg + "is not a Directory"); } }
From source file:projekt.CustomRenderer.java
public void raport_lokalny() throws IOException, ClassNotFoundException, SQLException { loginController login = new loginController(); String zapytanie = "select count(*) as Aktualne from projekty, (SELECT Nazwa, Opis, Status_zadania, idUzytkownika,projekt from zadania where Status_zadania = 'Aktualne' and idUzytkownika = '" + login.uzytkownikID + "') x where projekty.Nazwa = x.projekt"; String zapytanie1 = "select count(*) as FORTEST from projekty, (SELECT Nazwa, Opis, Status_zadania, idUzytkownika,projekt from zadania where Status_zadania = 'FORTEST' and idUzytkownika = '" + login.uzytkownikID + "') x where projekty.Nazwa = x.projekt"; String zapytanie2 = "select count(*) as Zakonczone from projekty, (SELECT Nazwa, Opis, Status_zadania, idUzytkownika,projekt from zadania where Status_zadania = 'Zakonczone' and idUzytkownika = '" + login.uzytkownikID + "') x where projekty.Nazwa = x.projekt"; Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/pz?characterEncoding=utf8", "root", ""); PreparedStatement statment;//w ww. j a v a 2s . co m ResultSet result; double odp = 0, odp1 = 0, odp2 = 0; statment = con.prepareStatement(zapytanie); result = statment.executeQuery(); if (result.next()) { odp = result.getDouble("Aktualne"); } statment = con.prepareStatement(zapytanie1); result = statment.executeQuery(); if (result.next()) { odp1 = result.getDouble("FORTEST"); } statment = con.prepareStatement(zapytanie2); result = statment.executeQuery(); if (result.next()) { odp2 = result.getDouble("Zakonczone"); } //tu tez zmienic na id statment = con.prepareStatement( "SELECT CONCAT(imie, ' ', nazwisko) as osoba from uzytkownicy WHERE idUzytkownika = '" + login.uzytkownikID + "'"); result = statment.executeQuery(); String bbc = ""; if (result.next()) { bbc = result.getString(1); } DefaultCategoryDataset set2 = new DefaultCategoryDataset(); set2.setValue(odp, "", "Aktualne"); set2.setValue(odp1, "", "FORTEST"); set2.setValue(odp2, "", "Zakonczone"); JFreeChart chart = ChartFactory.createBarChart( "Wszystkie zadania z projektow za ktore odpowiada " + result.getString(1), "Zadania", "Ilosc", set2, PlotOrientation.VERTICAL, false, true, false); final CategoryItemRenderer renderer = new CustomRenderer(new Paint[] { Color.blue, Color.pink, Color.cyan, Color.yellow, Color.orange, Color.cyan, Color.magenta, Color.blue }); final CategoryPlot plot = chart.getCategoryPlot(); plot.setNoDataMessage("NO DATA!"); renderer.setItemLabelsVisible(true); final ItemLabelPosition p = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, 45.0); renderer.setPositiveItemLabelPosition(p); plot.setRenderer(renderer); ByteArrayOutputStream out = new ByteArrayOutputStream(); ChartUtilities.writeChartAsJPEG(out, chart, 450, 600); DateFormat dataformat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); DateFormat dataformat1 = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss"); Date data = new Date(); String fileName = "Raport lokalny " + dataformat1.format(data) + ".pdf"; try { PDRectangle PAGE_SIZE = PDRectangle.A4; PDDocument doc = new PDDocument(); PDFont font = PDType0Font.load(doc, getClass().getResourceAsStream("/fonts/RobotoCondensed-Regular.ttf")); PDFont font1 = PDType0Font.load(doc, getClass().getResourceAsStream("/fonts/RobotoCondensed-Bold.ttf")); PDPage page = new PDPage(PAGE_SIZE); PDPage page1 = new PDPage(PAGE_SIZE); doc.addPage(page); PDPageContentStream content = new PDPageContentStream(doc, page); //naglowek strona 1 Naglowek1(content, dataformat, data); //stopka strona1 Stopka(content, doc); content.beginText(); content.setFont(font1, 48); content.moveTextPositionByAmount(135, 550); content.showText("Raport lokalny"); content.endText(); content.beginText(); content.setFont(font, 22); content.moveTextPositionByAmount(30, 250); content.showText("Wersja systemu : 1.0"); content.newLine(); content.moveTextPositionByAmount(0, 35); content.showText("Autor raportu : " + result.getString("osoba")); content.endText(); content.close(); PDPageContentStream content1 = new PDPageContentStream(doc, page1); PDPage page2 = new PDPage(PAGE_SIZE); doc.addPage(page2); PDPageContentStream content2 = new PDPageContentStream(doc, page2); Naglowek1(content2, dataformat, data); //stopka strona2 Stopka(content2, doc); content2.beginText(); content2.setFont(font, 14); content2.moveTextPositionByAmount(30, 775); content2.showText("Wszystkie projekty za ktre odpowiada: " + result.getString(1)); statment = con.prepareStatement( "Select Nazwa, Opis, Poczatek, Koniec, ludzie from projekty where idUzytkownika='" + login.uzytkownikID + "'"); result = statment.executeQuery(); content2.newLine(); int liczba = 615; content2.moveTextPositionByAmount(0, -15); while (result.next()) { content2.newLine(); content2.moveTextPositionByAmount(0, -22); liczba += 22; //content2.showText("Nazwa : "+result.getString("Nazwa")+" Opis: "+result.getString("Opis")+" Data rozpoczecia: "+result.getString("Poczatek")+" Data zakonczenia: "+result.getString("Koniec")); content2.showText("Nazwa : " + result.getString("Nazwa") + " Opis: " + result.getString(1)); content2.newLine(); content2.moveTextPositionByAmount(0, -17); liczba += 22; content2.showText("Data rozpoczecia: " + result.getString("Poczatek") + " Data zakonczenia: " + result.getString("Koniec")); } content2.endText(); // content2.setLineWidth(2); // content2.moveTo(10, liczba + 5); // content2.lineTo(10, liczba +5); // content2.closeAndStroke(); DateFormat dataformat2 = new SimpleDateFormat("yyyy-MM-dd"); statment = con.prepareStatement("Select count(*) as 'Aktualne' from projekty where Koniec > '" + dataformat2.format(data) + "' and idUzytkownika='" + login.uzytkownikID + "'"); result = statment.executeQuery(); int aktualne = 0, zakonczone = 0; if (result.next()) { aktualne = result.getInt("Aktualne"); } statment = con.prepareStatement("Select count(*) as 'Zakonczone' from projekty where Koniec < '" + dataformat2.format(data) + "' and idUzytkownika='" + login.uzytkownikID + "'"); result = statment.executeQuery(); if (result.next()) { zakonczone = result.getInt("Zakonczone"); } DefaultPieDataset pieDataset = new DefaultPieDataset(); pieDataset.setValue("Aktualne", aktualne); pieDataset.setValue("Zakonczone", zakonczone); JFreeChart chart1 = ChartFactory.createPieChart("Zestawienia projekt za ktore odpowiada" + bbc, // Title pieDataset, // Dataset true, // Show legend true, // Use tooltips false // Configure chart to generate URLs? ); PiePlot plot1 = (PiePlot) chart1.getPlot(); plot1.setSectionPaint("Aktualne", Color.blue); plot1.setSectionPaint("Zakonczone", Color.yellow); plot1.setExplodePercent("Aktualne", 0.10); plot1.setSimpleLabels(true); PieSectionLabelGenerator gen = new StandardPieSectionLabelGenerator("{0}: {1} ({2})", new DecimalFormat("0"), new DecimalFormat("0%")); plot1.setLabelGenerator(gen); ByteArrayOutputStream out1 = new ByteArrayOutputStream(); ChartUtilities.writeChartAsJPEG(out1, chart1, 450, 600); PDImageXObject img1 = JPEGFactory.createFromStream(doc, new ByteArrayInputStream(out1.toByteArray())); content2.close(); PDPage page3 = new PDPage(PAGE_SIZE); doc.addPage(page3); PDPageContentStream content3 = new PDPageContentStream(doc, page3); Naglowek1(content3, dataformat, data); //stopka strona2 Stopka(content3, doc); content3.drawImage(img1, 50, 50); content3.close(); PDPage page4 = new PDPage(PAGE_SIZE); doc.addPage(page4); PDPageContentStream content4 = new PDPageContentStream(doc, page4); Naglowek1(content4, dataformat, data); //stopka strona2 Stopka(content4, doc); content4.beginText(); content4.setFont(font, 14); content4.moveTextPositionByAmount(30, 780); content4.showText("Wszystkie zadania w projektach za ktore odpowiada:" + bbc); statment = con.prepareStatement( "SELECT zadania.Nazwa,zadania.Opis,zadania.Status_zadania,zadania.projekt, z.Imie, z.Nazwisko,CONCAT(y.imie, ' ' , y.nazwisko) as 'UZY' FROM zadania , (select Nazwa from projekty where idUzytkownika = '" + login.uzytkownikID + "') x, (SELECT imie, nazwisko, idUzytkownika from uzytkownicy) y,(SELECT imie, nazwisko, idUzytkownika from uzytkownicy where idUzytkownika = '" + login.uzytkownikID + "') z WHERE zadania.projekt = x.Nazwa LIMIT 12"); //poprawic result = statment.executeQuery(); content4.newLine(); int nw = 850; content4.moveTextPositionByAmount(0, -15); nw -= 15; while (result.next()) { content4.newLine(); nw -= 22; content4.moveTextPositionByAmount(0, -22); //content2.showText("Nazwa : "+result.getString("Nazwa")+" Opis: "+result.getString("Opis")+" Data rozpoczecia: "+result.getString("Poczatek")+" Data zakonczenia: "+result.getString("Koniec")); content4.showText("Nazwa : " + result.getString("zadania.Nazwa")); content4.newLine(); nw -= 17; content4.moveTextPositionByAmount(0, -17); content4.showText(" Opis: " + result.getString("zadania.Opis") + " Status zadania: " + result.getString("zadania.Status_zadania")); content4.newLine(); nw -= 17; content4.moveTextPositionByAmount(0, -17); content4.showText(" Projekt: " + result.getString("zadania.projekt") + " Przydzielona osoba do zadania: " + result.getString("UZY")); } content4.endText(); content4.close(); statment = con.prepareStatement( "SELECT count(*) as 'liczba' FROM `zadania` where idUzytkownika='" + login.uzytkownikID + "'"); //poprawic result = statment.executeQuery(); if (result.next()) { } statment = con.prepareStatement( "SELECT zadania.Nazwa,zadania.Opis,zadania.Status_zadania,zadania.projekt, z.Imie, z.Nazwisko,CONCAT(y.imie, \" \", y.nazwisko) as \"UZY\" FROM zadania , (select Nazwa from projekty where idUzytkownika = '" + login.uzytkownikID + "') x, (SELECT imie, nazwisko, idUzytkownika from uzytkownicy) y,(SELECT imie, nazwisko, idUzytkownika from uzytkownicy where idUzytkownika = '" + login.uzytkownikID + "') z WHERE zadania.projekt = x.Nazwa LIMIT 12," + result.getInt(1) + ""); result = statment.executeQuery(); PDPage page5 = new PDPage(PAGE_SIZE); doc.addPage(page5); PDPageContentStream content5 = new PDPageContentStream(doc, page5); Naglowek1(content5, dataformat, data); //stopka strona2 Stopka(content5, doc); content5.beginText(); content5.setFont(font, 14); content5.moveTextPositionByAmount(30, 700); while (result.next()) { content5.newLine(); nw -= 22; content5.moveTextPositionByAmount(0, -22); //content2.showText("Nazwa : "+result.getString("Nazwa")+" Opis: "+result.getString("Opis")+" Data rozpoczecia: "+result.getString("Poczatek")+" Data zakonczenia: "+result.getString("Koniec")); content5.showText("Nazwa : " + result.getString("zadania.Nazwa")); content5.newLine(); nw -= 17; content5.moveTextPositionByAmount(0, -17); content5.showText(" Opis: " + result.getString("zadania.Opis") + " Status zadania: " + result.getString("zadania.Status_zadania")); content5.newLine(); nw -= 17; content5.moveTextPositionByAmount(0, -17); content5.showText(" Projekt: " + result.getString("zadania.projekt") + " Przydzielona osoba do zadania: " + result.getString("UZY")); } content5.endText(); content5.close(); doc.addPage(page1); //naglowek strona 2 Naglowek1(content1, dataformat, data); //stopka strona2 Stopka(content1, doc); PDImageXObject img = JPEGFactory.createFromStream(doc, new ByteArrayInputStream(out.toByteArray())); content1.drawImage(img, 50, 50); content1.close(); doc.save(fileName); doc.close(); } catch (Exception e) { System.err.println(e.getMessage()); } }
From source file:projekt.CustomRenderer.java
public void raport_globalny() throws IOException, ClassNotFoundException, SQLException { String zapytanie = "select count(*) as Aktualne from zadania where Status_zadania='Aktualne'"; String zapytanie1 = "select count(*) as FORTEST from zadania where Status_zadania='FORTEST'"; String zapytanie2 = "select count(*) as Zakonczone from zadania where Status_zadania='Zakonczone'"; Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/pz?characterEncoding=utf8", "root", ""); PreparedStatement statment;//from w w w . j ava 2s .c o m ResultSet result; double odp = 0, odp1 = 0, odp2 = 0; statment = con.prepareStatement(zapytanie); result = statment.executeQuery(); if (result.next()) { odp = result.getDouble("Aktualne"); } statment = con.prepareStatement(zapytanie1); result = statment.executeQuery(); if (result.next()) { odp1 = result.getDouble("FORTEST"); } statment = con.prepareStatement(zapytanie2); result = statment.executeQuery(); if (result.next()) { odp2 = result.getDouble("Zakonczone"); } loginController login = new loginController(); statment = con.prepareStatement( "SELECT CONCAT(imie, ' ', nazwisko) as osoba from uzytkownicy WHERE idUzytkownika = '" + login.uzytkownikID + "'"); result = statment.executeQuery(); String bbc = ""; if (result.next()) { bbc = result.getString(1); } DefaultCategoryDataset set2 = new DefaultCategoryDataset(); set2.setValue(odp, "", "Aktualne"); set2.setValue(odp1, "", "FORTEST"); set2.setValue(odp2, "", "Zakonczone"); JFreeChart chart = ChartFactory.createBarChart("Wszystkie zadania w bazie", "Zadania", "Ilosc", set2, PlotOrientation.VERTICAL, false, true, false); final CategoryItemRenderer renderer = new CustomRenderer(new Paint[] { Color.red, Color.blue, Color.green, Color.yellow, Color.orange, Color.cyan, Color.magenta, Color.blue }); final CategoryPlot plot = chart.getCategoryPlot(); plot.setNoDataMessage("NO DATA!"); renderer.setItemLabelsVisible(true); final ItemLabelPosition p = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, 45.0); renderer.setPositiveItemLabelPosition(p); plot.setRenderer(renderer); ByteArrayOutputStream out = new ByteArrayOutputStream(); ChartUtilities.writeChartAsJPEG(out, chart, 450, 600); DateFormat dataformat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); DateFormat dataformat1 = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss"); Date data = new Date(); String fileName = "Raport globalny " + dataformat1.format(data) + ".pdf"; try { PDRectangle PAGE_SIZE = PDRectangle.A4; PDDocument doc = new PDDocument(); PDFont font = PDType0Font.load(doc, getClass().getResourceAsStream("/fonts/RobotoCondensed-Regular.ttf")); PDFont font1 = PDType0Font.load(doc, getClass().getResourceAsStream("/fonts/RobotoCondensed-Bold.ttf")); PDPage page = new PDPage(PAGE_SIZE); PDPage page1 = new PDPage(PAGE_SIZE); doc.addPage(page); PDPageContentStream content = new PDPageContentStream(doc, page); //naglowek strona 1 Naglowek(content, dataformat, data); //stopka strona1 Stopka(content, doc); content.beginText(); content.setFont(font1, 48); content.moveTextPositionByAmount(135, 550); content.showText("Raport globalny"); content.endText(); content.beginText(); content.setFont(font, 22); content.moveTextPositionByAmount(30, 250); content.showText("Wersja systemu : 1.0"); content.newLine(); content.moveTextPositionByAmount(0, 35); content.showText("Autor raportu : " + result.getString("osoba")); content.endText(); content.close(); PDPageContentStream content1 = new PDPageContentStream(doc, page1); PDPage page2 = new PDPage(PAGE_SIZE); doc.addPage(page2); PDPageContentStream content2 = new PDPageContentStream(doc, page2); Naglowek(content2, dataformat, data); //stopka strona2 Stopka(content2, doc); content2.beginText(); content2.setFont(font, 14); content2.moveTextPositionByAmount(30, 775); content2.showText("Wszystkie projekty z bazy danych:"); statment = con.prepareStatement("Select Nazwa, Opis, Poczatek, Koniec, ludzie from projekty"); result = statment.executeQuery(); content2.newLine(); int liczba = 615; content2.moveTextPositionByAmount(0, -15); while (result.next()) { content2.newLine(); content2.moveTextPositionByAmount(0, -22); liczba += 22; //content2.showText("Nazwa : "+result.getString("Nazwa")+" Opis: "+result.getString("Opis")+" Data rozpoczecia: "+result.getString("Poczatek")+" Data zakonczenia: "+result.getString("Koniec")); content2.showText("Nazwa : " + result.getString("Nazwa") + " Opis: " + result.getString("Opis")); content2.newLine(); content2.moveTextPositionByAmount(0, -17); liczba += 22; content2.showText("Data rozpoczecia: " + result.getString("Poczatek") + " Data zakonczenia: " + result.getString("Koniec")); } content2.endText(); // content2.setLineWidth(2); // content2.moveTo(10, liczba + 5); // content2.lineTo(10, liczba +5); // content2.closeAndStroke(); DateFormat dataformat2 = new SimpleDateFormat("yyyy-MM-dd"); statment = con.prepareStatement("Select count(*) as 'Aktualne' from projekty where Koniec > '" + dataformat2.format(data) + "'"); result = statment.executeQuery(); int aktualne = 0, zakonczone = 0; if (result.next()) { aktualne = result.getInt("Aktualne"); } System.out.println("aktualne:" + aktualne); statment = con.prepareStatement("Select count(*) as 'Zakonczone' from projekty where Koniec < '" + dataformat2.format(data) + "'"); result = statment.executeQuery(); if (result.next()) { zakonczone = result.getInt("Zakonczone"); } System.out.println("zakonczone:" + zakonczone); DefaultPieDataset pieDataset = new DefaultPieDataset(); pieDataset.setValue("Aktualne", aktualne); pieDataset.setValue("Zakonczone", zakonczone); JFreeChart chart1 = ChartFactory.createPieChart("Zestawienia projektw", // Title pieDataset, // Dataset true, // Show legend true, // Use tooltips false // Configure chart to generate URLs? ); PiePlot plot1 = (PiePlot) chart1.getPlot(); plot1.setSectionPaint("Aktualne", Color.green); plot1.setSectionPaint("Zakonczone", Color.red); plot1.setExplodePercent("Aktualne", 0.10); plot1.setSimpleLabels(true); PieSectionLabelGenerator gen = new StandardPieSectionLabelGenerator("{0}: {1} ({2})", new DecimalFormat("0"), new DecimalFormat("0%")); plot1.setLabelGenerator(gen); ByteArrayOutputStream out1 = new ByteArrayOutputStream(); ChartUtilities.writeChartAsJPEG(out1, chart1, 450, 600); PDImageXObject img1 = JPEGFactory.createFromStream(doc, new ByteArrayInputStream(out1.toByteArray())); content2.close(); PDPage page3 = new PDPage(PAGE_SIZE); doc.addPage(page3); PDPageContentStream content3 = new PDPageContentStream(doc, page3); Naglowek(content3, dataformat, data); //stopka strona2 Stopka(content3, doc); content3.drawImage(img1, 50, 50); content3.close(); PDPage page4 = new PDPage(PAGE_SIZE); doc.addPage(page4); PDPageContentStream content4 = new PDPageContentStream(doc, page4); Naglowek(content4, dataformat, data); //stopka strona2 Stopka(content4, doc); content4.beginText(); content4.setFont(font, 14); content4.moveTextPositionByAmount(30, 780); content4.showText("Wszystkie zadania w bazie:"); statment = con.prepareStatement( "SELECT `Nazwa`,`Opis`,`Status_zadania`,`projekt`, CONCAT(x.imie, \" \", x.nazwisko) as \"UZY\" FROM `zadania` , (SELECT imie, nazwisko, idUzytkownika from uzytkownicy) X WHERE zadania.idUzytkownika=x.idUzytkownika limit 12"); result = statment.executeQuery(); content4.newLine(); int nw = 850; content4.moveTextPositionByAmount(0, -15); nw -= 15; while (result.next()) { content4.newLine(); nw -= 22; content4.moveTextPositionByAmount(0, -22); //content2.showText("Nazwa : "+result.getString("Nazwa")+" Opis: "+result.getString("Opis")+" Data rozpoczecia: "+result.getString("Poczatek")+" Data zakonczenia: "+result.getString("Koniec")); content4.showText("Nazwa : " + result.getString("Nazwa")); content4.newLine(); nw -= 17; content4.moveTextPositionByAmount(0, -17); content4.showText(" Opis: " + result.getString("Opis") + " Status zadania: " + result.getString("Status_zadania")); content4.newLine(); nw -= 17; content4.moveTextPositionByAmount(0, -17); content4.showText(" Projekt: " + result.getString("projekt") + " Przydzielona osoba do zadania: " + result.getString("UZY")); } content4.endText(); content4.close(); statment = con.prepareStatement("SELECT count(*) as 'liczba' FROM `zadania`"); result = statment.executeQuery(); if (result.next()) { } statment = con.prepareStatement( "SELECT `Nazwa`,`Opis`,`Status_zadania`,`projekt`, CONCAT(x.imie, \" \", x.nazwisko) as \"UZY\" FROM `zadania` , (SELECT imie, nazwisko, idUzytkownika from uzytkownicy) X WHERE zadania.idUzytkownika=x.idUzytkownika limit 12," + result.getInt(1) + ""); result = statment.executeQuery(); PDPage page5 = new PDPage(PAGE_SIZE); doc.addPage(page5); PDPageContentStream content5 = new PDPageContentStream(doc, page5); Naglowek(content5, dataformat, data); //stopka strona2 Stopka(content5, doc); content5.beginText(); content5.setFont(font, 14); content5.moveTextPositionByAmount(30, 700); while (result.next()) { content5.newLine(); nw -= 22; content5.moveTextPositionByAmount(0, -22); //content2.showText("Nazwa : "+result.getString("Nazwa")+" Opis: "+result.getString("Opis")+" Data rozpoczecia: "+result.getString("Poczatek")+" Data zakonczenia: "+result.getString("Koniec")); content5.showText("Nazwa : " + result.getString("Nazwa")); content5.newLine(); nw -= 17; content5.moveTextPositionByAmount(0, -17); content5.showText(" Opis: " + result.getString("Opis") + " Status zadania: " + result.getString("Status_zadania")); content5.newLine(); nw -= 17; content5.moveTextPositionByAmount(0, -17); content5.showText(" Projekt: " + result.getString("projekt") + " Przydzielona osoba do zadania: " + result.getString("UZY")); } content5.endText(); content5.close(); doc.addPage(page1); //naglowek strona 2 Naglowek(content1, dataformat, data); //stopka strona2 Stopka(content1, doc); PDImageXObject img = JPEGFactory.createFromStream(doc, new ByteArrayInputStream(out.toByteArray())); content1.drawImage(img, 50, 50); content1.close(); doc.save(fileName); doc.close(); } catch (Exception e) { System.err.println(e.getMessage()); } }
From source file:Publisher.CReport.java
public static String genReport(JSONArray pObjAry) throws IOException, COSVisitorException { List<List<String>> lstIncidentContents = new ArrayList<>(); List<List<String>> lstHaze = new ArrayList<>(); List<List<String>> lstDengue = new ArrayList<>(); List<String> aryLst = new ArrayList<>(); aryLst.add("Incident Type"); aryLst.add("Percentage"); lstIncidentContents.add(aryLst);/*from ww w . ja va 2s .c o m*/ List<String> aryHazeHeader = new ArrayList<>(); aryHazeHeader.add("Region"); aryHazeHeader.add("PSI"); lstHaze.add(aryHazeHeader); List<String> aryDengueHeader = new ArrayList<>(); aryDengueHeader.add("Zones"); aryDengueHeader.add("Count"); lstDengue.add(aryDengueHeader); for (Object obj : pObjAry) { JSONObject objJson = (JSONObject) obj; Iterator<?> keys = objJson.keySet().iterator(); while (keys.hasNext()) { String key = (String) keys.next(); if (key.equalsIgnoreCase("type")) { continue; } String value = objJson.get(key) + ""; List<String> aryValues = new ArrayList<>(); switch (objJson.get("Type").toString().toUpperCase()) { case "STATS": aryValues.add(key); aryValues.add(value + "%"); lstIncidentContents.add(aryValues); break; case "HAZE": aryValues.add(key + " Area"); aryValues.add(value); lstHaze.add(aryValues); break; case "DENGUE": switch (key.toUpperCase()) { case "ALERT": aryValues.add("Red Zone"); break; default: aryValues.add("Yellow Zone"); break; } aryValues.add(value); lstDengue.add(aryValues); break; } } } try (// Create a document and add a page to it PDDocument document = new PDDocument()) { PDPage page = new PDPage(PDPage.PAGE_SIZE_A4); document.addPage(page); // Create a new font object selecting one of the PDF base fonts PDFont font = PDType1Font.HELVETICA_BOLD; // Define a text content stream using the selected font, moving the cursor and drawing the text "Hello World" try (// Start a new content stream which will "hold" the to be created content PDPageContentStream contentStream = new PDPageContentStream(document, page)) { // Define a text content stream using the selected font, moving the cursor and drawing the text "Hello World" contentStream.beginText(); contentStream.setFont(font, 20); contentStream.moveTextPositionByAmount(70, 720); contentStream.drawString("Incident Summary (" + new Date() + ")"); contentStream.endText(); contentStream.beginText(); contentStream.setFont(font, 18); contentStream.moveTextPositionByAmount(100, 670); contentStream.drawString("Incident Statistics"); contentStream.endText(); contentStream.beginText(); contentStream.setFont(font, 18); contentStream.moveTextPositionByAmount(100, 500); contentStream.drawString("Haze Statistics"); contentStream.endText(); contentStream.beginText(); contentStream.setFont(font, 18); contentStream.moveTextPositionByAmount(100, 300); contentStream.drawString("Dengue Statistics"); contentStream.endText(); drawTable(page, contentStream, 650, 100, lstIncidentContents); drawTable(page, contentStream, 480, 100, lstHaze); drawTable(page, contentStream, 280, 100, lstDengue); // Make sure that the content stream is closed: } String strFileName = new Date().getTime() + ".pdf"; // Save the results and ensure that the document is properly closed: document.save(strFileName); return Paths.get(strFileName).toAbsolutePath().toString(); } }
From source file:Report.CReport.java
public static void genReport(JSONArray pObjAry) throws IOException, COSVisitorException { String imagePath = "C:\\Users\\Bryden\\Desktop\\pie-sample.png"; List<List<String>> lstContents = new ArrayList<>(); List<String> aryLst = new ArrayList<>(); aryLst.add("Incident Type"); aryLst.add(""); lstContents.add(aryLst);//from w w w .j a va 2s .c om for (Object obj : pObjAry) { JSONObject objJson = (JSONObject) obj; Iterator<?> keys = objJson.keySet().iterator(); while (keys.hasNext()) { String key = (String) keys.next(); // loop to get the dynamic key String value = (String) objJson.get(key); List<String> aryValues = new ArrayList<>(); aryValues.add(key); aryValues.add(value); lstContents.add(aryValues); } } try (// Create a document and add a page to it PDDocument document = new PDDocument()) { PDPage page = new PDPage(PDPage.PAGE_SIZE_A4); document.addPage(page); // Create a new font object selecting one of the PDF base fonts PDFont font = PDType1Font.HELVETICA_BOLD; InputStream in = Files.newInputStream(Paths.get(imagePath)); PDJpeg img = new PDJpeg(document, in); // Define a text content stream using the selected font, moving the cursor and drawing the text "Hello World" try (// Start a new content stream which will "hold" the to be created content PDPageContentStream contentStream = new PDPageContentStream(document, page)) { // Define a text content stream using the selected font, moving the cursor and drawing the text "Hello World" contentStream.beginText(); contentStream.setFont(font, 20); contentStream.moveTextPositionByAmount(70, 720); contentStream.drawString("Incident Summary " + new Date()); contentStream.endText(); contentStream.beginText(); contentStream.setFont(font, 20); contentStream.moveTextPositionByAmount(100, 670); contentStream.drawString("Statistics"); contentStream.endText(); contentStream.drawImage(img, 10, 10); drawTable(page, contentStream, 650, 100, lstContents); // Make sure that the content stream is closed: } img.clear(); // Save the results and ensure that the document is properly closed: document.save("Hello World.pdf"); } }
From source file:richtercloud.document.scanner.gui.DefaultMainPanel.java
License:Open Source License
@Override public void exportActiveDocumentItem(OutputStream out, int exportFormat) throws IOException, ImageWrapperException { if (exportFormat == EXPORT_FORMAT_PDF) { //There seems to be no PNG support in Apache PDFBox, but //transforming into JPEG isn't too much of an effort and allows to //limit dependencies to Apache PDFBox PDDocument document = new PDDocument(); PDRectangle documentRectangle = PDRectangle.A4; for (OCRSelectPanel oCRSelectPanel : oCRSelectComponent.getoCRSelectPanelPanel().getoCRSelectPanels()) { ImageWrapper imageWrapper = oCRSelectPanel.getImage(); PDPage page = new PDPage(documentRectangle); document.addPage(page);/*from ww w . j a v a 2 s . c o m*/ //@TODO: figure out how to create PDImageXObject from stream //since this was possible in 1.8 and it's unlikely that there's //such a severe regression InputStream inputStream = imageWrapper.getOriginalImageStream(); if (inputStream == null) { //cache has been shut down return; } BufferedImage awtImage = ImageIO.read(inputStream); PDImageXObject pdImageXObject = LosslessFactory.createFromImage(document, awtImage); PDPageContentStream contentStream = new PDPageContentStream(document, page); contentStream.drawImage(pdImageXObject, 0, 0, documentRectangle.getWidth(), documentRectangle.getHeight()); //in case width and height exceed the size of //documentRectangle, the page is empty (or the content might //be placed outside the page which has the same effect) contentStream.setFont(PDType1Font.COURIER, 10); contentStream.close(); } document.save(out); document.close(); out.flush(); out.close(); } else { throw new IllegalArgumentException("export format %s isn't supported"); } }
From source file:serock.pdfpagerestorer.PdfPageRestorer.java
License:Open Source License
private static void addPages(final PDDocument pdDoc, final COSDocument cosDoc) throws IOException { final List<COSObject> pageObjects = cosDoc.getObjectsByType(COSName.PAGE); for (COSObject pageObject : pageObjects) { final COSBase baseObject = pageObject.getObject(); final COSDictionary pageDictionary = (COSDictionary) baseObject; final PDPage page = new PDPage(pageDictionary); pdDoc.addPage(page);/* w w w .j a v a 2 s.c o m*/ } }
From source file:testppttopdf.TestPptToPdf.java
/** * @param args the command line arguments *///from ww w. j av a2s . c om public static void main(String[] args) throws FileNotFoundException, IOException, COSVisitorException { // TODO code application logic here FileInputStream is = new FileInputStream("/home/sagar/Desktop/Shareback/test.ppt"); HSLFSlideShow ppt = new HSLFSlideShow(is); is.close(); Dimension pgsize = ppt.getPageSize(); int idx = 1; for (HSLFSlide slide : ppt.getSlides()) { BufferedImage img = new BufferedImage(pgsize.width, pgsize.height, BufferedImage.TYPE_INT_RGB); Graphics2D graphics = img.createGraphics(); // clear the drawing area graphics.setPaint(Color.white); graphics.fill(new Rectangle2D.Float(0, 0, pgsize.width, pgsize.height)); // render slide.draw(graphics); // save the output FileOutputStream out = new FileOutputStream("/home/sagar/Desktop/Shareback/img/slide-" + idx + ".jpg"); javax.imageio.ImageIO.write(img, "jpg", out); out.close(); idx++; } String someimg = "/home/sagar/Desktop/Shareback/img/"; PDDocument document = new PDDocument(); File file = new File(someimg); if (file.isDirectory()) { for (File f : file.listFiles()) { InputStream in = new FileInputStream(f); BufferedImage bimg = ImageIO.read(in); float width = bimg.getWidth(); float height = bimg.getHeight(); PDPage page = new PDPage(new PDRectangle(width + 10, height + 10)); document.addPage(page); PDXObjectImage img = new PDJpeg(document, new FileInputStream(f)); PDPageContentStream contentStream = new PDPageContentStream(document, page); contentStream.drawImage(img, 0, 0); contentStream.close(); in.close(); } document.save("/home/sagar/Desktop/Shareback/test-generated.pdf"); document.close(); } else { System.out.println(someimg + "is not a Directory"); } }
From source file:testppttopdf.TestPptToPdf.java
static void testPptxToPdf() { String filepath = "/home/sagar/Desktop/Shareback/test.pptx"; FileInputStream is;//from w ww .j a v a2s .com try { is = new FileInputStream(filepath); XMLSlideShow pptx = new XMLSlideShow(is); Dimension pgsize = pptx.getPageSize(); int idx = 1; for (XSLFSlide slide : pptx.getSlides()) { BufferedImage img = new BufferedImage(pgsize.width, pgsize.height, BufferedImage.TYPE_INT_RGB); Graphics2D graphics = img.createGraphics(); // clear the drawing area graphics.setPaint(Color.white); graphics.fill(new Rectangle2D.Float(0, 0, pgsize.width, pgsize.height)); // render slide.draw(graphics); // save the output FileOutputStream out = new FileOutputStream( "/home/sagar/Desktop/Shareback/img/slide-" + idx + ".jpg"); javax.imageio.ImageIO.write(img, "jpg", out); out.close(); idx++; } String someimg = "/home/sagar/Desktop/Shareback/pptx/img/"; PDDocument document = new PDDocument(); File file = new File(someimg); if (!file.exists()) file.mkdir(); if (file.isDirectory()) { for (File f : file.listFiles()) { InputStream in = new FileInputStream(f); BufferedImage bimg = ImageIO.read(in); float width = bimg.getWidth(); float height = bimg.getHeight(); PDPage page = new PDPage(new PDRectangle(width + 10, height + 10)); document.addPage(page); PDXObjectImage img = new PDJpeg(document, new FileInputStream(f)); PDPageContentStream contentStream = new PDPageContentStream(document, page); contentStream.drawImage(img, 0, 0); contentStream.close(); in.close(); } document.save("/home/sagar/Desktop/Shareback/test-generated-pptx.pdf"); document.close(); } else { System.out.println(someimg + "is not a Directory"); } } catch (Exception ex) { Logger.getLogger(TestPptToPdf.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:uia.pdf.papers.Paper.java
License:Apache License
/** * Create a page based on paper size. * @return Page. */ public PDPage createPage() { return new PDPage(this.rect); }