List of usage examples for com.itextpdf.text Image scaleAbsolute
public void scaleAbsolute(final float newWidth, final float newHeight)
From source file:com.skatettoo.reportes.Generador.java
public String generarPDF() throws Exception { try {// ww w .j a v a 2s .com String path = FacesContext.getCurrentInstance().getExternalContext().getRealPath("img"); path = path.substring(0, path.indexOf("\\build")); path = path + "\\web\\img\\"; Document doc = new Document(PageSize.A4, 36, 36, 10, 10); PdfPTable tabla = new PdfPTable(4); PdfWriter.getInstance(doc, new FileOutputStream(path + "\\archivo\\reporte.pdf\\")); doc.open(); Image img = Image.getInstance(path + "Skatetoo4.png"); img.scaleAbsolute(40, 40); img.setAlignment(Element.ALIGN_LEFT); doc.add(img); doc.addTitle(this.titulo); doc.addAuthor("\n "); doc.addAuthor("\n "); doc.addAuthor("\n "); doc.addAuthor("\n "); tabla.setWidthPercentage(100); tabla.setWidths(new float[] { 1.4f, 0.8f, 0.8f, 0.8f }); Object font = new Font(Font.FontFamily.HELVETICA, 14, Font.BOLD, BaseColor.WHITE); PdfPCell cell = new PdfPCell(new Phrase("Reporte de tatuadores", (Font) font)); cell.setColspan(4); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setPaddingTop(0f); cell.setPaddingBottom(7f); cell.setBackgroundColor(new BaseColor(0, 0, 0)); cell.setBorder(0); cell.setBorderWidthBottom(2f); tabla.addCell(cell); tabla.addCell("Tatuador"); tabla.addCell("Cantidad de diseos"); tabla.addCell("Citas realizadas"); tabla.addCell("Noticias publicadas"); for (Usuario u : this.getUsu()) { tabla.addCell(u.getNombre() + " " + u.getApellido()); tabla.addCell(String.valueOf(u.getDisenioList().size())); tabla.addCell(String.valueOf(u.getCitaList1().size())); tabla.addCell(String.valueOf(u.getNoticiaList().size())); } doc.add(tabla); doc.bottomMargin(); /* doc.add(new Paragraph("Tatuador mas solicitado")); for(Usuario u : this.getUs()){ doc.add(new Paragraph(u.getNombre() + " " + u.getApellido())); }*/ doc.close(); FacesContext context = FacesContext.getCurrentInstance(); ExternalContext externalContext = context.getExternalContext(); externalContext.responseReset(); externalContext.setResponseContentType("application/pdf"); externalContext.setResponseHeader("Content-Disposition", "attachment;filename=\"reporte.pdf\""); FileInputStream inputStream = new FileInputStream(new File(path + "\\archivo\\reporte.pdf\\")); OutputStream outputStream = externalContext.getResponseOutputStream(); byte[] buffer = new byte[1024]; int length; while ((length = inputStream.read(buffer)) > 0) { outputStream.write(buffer, 0, length); } inputStream.close(); context.responseComplete(); } catch (Exception e) { throw e; } return ""; }
From source file:control.ModificaPrestamo.java
public boolean generapdf(String path) throws DocumentException, FileNotFoundException { boolean estado = false; Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(path)); document.open();// w ww.jav a 2 s . c o m Image img = null; try { img = Image.getInstance("src/img/imgen.jpg"); img.scaleAbsolute(80f, 50f); img.setAbsolutePosition(470f, 750f); document.add(img); } catch (BadElementException ex) { Logger.getLogger(nuevoReporte.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(nuevoReporte.class.getName()).log(Level.SEVERE, null, ex); } Paragraph paragraph1 = new Paragraph("Solicitante: " + Solicitante.getText()); Paragraph paragraph2 = new Paragraph("Proyecto: " + Proyecto.getText()); Paragraph paragraph3 = new Paragraph( "Fecha y hora del prestamo: " + fecha.getText() + " " + hora.getText()); Paragraph paragraph4 = new Paragraph("Fecha de entrega: " + fecha1.getText()); document.add(paragraph1); document.add(paragraph2); document.add(paragraph3); document.add(paragraph4); Paragraph tmp = new Paragraph(""); tmp.setSpacingBefore(10); document.add(tmp); PdfPTable table = new PdfPTable(4); table.addCell("Id Equipo"); table.addCell("Equipo"); table.addCell("Accesorios"); table.addCell("Descripcion"); Object[][] tabla = this.getTableData(tabReporte); for (Object[] o : tabla) for (Object e : o) { table.addCell((String) e); } document.add(table); System.out.println(clausula1.getText() + " " + clausula2.getText()); Paragraph paragraph5 = new Paragraph("Clausula 1: " + clausula1.getText()); Paragraph paragraph6 = new Paragraph("Clausula 2: " + clausula2.getText()); document.add(paragraph5); document.add(paragraph6); tmp = new Paragraph(""); tmp.setSpacingBefore(10); document.add(tmp); Paragraph p = new Paragraph("Firma del solicitante: "); p.add(new Chunk(new DottedLineSeparator())); p.add(" Firma del prestador: "); p.add(new Chunk(new DottedLineSeparator())); document.add(p); //PdfPTable firma = new PdfPTable(1); //firma.addCell("Firma"); //document.add(new Paragraph("")); //document.add(firma); document.close(); return true; }
From source file:Controller.app.ConsultaController.java
private File createPDF(TblServicioFactura factura) throws IOException { String data = factura.getTesPagoResponse(); JSONObject obj = new JSONObject(data); JSONArray content = obj.getJSONArray("lineaFactura"); String temp = ""; File _file = null;//w w w . j ava 2s.co m Document doc = null; OutputStream file = null; int page = 0; try { _file = File.createTempFile("temp_file", ".pdf"); TblServicioServicio servicio = servicios.search(factura.getTesCodigoSintesisBi().toString()); file = new FileOutputStream(_file); doc = new Document(PageSize.LETTER); doc.setMargins(servicio.getMarginLeft().floatValue(), servicio.getMarginRight().floatValue(), servicio.getMarginTop().floatValue(), servicio.getMarginBottom().floatValue()); PdfWriter.getInstance(doc, file); doc.open(); // ClassLoader classloader = Thread.currentThread().getContextClassLoader(); ClassLoader classloader = getClass().getClassLoader(); URL url = classloader.getResource("cour.ttf"); BaseFont base = null; if (url == null) { base = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); } else { String path = url.getPath(); if ("/".equals(path.substring(0, 1))) { path = path.substring(1); } Logger.getLogger(ConsultaController.class.getName()).log(Level.INFO, path); base = BaseFont.createFont(path, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); } Font f = new Font(base, servicio.getFontSize(), Font.NORMAL, BaseColor.BLACK); String qr = ""; float line = 0; for (Object item : content) { Paragraph paragraph = new Paragraph(item.toString(), f); if (servicio.getTesDetalleVc().trim().equals("PAGO ENTEL")) { if (item.toString().contains("P X#X&$#&K##")) { paragraph = new Paragraph(" ", f); doc.add(paragraph); doc.add(paragraph); paragraph = new Paragraph(item.toString(), f); } } if (item.toString().contains("<b>")) { Font bold = new Font(base, 7.0f, Font.BOLD, BaseColor.BLACK); paragraph = new Paragraph(item.toString().replace("<b>", ""), bold); } if (item.toString().contains("<QR>") || item.toString().contains("<QR_ENT_G>")) { qr = item.toString().replaceAll("<QR>", ""); qr = item.toString().replaceAll("<QR_ENT_G>", ""); Image image = QR.create(qr); image.scaleAbsolute(servicio.getQrScale().floatValue(), servicio.getQrScale().floatValue()); if (servicio.getTesDetalleVc().trim().equals("PAGO ENTEL") || servicio.getTesDetalleVc().trim().equals("PAGO TELECEL") || servicio.getTesDetalleVc().trim().equals("PAGO NUEVATEL") || servicio.getTesDetalleVc().trim().equals("PAGO TIGOSTAR (MULTIVISION)")) { float y = (doc.getPageSize().getHeight() - (paragraph.getLeading() * (line + 1))); float x = 0; if (servicio.getTesDetalleVc().trim().equals("PAGO ENTEL")) { image.setAlignment(Image.ALIGN_RIGHT); x = doc.getPageSize().getWidth() - (110 - servicio.getMarginLeft().floatValue()); } if (servicio.getTesDetalleVc().trim().equals("PAGO TELECEL")) { image.setAlignment(Image.ALIGN_LEFT); x = 30; y -= (servicio.getQrScale().floatValue() - (paragraph.getLeading() * 2)); } if (servicio.getTesDetalleVc().trim().equals("PAGO NUEVATEL")) { image.setAlignment(Image.ALIGN_LEFT); x = doc.getPageSize().getWidth() - (120 - servicio.getMarginLeft().floatValue()); y -= (servicio.getQrScale().floatValue() - (paragraph.getLeading())); } if (servicio.getTesDetalleVc().trim().equals("PAGO TIGOSTAR (MULTIVISION)")) { image.setAlignment(Image.ALIGN_LEFT); x = doc.getPageSize().getWidth() - (120 - servicio.getMarginLeft().floatValue()); y -= (servicio.getQrScale().floatValue() - (paragraph.getLeading())); } image.setAbsolutePosition(x, y); } doc.add(image); } if (servicio.getDelimitador().equals(item.toString().trim())) { line = 0; page++; doc.newPage(); } else { line += 1f; if (!(item.toString().contains("<QR>") || item.toString().contains("<QR_ENT_G>"))) { doc.add(paragraph); } } temp += item.toString(); } } catch (FileNotFoundException ex) { Logger.getLogger(ConsultaController.class.getName()).log(Level.INFO, null, ex); } catch (DocumentException | IOException ex) { Logger.getLogger(ConsultaController.class.getName()).log(Level.INFO, null, ex); } doc.close(); file.close(); return _file; }
From source file:cz.zcu.kiv.eegdatabase.logic.pdf.PDFUtils.java
License:Apache License
private Image GetResizedAndCenteredImage(String filename) throws IOException, BadElementException { Image img = Image.getInstance(filename); if (img.getWidth() <= PageSize.A4.getWidth() - PADDING[1] - PADDING[3]) { return img; }/* w ww . ja va2 s.c o m*/ float newWidth = PageSize.A4.getWidth() - PADDING[1] - PADDING[3]; float ratio = newWidth / img.getWidth(); float newHeight = img.getHeight() * ratio; img.scaleAbsolute(newWidth, newHeight); return img; }
From source file:dbms_prj.Display.java
public void create_pdf() throws Exception { Document doc = new Document(); PdfWriter.getInstance(doc, new FileOutputStream(S1 + ".pdf")); Image image = Image.getInstance("src/Travel partners.png"); image.scaleAbsolute(500f, 200f); Image ima = Image.getInstance("src/images.jpg"); ima.scaleAbsolute(100f, 100f);/*from w w w.ja v a2s . c o m*/ ima.setAlignment(Element.ALIGN_CENTER); PdfPTable table = new PdfPTable(9); PdfPCell cell = new PdfPCell(new Paragraph("Ticket")); cell.setColspan(9); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setPadding(10.0f); cell.setBackgroundColor(new BaseColor(140, 221, 8)); table.addCell(cell); table.addCell("PNR"); table.addCell("BOOK_ID"); table.addCell("FLIGHT_NO"); table.addCell("NAME"); table.addCell("SOURCE"); table.addCell("DESTINATION"); table.addCell("STATUS"); table.addCell("FARE"); table.addCell("Date"); table.addCell(S1); table.addCell(S11); table.addCell(S4); table.addCell(S6 + " " + S7); table.addCell(S8); table.addCell(S9); table.addCell(S5); table.addCell(S10); table.addCell(S12); table.setSpacingBefore(30.0f); // Space Before table starts, like margin-top in CSS table.setSpacingAfter(30.0f); doc.open(); //doc.add(new Paragraph("Hello!! Yo this is my first pdf!")); doc.add(image); doc.add(new Paragraph("Ticket created on " + new Date().toString())); doc.add(table); //doc.add(list); doc.add(ima); doc.close(); }
From source file:dbms_prj.Status.java
public void create_pdf() throws Exception { Document doc = new Document(); PdfWriter.getInstance(doc, new FileOutputStream(S1 + ".pdf")); Image image = Image.getInstance("src/Travel partners.png"); image.scaleAbsolute(500f, 200f); Image ima = Image.getInstance("src/images.jpg"); ima.scaleAbsolute(100f, 100f);//from ww w. j a v a 2s . co m ima.setAlignment(Element.ALIGN_CENTER); PdfPTable table = new PdfPTable(9); PdfPCell cell = new PdfPCell(new Paragraph("Ticket")); cell.setColspan(9); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setPadding(10.0f); table.setTotalWidth(300.0f); cell.setBackgroundColor(new BaseColor(140, 221, 8)); table.addCell(cell); table.addCell("PNR"); table.addCell("BOOK_ID"); table.addCell("FLIGHT_NO"); table.addCell("NAME"); table.addCell("SOURCE"); table.addCell("DESTINATION"); table.addCell("STATUS"); table.addCell("FARE"); table.addCell("Date"); table.addCell(S1); table.addCell(S11); table.addCell(S4); table.addCell(S6 + S7); table.addCell(S8); table.addCell(S9); table.addCell(S5); table.addCell(S10); table.addCell(S2); table.setSpacingBefore(50.0f); // Space Before table starts, like margin-top in CSS table.setSpacingAfter(50.0f); doc.open(); //doc.add(new Paragraph("Hello!! Yo this is my first pdf!")); doc.add(image); //doc.add(new Paragraph("Ticket created on " + new Date().toString())); doc.add(table); //doc.add(list); doc.add(ima); doc.close(); }
From source file:de.aidger.utils.pdf.ActivityReportConverter.java
License:Open Source License
/** * Writes the logos and the address of the institute. *///from w w w.j ava 2 s .com private void writeLogo() { try { Font generatedByFont = new Font( BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED), 8); Image aidger = Image.getInstance(getClass().getResource("/de/aidger/res/pdf/AidgerLogo.png")); aidger.scaleAbsolute(80.0f, 20.0f); PdfPTable table = new PdfPTable(2); table.setTotalWidth(reader.getPageSize(1).getRight()); PdfPCell cell = new PdfPCell(new Phrase(_("Generated by: "), generatedByFont)); cell.setBorder(0); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setPaddingBottom(5); cell.setVerticalAlignment(Element.ALIGN_BOTTOM); table.addCell(cell); cell = new PdfPCell(Image.getInstance(aidger)); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setBorder(0); table.addCell(cell); table.writeSelectedRows(0, -1, 0, 25, contentByte); } catch (BadElementException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (DocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:de.earthdawn.ECEPdfExporter.java
License:Open Source License
public void exportRedbrickExtended(EDCHARACTER edCharakter, File outFile) throws DocumentException, IOException { PdfReader reader = new PdfReader( new FileInputStream(new File("./templates/ed3_extended_character_sheet.pdf"))); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(outFile)); acroFields = stamper.getAcroFields(); CharacterContainer character = new CharacterContainer(edCharakter); // +++ DEBUG +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //Set<String> fieldNames = acroFields.getFields().keySet(); //fieldNames = new TreeSet<String>(fieldNames); //for( String fieldName : fieldNames ) { // acroFields.setField( fieldName, fieldName ); // System.out.println( fieldName ); //}/*from ww w .j a va 2 s . c o m*/ // +++ ~DEBUG ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ exportCommonFields(character, 16, 55); setButtons(character.getWound().getNormal(), "WoundPenalties.", 9); acroFields.setField("Shield", "none"); acroFields.setField("ShieldDeflectionBonus", "na"); // Charakter Potrait-Bild einfgen List<Base64BinaryType> potraits = character.getPortrait(); if (!potraits.isEmpty()) { Image image = Image.getInstance(potraits.get(0).getValue()); image.setAbsolutePosition(35f, 517f); image.scaleAbsolute(165f, 200f); PdfContentByte overContent = stamper.getOverContent(2); overContent.addImage(image); } int armor_max = 0; int shield_max = 0; for (ARMORType armor : character.getProtection().getARMOROrSHIELD()) { if (!armor.getUsed().equals(YesnoType.YES)) continue; if (armor.getClass().getSimpleName().equals("ARMORType")) { if (armor.getPhysicalarmor() > armor_max) { armor_max = armor.getPhysicalarmor(); acroFields.setField("Armor", armor.getName()); } } else if (armor.getClass().getSimpleName().equals("SHIELDType")) { SHIELDType shield = (SHIELDType) armor; if (shield.getPhysicalarmor() > shield_max) { shield_max = armor.getPhysicalarmor(); acroFields.setField("Shield", shield.getName()); acroFields.setField("ShieldDeflectionBonus", shield.getPhysicaldeflectionbonus() + "/" + shield.getMysticdeflectionbonus()); } } else { System.err.println("Unbekannte Rstungstyp: " + armor.getClass().getSimpleName()); } } acroFields.setField("Discipline", concat(" / ", character.getDisciplineNames())); acroFields.setField("Circle", concat(" / ", character.getDisciplineCircles())); int counterKarmaritual = 0; for (String karmaritual : character.getAllKarmaritual()) { for (String description : wrapString(50, karmaritual)) { if (counterKarmaritual > 11) { System.err.println("Karmaritual description is to long. Only first 12 lines were displayed."); break; } acroFields.setField("KarmaRitual." + counterKarmaritual, description); counterKarmaritual++; } } List<DISCIPLINEType> disciplines = character.getDisciplines(); if (!disciplines.isEmpty()) { DISCIPLINEType discipline1 = disciplines.get(0); int counter = 0; List<TALENTType> disziplinetalents = discipline1.getDISZIPLINETALENT(); Collections.sort(disziplinetalents, new TalentComparator()); HashMap<String, ATTRIBUTEType> attributes = character.getAttributes(); for (TALENTType talent : disziplinetalents) { if ((talent.getCircle() > 4) && (counter < 9)) counter = 9; if ((talent.getCircle() > 8) && (counter < 13)) counter = 13; if ((talent.getCircle() > 12) && (counter < 17)) counter = 17; setTalent(counter, talent, attributes); counter++; } List<TALENTType> optionaltalents = discipline1.getOPTIONALTALENT(); Collections.sort(optionaltalents, new TalentComparator()); counter = 0; for (TALENTType talent : optionaltalents) { if ((talent.getCircle() > 4) && (counter < 7)) counter = 7; if ((talent.getCircle() > 8) && (counter < 13)) counter = 13; setTalent(20 + counter, talent, attributes); // Optionale Talente knnen Karma erfordern if (talent.getKarma().equals(YesnoType.YES)) { acroFields.setField("KarmaRequired." + counter, "Yes"); } else { acroFields.setField("KarmaRequired." + counter, ""); } counter++; } } if (disciplines.size() > 1) { DISCIPLINEType discipline2 = disciplines.get(1); int counter = 36; List<TALENTType> disziplinetalents = discipline2.getDISZIPLINETALENT(); Collections.sort(disziplinetalents, new TalentComparator()); HashMap<String, ATTRIBUTEType> attributes = character.getAttributes(); for (TALENTType talent : disziplinetalents) { if ((talent.getCircle() > 4) && (counter < 44)) counter = 44; if ((talent.getCircle() > 8) && (counter < 48)) counter = 48; if ((talent.getCircle() > 12) && (counter < 52)) counter = 52; setTalent(counter, talent, attributes); counter++; } List<TALENTType> optionaltalents = discipline2.getOPTIONALTALENT(); Collections.sort(optionaltalents, new TalentComparator()); counter = 16; for (TALENTType talent : optionaltalents) { if ((talent.getCircle() > 4) && (counter < 22)) counter = 22; if ((talent.getCircle() > 8) && (counter < 26)) counter = 26; setTalent(39 + counter, talent, attributes); // Optionale Talente knnen Karma erfordern if (talent.getKarma().equals(YesnoType.YES)) { acroFields.setField("KarmaRequired." + counter, "Yes"); } else { acroFields.setField("KarmaRequired." + counter, ""); } counter++; } } List<WEAPONType> weapons = character.getWeapons(); if (weapons != null) { int counter_melee = 0; int counter_range = 0; for (WEAPONType weapon : weapons) { if (weapon.getShortrange() > 0) { acroFields.setField("RangedWeapon." + counter_range, weapon.getName()); acroFields.setField("RangedWeaponDmgStep." + counter_range, String.valueOf(weapon.getDamagestep())); acroFields.setField("RangedWeapon Size." + counter_range, String.valueOf(weapon.getSize())); acroFields.setField("RangedWeaponTimesForged." + counter_range, String.valueOf(weapon.getTimesforged())); acroFields.setField("WeaponShortRange." + counter_range, String.valueOf(weapon.getShortrange())); acroFields.setField("Weapon Long Range." + counter_range, String.valueOf(weapon.getLongrange())); counter_range++; } else { acroFields.setField("Weapon." + counter_melee, weapon.getName()); acroFields.setField("WeaponDmgStep." + counter_melee, String.valueOf(weapon.getDamagestep())); acroFields.setField("Weapon Size." + counter_melee, String.valueOf(weapon.getSize())); acroFields.setField("WeaponTimesForged." + counter_melee, String.valueOf(weapon.getTimesforged())); counter_melee++; } } } List<List<SPELLType>> spellslist = new ArrayList<List<SPELLType>>(); spellslist.add(character.getOpenSpellList()); for (DISCIPLINEType discipline : disciplines) spellslist.add(discipline.getSPELL()); setSpellRedbrick(spellslist); counterEquipment = 0; for (ITEMType item : listArmorAndWeapon(character)) addEquipment(item.getName(), item.getWeight()); for (ITEMType item : character.getItems()) addEquipment(item.getName(), item.getWeight()); for (MAGICITEMType item : character.getMagicItem()) { StringBuffer text = new StringBuffer(item.getName()); text.append(" ("); text.append(item.getBlooddamage()); text.append("/"); text.append(item.getDepatterningrate()); text.append("/"); text.append(item.getEnchantingdifficultynumber()); text.append(")"); addEquipment(text.toString(), item.getWeight()); } int copperPieces = 0; int goldPieces = 0; int silverPieces = 0; for (COINSType coins : character.getAllCoins()) { addEquipment(coinsToString(coins), coins.getWeight()); copperPieces += coins.getCopper(); silverPieces += coins.getSilver(); goldPieces += coins.getGold(); } acroFields.setField("CopperPieces", String.valueOf(copperPieces)); acroFields.setField("SilverPieces", String.valueOf(silverPieces)); acroFields.setField("GoldPieces", String.valueOf(goldPieces)); int counterDescription = 0; for (String description : wrapString(60, character.getDESCRIPTION())) { acroFields.setField("ShortDescription." + counterDescription, description); counterDescription++; if (counterDescription > 7) { System.err.println("Character description to long. Only first 8 lines were displayed."); break; } } int counterMagicItem = 0; int counterThreadItem = 0; for (THREADITEMType item : character.getThreadItem()) { int weaventhreadrank = item.getWeaventhreadrank(); acroFields.setField("MagicalTreasureName." + counterMagicItem, item.getName()); acroFields.setField("MagicalTreasureSpellDefense." + counterMagicItem, String.valueOf(item.getSpelldefense())); acroFields.setField("MagicalTreasureMaxThreads." + counterMagicItem, String.valueOf(item.getMaxthreads())); int counterMagicItemDescription = 0; for (String description : wrapString(55, item.getDESCRIPTION())) { acroFields.setField("MagicalTreasureDesc." + counterMagicItemDescription + "." + counterMagicItem, description); counterMagicItemDescription++; if (counterMagicItemDescription > 2) { System.err.println("MagicItem description to long. Only first 3 lines were displayed."); break; } } int counterMagicItemRank = 0; for (THREADRANKType rank : item.getTHREADRANK()) { acroFields.setField("MagicalTreasureRank." + counterMagicItemRank + "." + counterMagicItem, String.valueOf(counterMagicItemRank + 1)); acroFields.setField("MagicalTreasureLPCost." + counterMagicItemRank + "." + counterMagicItem, String.valueOf(rank.getLpcost())); acroFields.setField("MagicalTreasureKeyKnowledge." + counterMagicItemRank + "." + counterMagicItem, rank.getKeyknowledge()); acroFields.setField("MagicalTreasureEffect." + counterMagicItemRank + "." + counterMagicItem, rank.getEffect()); if (counterMagicItemRank < weaventhreadrank) { acroFields.setField("ThreadMagicTarget." + counterThreadItem, item.getName()); acroFields.setField("ThreadMagicEffect." + counterThreadItem, rank.getEffect()); acroFields.setField("ThreadMagicLPCost." + counterThreadItem, String.valueOf(rank.getLpcost())); acroFields.setField("ThreadMagicRank." + counterThreadItem, String.valueOf(counterMagicItemRank + 1)); counterThreadItem++; } counterMagicItemRank++; } counterMagicItem++; } int counterBloodCharms = 0; for (MAGICITEMType item : character.getBloodCharmItem()) { acroFields.setField("BloodMagicType." + counterBloodCharms, item.getName()); if (item.getUsed().equals(YesnoType.YES)) { acroFields.setField("BloodMagicDamage." + counterBloodCharms, String.valueOf(item.getBlooddamage())); } else { acroFields.setField("BloodMagicDamage." + counterBloodCharms, "(" + item.getBlooddamage() + ")"); } acroFields.setField("BloodMagicDR." + counterBloodCharms, String.valueOf(item.getDepatterningrate())); acroFields.setField("BloodMagicEffect." + counterBloodCharms, item.getEffect()); counterBloodCharms++; } stamper.close(); }
From source file:de.earthdawn.ECEPdfExporter.java
License:Open Source License
public void exportAjfelMordom(EDCHARACTER edCharakter, int pdftype, File outFile) throws DocumentException, IOException { File pdfinputfile;// w w w .j a v a 2 s .c o m if (pdftype == 1) pdfinputfile = new File("templates/ed3_character_sheet_Ajfel+Mordom_pl.pdf"); else pdfinputfile = new File("templates/ed3_character_sheet_Ajfel+Mordom.pdf"); PdfReader reader = new PdfReader(new FileInputStream(pdfinputfile)); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(outFile)); acroFields = stamper.getAcroFields(); CharacterContainer character = new CharacterContainer(edCharakter); // +++ DEBUG +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //Set<String> fieldNames = acroFields.getFields().keySet(); //fieldNames = new TreeSet<String>(fieldNames); //for( String fieldName : fieldNames ) { // acroFields.setField( fieldName, fieldName ); //} // +++ ~DEBUG ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ exportCommonFields(character, 16, 40); setButtons(character.getWound().getNormal(), "Wound.", 7); acroFields.setField("BloodWound", "D:" + character.getHealth().getBlooddamage() + ", W:" + character.getWound().getBlood() + ", DR:" + character.getHealth().getDepatterningrate()); // Charakter Potrait-Bild einfgen List<Base64BinaryType> potraits = character.getPortrait(); if (!potraits.isEmpty()) { Image image = Image.getInstance(potraits.get(0).getValue()); if (image != null) { image.setAbsolutePosition(18.5f, 702.5f); image.scaleAbsolute(91.5f, 93f); PdfContentByte overContent = stamper.getOverContent(2); if (overContent != null) overContent.addImage(image); else errorout.println("Unable to insert character image."); } } int counterArmor = 0; for (ARMORType armor : character.getProtection().getARMOROrSHIELD()) { if (!armor.getUsed().equals(YesnoType.YES)) continue; int physicalarmor = armor.getPhysicalarmor(); int mysticarmor = armor.getMysticarmor(); int penalty = armor.getPenalty(); if ((physicalarmor == 0) && (mysticarmor == 0) && (penalty == 0)) continue; acroFields.setField("ArmorName." + counterArmor, armor.getName()); acroFields.setField("ArmorPhysical." + counterArmor, String.valueOf(physicalarmor)); acroFields.setField("ArmorMystic." + counterArmor, String.valueOf(mysticarmor)); acroFields.setField("ArmorPenalty." + counterArmor, String.valueOf(penalty)); counterArmor++; } acroFields.setField("Discipline", concat(" / ", character.getDisciplineNames())); acroFields.setField("Circle", concat(" / ", character.getDisciplineCircles())); acroFields.setField("HalfMagic", character.getAllHalfMagic()); List<WEAPONType> weapons = character.getWeapons(); if (weapons != null) { int counter = 0; ATTRIBUTEType str = character.getAttributes().get("STR"); for (WEAPONType weapon : weapons) { acroFields.setField("Weapon." + counter, weapon.getName()); acroFields.setField("WeaponStrength." + counter, String.valueOf(str.getStep())); acroFields.setField("WeaponDamage.0." + counter, String.valueOf(weapon.getDamagestep())); acroFields.setField("WeaponDamage.1." + counter, String.valueOf(weapon.getDamagestep() + str.getStep())); acroFields.setField("WeaponRange." + counter, weapon.getShortrange() + " / " + weapon.getLongrange()); counter++; } } counterEquipment = 0; for (ITEMType item : listArmorAndWeapon(character)) addEquipment(item.getName(), item.getWeight()); for (ITEMType item : character.getItems()) addEquipment(item.getName(), item.getWeight()); for (MAGICITEMType item : character.getMagicItem()) { StringBuffer text = new StringBuffer(item.getName()); text.append(" ("); text.append(item.getBlooddamage()); text.append("/"); text.append(item.getDepatterningrate()); text.append("/"); text.append(item.getEnchantingdifficultynumber()); text.append(")"); addEquipment(text.toString(), item.getWeight()); } String copperPieces = null; String goldPieces = null; String silverPieces = null; int otherPieces = 0; for (COINSType coins : character.getAllCoins()) { StringBuffer other = new StringBuffer(); if (coins.getEarth() > 0) other.append(" earth:" + coins.getEarth()); if (coins.getWater() > 0) other.append(" water:" + coins.getWater()); if (coins.getAir() > 0) other.append(" air:" + coins.getAir()); if (coins.getFire() > 0) other.append(" fire:" + coins.getFire()); if (coins.getOrichalcum() > 0) other.append(" orichalcum:" + coins.getOrichalcum()); if (coins.getGem50() > 0) other.append(" gem50:" + coins.getGem50()); if (coins.getGem100() > 0) other.append(" gem100:" + coins.getGem100()); if (coins.getGem200() > 0) other.append(" gem200:" + coins.getGem200()); if (coins.getGem500() > 0) other.append(" gem500:" + coins.getGem500()); if (coins.getGem1000() > 0) other.append(" gem1000:" + coins.getGem1000()); if (!other.toString().isEmpty()) { if (!coins.getName().isEmpty()) other.append(" [" + coins.getName() + "]"); acroFields.setField("Coins." + String.valueOf(otherPieces), other.toString()); otherPieces++; } if (coins.getCopper() != 0) { if (copperPieces == null) { copperPieces = String.valueOf(coins.getCopper()); } else { copperPieces += "+" + String.valueOf(coins.getCopper()); } } if (coins.getSilver() != 0) { if (silverPieces == null) { silverPieces = String.valueOf(coins.getSilver()); } else { silverPieces += "+" + String.valueOf(coins.getSilver()); } } if (coins.getGold() != 0) { if (goldPieces == null) { goldPieces = String.valueOf(coins.getGold()); } else { goldPieces += "+" + String.valueOf(coins.getGold()); } } } acroFields.setField("CopperPieces", copperPieces); acroFields.setField("SilverPieces.0", silverPieces); acroFields.setField("GoldPieces", goldPieces); List<List<SPELLType>> spellslist = new ArrayList<List<SPELLType>>(); spellslist.add(character.getOpenSpellList()); int counterDisciplinetalent = 0; int counterOthertalent = 0; int counterKnack = 0; for (DISCIPLINEType discipline : character.getDisciplines()) { List<TALENTType> disziplinetalents = discipline.getDISZIPLINETALENT(); Collections.sort(disziplinetalents, new TalentComparator()); for (TALENTType talent : disziplinetalents) { // Fr mehr als 20 Disziplintalente ist kein Platz! if (counterDisciplinetalent > 20) break; setTalent(counterDisciplinetalent, talent, character.getAttributes()); counterDisciplinetalent++; for (KNACKType knack : talent.getKNACK()) { acroFields.setField("TalentKnackTalent." + counterKnack, talent.getName()); acroFields.setField("TalentKnackName." + counterKnack, knack.getName() + " [" + knack.getStrain() + "]"); counterKnack++; } } List<TALENTType> optionaltalents = discipline.getOPTIONALTALENT(); Collections.sort(optionaltalents, new TalentComparator()); for (TALENTType talent : optionaltalents) { setTalent(20 + counterOthertalent, talent, character.getAttributes()); if (talent.getKarma().equals(YesnoType.YES)) { acroFields.setField("KarmaRequired." + counterOthertalent, "Yes"); } else { acroFields.setField("KarmaRequired." + counterOthertalent, ""); } counterOthertalent++; for (KNACKType knack : talent.getKNACK()) { acroFields.setField("TalentKnackTalent." + counterKnack, talent.getName()); acroFields.setField("TalentKnackName." + counterKnack, knack.getName() + " [" + knack.getStrain() + "]"); counterKnack++; } } spellslist.add(discipline.getSPELL()); } setSpellAjfelMordom(spellslist); // Die eventuell gesetzte KarmaBentigtHarken lschen while (counterOthertalent < 17) { acroFields.setField("KarmaRequired." + counterOthertalent, ""); counterOthertalent++; } int counterMagicItem = 0; for (THREADITEMType item : character.getThreadItem()) { int counterMagicItemRank = 0; for (THREADRANKType rank : item.getTHREADRANK()) { counterMagicItemRank++; acroFields.setField("ThreadMagicObject." + counterMagicItem, item.getName()); acroFields.setField("ThreadMagicRank." + counterMagicItem, String.valueOf(counterMagicItemRank)); acroFields.setField("ThreadMagicLPCost." + counterMagicItem, String.valueOf(rank.getLpcost())); acroFields.setField("ThreadMagicEffect." + counterMagicItem, rank.getEffect()); counterMagicItem++; } } int counterBloodCharms = 0; for (MAGICITEMType item : character.getBloodCharmItem()) { acroFields.setField("BloodMagicType." + counterBloodCharms, item.getName()); String used = ""; if (item.getUsed().equals(YesnoType.YES)) used = " (in use)"; acroFields.setField("BloodMagicDamage." + counterBloodCharms, item.getBlooddamage() + used); acroFields.setField("BloodMagicEffect." + counterBloodCharms, item.getEffect()); counterBloodCharms++; } acroFields.setField("ShortDescription", character.getDESCRIPTION()); int counterLanguageSpeak = 0; int counterLanguageReadwrite = 0; for (CHARACTERLANGUAGEType language : character.getLanguages().getLanguages()) { if (!language.getSpeak().equals(LearnedbyType.NO)) { acroFields.setField("LanguagesSpeak." + counterLanguageSpeak, language.getLanguage()); counterLanguageSpeak++; } if (!language.getReadwrite().equals(LearnedbyType.NO)) { acroFields.setField("LanguagesReadWrite." + counterLanguageReadwrite, language.getLanguage()); counterLanguageReadwrite++; } } stamper.close(); }
From source file:domain.Pdfmaker.java
public void makePdf() { Document doc = new Document(); doc.setPageSize(PageSize.A4);/*from ww w .ja v a 2 s . c o m*/ try { PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream(test.getTitle() + ".pdf")); writer.setPdfVersion(PdfWriter.VERSION_1_7); doc.open(); Font f = new Font(Font.FontFamily.TIMES_ROMAN, 15, Font.BOLD, new BaseColor(0, 0, 0)); Paragraph title = new Paragraph("TEST TITLE", f); title.setAlignment(Element.ALIGN_CENTER); doc.addCreator("Arne De Bremme"); //make table PdfPTable table = new PdfPTable(4); table.setTotalWidth(550f); table.setLockedWidth(true); table.setHeaderRows(1); Paragraph p = new Paragraph(test.getTitle()); p.setAlignment(Element.ALIGN_CENTER); PdfPCell cell = new PdfPCell(p); cell.setGrayFill(0.7f); cell.setColspan(4); table.addCell(cell); table.addCell(test.getClassGroup().getGroupName()); PdfPCell cell2 = new PdfPCell(new Paragraph(test.getDescription())); cell2.setColspan(2); cell2.setRowspan(2); table.addCell(cell2); PdfPCell cell3 = new PdfPCell(new Paragraph("DD " + test.getStartDate().getDay() + "/" + test.getStartDate().getMonth() + "/" + test.getStartDate().getYear())); cell3.setRowspan(2); table.addCell(cell3); table.addCell(new Paragraph("Test " + test.getTestId())); doc.add(table); doc.add(Chunk.NEWLINE); for (Exercise e : ex) { Paragraph par = new Paragraph(); par.add("Vraag " + counter); par.add(Chunk.TABBING); par.add(Chunk.TABBING); par.add(Chunk.TABBING); par.add(Chunk.TABBING); par.add(e.getPunten() + "/"); doc.add(par); doc.add(new Paragraph("Klimatogram " + e.getClimateChart().getLocation() + " " + e.getPunten())); Robot r = new Robot(); Desktop.getDesktop().browse(new URI( "http://climatechart.azurewebsites.net/ClimateChart/ShowExercises?selectedYear=1&continentId=" + e.getClimateChart().getCountry().getContinent().getId() + "&countryId=" + e.getClimateChart().getCountry().getContinent().getId() + "&climateId=" + e.getClimateChart().getId())); TimeUnit.SECONDS.sleep(6); BufferedImage bi = r.createScreenCapture( new Rectangle(Toolkit.getDefaultToolkit().getScreenSize().width * 7 / 10, Toolkit.getDefaultToolkit().getScreenSize().width * 8 / 14)); File file = new File("screenCapture" + counter + ".jpg"); ImageIO.write(bi, "jpg", file); Image img = Image.getInstance("screenCapture.jpg"); img.scaleAbsolute(400, 300); doc.add(img); doc.add(Chunk.NEWLINE); doc.add(new Paragraph(e.getNaam())); doc.add(Chunk.NEXTPAGE); counter++; } doc.close(); File filz = new File(test.getTitle() + ".pdf"); Desktop.getDesktop().open(filz); } catch (Exception e) { } }