Java tutorial
package negotiation.Contract; import java.io.FileOutputStream; import com.itextpdf.text.Anchor; import com.itextpdf.text.BaseColor; import com.itextpdf.text.Document; import com.itextpdf.text.DocumentException; import com.itextpdf.text.Font; import com.itextpdf.text.Paragraph; import com.itextpdf.text.pdf.PdfWriter; import negotiation.Contract.ContractContents; import negotiation.Contract.AwsContract.AwsEc2ContractContents; public class FormContractPdf { // the path to store contract pdf //private static String FILE = "/opt/AHE3/contract/" + group/" + "user".pdf"; private static Font catFont = new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD); private static Font redFont = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL, BaseColor.RED); private static Font subFont = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD); private static Font smallBold = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD); public static void generateAwsContract(String group, String user, Long id) throws DocumentException { //public static void main(String[] args) throws DocumentException { String FILE = "/opt/AHE3/contract/" + group + "/" + user + "/" + id + ".pdf"; try { Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(FILE)); document.open(); addMetaData(document); addTitlePage(document, "AWS Services"); //addGeneral("usera", "mangroup", "aws", "2014", "2015"); //addDescription("usera", "aws-ec2", "computing service"); addContents(document); document.close(); } catch (Exception e) { e.printStackTrace(); } //System.out.println(addDescription("usera", "aws-ec2", "computing service")); } static String glo_service; // iText allows to add metadata to the PDF which can be viewed in your Adobe // Reader // under File -> Properties public static void addMetaData(Document document) { document.addTitle("FitSM Module"); document.addSubject("Using iText"); document.addKeywords("Java, PDF, iText, FitSM"); document.addAuthor("Zeqian Meng"); document.addCreator("Zeqian Meng"); } public static void addTitlePage(Document document, String service) throws DocumentException { glo_service = service; Paragraph preface = new Paragraph(); // We add one empty line addEmptyLine(preface, 1); // Lets write a big header preface.add(new Paragraph("SLA on " + service, catFont)); addEmptyLine(preface, 1); // Will create: Report generated by: _name, _date /*preface.add(new Paragraph("Report generated by: Sophia" + ", " + new Date(), smallBold)); addEmptyLine(preface, 3); preface.add(new Paragraph("This document describes SLA", smallBold)); addEmptyLine(preface, 8); preface.add(new Paragraph("This document is a preliminary version and not subject to your license agreement or any other agreement with vogella.com ;-).", redFont)); document.add(preface); // Start a new page document.newPage();*/ } public static void addContents(Document document) throws DocumentException { Anchor anchor = new Anchor("Contract", catFont); anchor.setName("Contract"); Paragraph para = new Paragraph(); para.add(new Paragraph("1. General", subFont)); String para1 = ContractContents.addGeneral("userA", "ManagerD", "aws", "2014", "2015"); para.add(para1); addEmptyLine(para, 1); para.add(new Paragraph("2. Scope & description of the service", subFont)); String para2 = ContractContents.addDescription("aws-ec2", "www.aws.com", "computing service"); para.add(para2); para.add(new Paragraph("3. Service hours & exceptions", subFont)); String para3 = ContractContents.addTime("2014", "2015"); para.add(para3); para.add(new Paragraph("4. Service components & dependencies", subFont)); String para4 = ContractContents.addComponents("aws-ec2", "computing service"); para.add(para4); para.add(new Paragraph("5. Support", subFont)); String para5 = ContractContents.addSupport("University of Manchester", "Mon-Fri: 9:00am - 5:00pm"); para.add(para5); para.add(new Paragraph("5.1 Incident handling", smallBold)); String para6 = ContractContents.addHandling("Incident handling ..."); para.add(para6); para.add(new Paragraph("5.2 Fulfillment of service requests", smallBold)); String para7 = ContractContents.addFulfillment("Fulfillment ..."); para.add(para7); para.add(new Paragraph("6. Service level targets", subFont)); String para8 = AwsEc2ContractContents.addTargets(); //String para8 = ContractContents.addTargets("Availability", "24 hours"); para.add(para8); para.add(new Paragraph("7. Limitations & constaints", subFont)); String para9 = AwsEc2ContractContents.addConstaints(); //String para9 = ContractContents.addConstaints("Wordload limits..."); para.add(para9); para.add(new Paragraph("8. Communication, reporting & escalation", subFont)); para.add(new Paragraph("8.1 General communication", smallBold)); String para10 = ContractContents.addContacts("123", "456", "789"); para.add(para10); para.add(new Paragraph("8.2 Regular reporting", smallBold)); String para11 = ContractContents.addReport("20150520", "regular check", "once a week", "University of Manchester."); para.add(para11); para.add(new Paragraph("8.3 SLA violations", smallBold)); String para12 = AwsEc2ContractContents.addViolations(); //String para12 = ContractContents.addViolations("Penalty required when performance cannot rearch agreed SLAs."); para.add(para12); para.add(new Paragraph("8.4 Escalation & complaints", smallBold)); String para13 = ContractContents .addEscalation("Please contact University of Manchester via provided email."); para.add(para13); para.add(new Paragraph("9. Information security & data protection", subFont)); String para14 = ContractContents .addProtection("All the data should be kept within University of Manchester network domain."); para.add(para14); para.add(new Paragraph("10. Additional responsibilities of the service provider", subFont)); String para15 = ContractContents.addProviderResp("Provider should ..."); para.add(para15); para.add(new Paragraph("11. Customer responsibilities", subFont)); String para16 = ContractContents.addCustomerResp("Customer should ..."); para.add(para16); para.add(new Paragraph("12. Review", subFont)); String para17 = ContractContents.addReview("Review should be taken..."); para.add(para17); para.add(new Paragraph("13. Glossary of terms", subFont)); String para18 = AwsEc2ContractContents.addTerms(); //String para18 = ContractContents.addTerms("aws-ec2", "computing services"); para.add(para18); para.add(new Paragraph("14. Document control", subFont)); String para19 = ContractContents.addControl(55555, "SLA on" + glo_service, "University of Manchester", "University of Manchester", "1.0", "2015", "2016", "No change so far"); para.add(para19); document.add(para); } private static void addEmptyLine(Paragraph paragraph, int number) { for (int i = 0; i < number; i++) { paragraph.add(new Paragraph(" ")); } } }