Java tutorial
/* This file is part of Domain Tool. Domain Tool is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Domain Tool is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Domain Tool. If not, see <http://www.gnu.org/licenses/>. */ package DomainToolCore.Report; import DomainToolCore.Core.Utils; import java.util.Date; import java.util.Calendar; import java.util.GregorianCalendar; import java.io.*; import java.util.Vector; import com.itextpdf.text.BadElementException; import com.itextpdf.text.Document; import com.itextpdf.text.DocumentException; import com.itextpdf.text.Element; import com.itextpdf.text.Font; 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; public class PDFSubDomains { private static Font catFont = new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD); private static Font smallBold = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD); private static Vector subd, ip; private static String domain, ip_domain; public static String FILE; private String pdfDir = System.getProperty("user.dir") + "\\Report\\pdf\\"; private Calendar c = new GregorianCalendar(); public PDFSubDomains(String domain, Vector v1, Vector v2, String ipdo) { subd = (Vector) v1.clone(); ip = (Vector) v2.clone(); this.domain = domain; this.ip_domain = ipdo; Utils u = new Utils(); /*****Check if the Report folder exist, if not, it will be created***/ if (!u.FolderExist("Report")) { u.MakeReportFolder(); u.CreateFolder("Report\\pdf"); } if (!u.FolderExist("Report\\pdf")) u.CreateFolder("Report\\pdf"); /********************************************************************/ try { Document document = new Document(); FILE = pdfDir + domain + "_" + c.get(Calendar.DAY_OF_MONTH) + "_" + c.get(Calendar.MONTH) + "_" + c.get(Calendar.YEAR) + "_" + c.get(Calendar.HOUR_OF_DAY) + "_" + c.get(Calendar.MINUTE) + "_" + c.get(Calendar.SECOND) + ".pdf"; PdfWriter.getInstance(document, new FileOutputStream(FILE)); document.open(); addMetaData(document); addTitlePage(document); createTable(document); document.close(); } catch (Exception e) { e.printStackTrace(); } } //HACK HACK, method called after the constructor, for retrieving the path of pdf public String GetPDFPath() { return FILE; } private static void addTitlePage(Document document) throws DocumentException { Paragraph preface = new Paragraph(); addEmptyLine(preface, 1); preface.add(new Paragraph("Doman Tool Report", catFont)); addEmptyLine(preface, 2); preface.add(new Paragraph("Report generated on: " + new Date(), smallBold)); addEmptyLine(preface, 2); preface.add(new Paragraph("Domain: " + domain, smallBold)); preface.add(new Paragraph("Domain IP: " + ip_domain, smallBold)); addEmptyLine(preface, 2); document.add(preface); } private static void addMetaData(Document document) { document.addTitle("Domain Tool Report"); document.addSubject("site: " + domain); document.addKeywords("Domain, Tool, PDF, ip, address"); document.addAuthor("Domain Tool"); document.addCreator("Domain Tool"); } private static void createTable(Document document) throws BadElementException, DocumentException { PdfPTable table = new PdfPTable(2); // t.setBorderColor(BaseColor.GRAY); // t.setPadding(4); // t.setSpacing(4); // t.setBorderWidth(1); PdfPCell c1 = new PdfPCell(new Phrase("SubDomain")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("IP Address")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); for (int i = 0; i < subd.size(); i++) { table.addCell((String) subd.elementAt(i)); table.addCell((String) ip.elementAt(i)); } document.add(table); } private static void addEmptyLine(Paragraph paragraph, int number) { for (int i = 0; i < number; i++) { paragraph.add(new Paragraph(" ")); } } }