List of usage examples for com.itextpdf.text Image setAbsolutePosition
public void setAbsolutePosition(final float absoluteX, final float absoluteY)
Image
. 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 ); //}//w ww.j av a 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 ww . ja v a 2s.co 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:de.knurt.heinzelmann.util.itext.ImageFactoryDefault.java
License:Creative Commons License
/** * scale image using {@link ResizeMode}// www .j a v a 2 s. c om */ @Override public Image getImageFromFileResource(File image, float width, float height, float absoluteX, float absoluteY) throws BadElementException, MalformedURLException, IOException { Image result = Image.getInstance(image.getAbsolutePath()); switch (rmUsed) { case SCALE_TO_FIT: result.scaleToFit(width, height); break; case SKEW: if (result.getScaledWidth() != width) { result.scaleAbsoluteWidth(width); } if (result.getScaledHeight() != height) { result.scaleAbsoluteHeight(height); } break; } result.setAbsolutePosition(absoluteX, absoluteY); return result; }
From source file:de.tuttas.servlets.DokuServlet.java
private Document createUmfrageauswertung(List<UmfrageResult> res1, List<UmfrageResult> res2, int idUmfrage1, int idUmfrage2, String filter1, String filter2, String kopf, OutputStream out) throws DocumentException, BadElementException, IOException { Document document = new Document(); /* Basic PDF Creation inside servlet */ Umfrage u1 = em.find(Umfrage.class, idUmfrage1); Umfrage u2 = em.find(Umfrage.class, idUmfrage2); // Bild einfgen String url = "http://www.mmbbs.de/fileadmin/template/mmbbs/gfx/mmbbs_logo_druck.gif"; Image image = Image.getInstance(url); image.setAbsolutePosition(45f, 720f); image.scalePercent(50f);// www . j a v a 2 s . com StringBuilder htmlString = new StringBuilder(); htmlString.append(kopf); htmlString.append("<br></br>"); int maxRows = res1.size(); if (res2.size() > maxRows) { maxRows = res2.size(); } PdfWriter writer = PdfWriter.getInstance(document, out); document.open(); writer.setPageEmpty(false); Font boldFont = new Font(Font.FontFamily.HELVETICA, 18, Font.BOLD); Font normalFont = new Font(Font.FontFamily.HELVETICA, 10, Font.ITALIC); PdfPTable table = new PdfPTable(new float[] { 1, 2, 2 }); PdfPCell qestionCell; PdfPCell group1Cell; PdfPCell group2Cell; int i = 0; for (i = 0; i < maxRows; i++) { Log.d("Print Row " + i); if (i % 5 == 0) { if (i != 0) { document.add(table); document.newPage(); document = printHead(writer, document, htmlString, out, image); } else { document = printHead(writer, document, htmlString, out, image); } table = new PdfPTable(new float[] { 1, 2, 2 }); table.setWidthPercentage((float) 100.0); qestionCell = new PdfPCell(new Phrase("\nFragen", boldFont)); group1Cell = new PdfPCell(); group1Cell.addElement(new Phrase("Hauptgruppe:", boldFont)); group1Cell.addElement(new Phrase(u1.getNAME() + "\n" + filter1, normalFont)); group2Cell = new PdfPCell(); group2Cell.addElement(new Phrase("Vergleichsgruppe:", boldFont)); group2Cell.addElement(new Phrase(u2.getNAME() + "\n" + filter2, normalFont)); qestionCell.setBorderWidth(2.0f); group1Cell.setBorderWidth(2.0f); group2Cell.setBorderWidth(2.0f); table.addCell(qestionCell); table.addCell(group1Cell); table.addCell(group2Cell); } String url1 = UmfrageUtil.getCharUrl(res1.get(i)); Log.d("URL1=" + url1); Image image1 = Image.getInstance(url1); Image image2 = null; if (res2.size() > i) { String url2 = UmfrageUtil.getCharUrl(res2.get(i)); Log.d("URL2=" + url2); image2 = Image.getInstance(url2); } Log.d("Write to pdf:" + res1.get(i).getFrage()); qestionCell = new PdfPCell(new Phrase(res1.get(i).getFrage(), normalFont)); qestionCell.setBorderWidth(1.0f); group1Cell = new PdfPCell(image1, true); group1Cell.setBorderWidth(1.0f); group1Cell.setPadding(10); if (image2 != null) group2Cell = new PdfPCell(image2, true); else group2Cell = new PdfPCell(); group2Cell.setBorderWidth(1.0f); group2Cell.setPadding(10); table.addCell(qestionCell); table.addCell(group1Cell); table.addCell(group2Cell); } if (!(i % 5 == 0)) { document.add(table); } document.close(); return document; }
From source file:de.tuttas.servlets.DokuServlet.java
private Document createBetriebsListe(MyTableDataModel mo, String kopf, OutputStream out) throws ParseException, IOException, DocumentException { Document document = new Document(); /* Basic PDF Creation inside servlet */ PdfWriter writer = PdfWriter.getInstance(document, out); StringBuilder htmlString = new StringBuilder(); htmlString.append(kopf);//from ww w. ja v a2s. c o m htmlString.append( "<br></br><table align='center' width='100%' style=\"border: 2px solid black; border-collapse: collapse;\">"); htmlString.append( "<tr><td width='25%' style=\"padding:5px;font-size: 14;border: 1px solid black;\"><b>Name</b></td>"); htmlString.append("<td style=\"padding:5px;border: 1px solid black;\">" + mo.getData(1, 0) + "</td>"); htmlString.append("<td style=\"padding:5px;border: 1px solid black;\">" + mo.getData(2, 0) + "</td>"); htmlString.append("<td style=\"padding:5px;border: 1px solid black;\">" + mo.getData(3, 0) + "</td>"); htmlString.append("<td style=\"padding:5px;border: 1px solid black;\">" + mo.getData(4, 0) + "</td>"); htmlString.append("<td style=\"padding:5px;border: 1px solid black;\">" + mo.getData(5, 0) + "</td>"); htmlString.append("</tr>"); for (int y = 1; y < mo.getRows(); y++) { htmlString.append("<tr>"); htmlString.append("<td style=\"padding:5px;border: 1px solid black;\">" + mo.getData(0, y) + "</td>"); for (int x = 1; x < mo.getCols(); x++) { htmlString.append("<td style=\"font-size: 10;padding:5px;border: 1px solid black;\">" + mo.getData(x, y) + "</td>"); } htmlString.append("</tr>"); } htmlString.append("</table>"); document.open(); // Dokument erzeugen InputStream is = new ByteArrayInputStream(htmlString.toString().getBytes()); // Bild einfgen String url = "http://www.mmbbs.de/fileadmin/template/mmbbs/gfx/mmbbs_logo_druck.gif"; Image image = Image.getInstance(url); image.setAbsolutePosition(45f, 720f); image.scalePercent(50f); document.add(image); XMLWorkerHelper.getInstance().parseXHtml(writer, document, is); document.close(); return document; }
From source file:de.tuttas.servlets.DokuServlet.java
private Document createNotenliste(MyTableDataModel mo, String kopf, OutputStream out, String schuljahrName) throws ParseException, IOException, DocumentException { Document document = new Document(); /* Basic PDF Creation inside servlet */ PdfWriter writer = PdfWriter.getInstance(document, out); StringBuilder htmlString = new StringBuilder(); htmlString.append(kopf);/*w w w. j a v a 2s . c o m*/ htmlString.append("<h3 align=\"center\">" + schuljahrName + "</h3>"); htmlString.append( "<table align='center' width='100%' style=\"border: 2px solid black; border-collapse: collapse;\">"); htmlString.append( "<tr><td width='25%' style=\"padding:5px;font-size: 14;border: 1px solid black;\"><b>Name</b></td>"); for (int x = 1; x < mo.getCols(); x++) { htmlString.append("<td style=\"padding:5px;border: 1px solid black;\">" + mo.getData(x, 0) + "</td>"); } htmlString.append("</tr>"); for (int y = 1; y < mo.getRows(); y++) { htmlString.append("<tr>"); htmlString.append("<td style=\"padding:5px;border: 1px solid black;\">" + mo.getData(0, y) + "</td>"); for (int x = 1; x < mo.getCols(); x++) { htmlString .append("<td style=\"padding:5px;border: 1px solid black;\">" + mo.getData(x, y) + "</td>"); } htmlString.append("</tr>"); } htmlString.append("</table>"); document.open(); // Dokument erzeugen InputStream is = new ByteArrayInputStream(htmlString.toString().getBytes()); // Bild einfgen String url = "http://www.mmbbs.de/fileadmin/template/mmbbs/gfx/mmbbs_logo_druck.gif"; Image image = Image.getInstance(url); image.setAbsolutePosition(45f, 720f); image.scalePercent(50f); document.add(image); XMLWorkerHelper.getInstance().parseXHtml(writer, document, is); document.close(); return document; }
From source file:de.tuttas.servlets.DokuServlet.java
private Document createStundenplan(Klasse kl, String kopf, Date parsedFrom, Date parsedTo, OutputStream out) throws ParseException, IOException, DocumentException { Document document = new Document(); /* Basic PDF Creation inside servlet */ PdfWriter writer = PdfWriter.getInstance(document, out); StringBuilder htmlString = new StringBuilder(); htmlString.append(kopf);// w ww . ja v a 2 s . c o m htmlString.append(StundenplanUtil.getInstance().getPlan(kl.getKNAME(), PlanType.STDPlanSchueler)); document.open(); // Dokument erzeugen InputStream is = new ByteArrayInputStream(htmlString.toString().getBytes()); // Bild einfgen String url = "http://www.mmbbs.de/fileadmin/template/mmbbs/gfx/mmbbs_logo_druck.gif"; Image image = Image.getInstance(url); image.setAbsolutePosition(45f, 720f); image.scalePercent(50f); document.add(image); XMLWorkerHelper.getInstance().parseXHtml(writer, document, is); document.close(); return document; }
From source file:de.tuttas.servlets.DokuServlet.java
private Document createVertretungsplan(Klasse kl, String kopf, Date parsedFrom, Date parsedTo, OutputStream out) throws ParseException, IOException, DocumentException { Document document = new Document(); /* Basic PDF Creation inside servlet */ PdfWriter writer = PdfWriter.getInstance(document, out); StringBuilder htmlString = new StringBuilder(); htmlString.append(kopf);// ww w . j a va 2 s . c om htmlString.append(StundenplanUtil.getInstance().getPlan(kl.getKNAME(), PlanType.VERTRPlanSchueler)); document.open(); // Dokument erzeugen InputStream is = new ByteArrayInputStream(htmlString.toString().getBytes()); // Bild einfgen String url = "http://www.mmbbs.de/fileadmin/template/mmbbs/gfx/mmbbs_logo_druck.gif"; Image image = Image.getInstance(url); image.setAbsolutePosition(45f, 720f); image.scalePercent(50f); document.add(image); XMLWorkerHelper.getInstance().parseXHtml(writer, document, is); document.close(); return document; }
From source file:de.tuttas.servlets.DokuServlet.java
private Document createFehlzeiten(Klasse kl, String kopf, Date parsedFrom, Date parsedTo, OutputStream out) throws ParseException, IOException, DocumentException { Document document = new Document(); /* Basic PDF Creation inside servlet */ PdfWriter writer = PdfWriter.getInstance(document, out); StringBuilder htmlString = new StringBuilder(); htmlString.append(kopf);//from w w w.jav a2 s .c o m TypedQuery<AnwesenheitEintrag> query = em.createNamedQuery("findAnwesenheitbyKlasse", AnwesenheitEintrag.class); query.setParameter("paramKName", kl.getKNAME()); query.setParameter("paramFromDate", new java.sql.Date(parsedFrom.getTime())); query.setParameter("paramToDate", new java.sql.Date(parsedTo.getTime())); Log.d("setze From auf " + new java.sql.Date(parsedFrom.getTime())); List<AnwesenheitObjekt> anwesenheit = getData(query); Log.d("Result List:" + anwesenheit); document.open(); String tagZeile = ""; tagZeile += "<table align='center' width='100%' style=\"border: 2px solid black; border-collapse: collapse;\">\n"; tagZeile += AnwesenheitObjekt.getTRHead(); for (AnwesenheitObjekt ao : anwesenheit) { VerspaetungsUtil.parse(ao); if (ao.getAnzahlVerspaetungen() != 0 || ao.getSummeFehltage() != 0) { Schueler s = em.find(Schueler.class, ao.getId_Schueler()); Log.d("Fehltage fr Schuler " + s); tagZeile += ao.toHTML(s.getVNAME() + " " + s.getNNAME()); } } tagZeile += "</table>"; htmlString.append(tagZeile); // Dokument erzeugen InputStream is = new ByteArrayInputStream(htmlString.toString().getBytes()); // Bild einfgen String url = "http://www.mmbbs.de/fileadmin/template/mmbbs/gfx/mmbbs_logo_druck.gif"; Image image = Image.getInstance(url); image.setAbsolutePosition(45f, 720f); image.scalePercent(50f); document.add(image); XMLWorkerHelper.getInstance().parseXHtml(writer, document, is); document.close(); return document; }
From source file:de.tuttas.servlets.DokuServlet.java
private Document createAnwesenheit(Klasse kl, String kopf, Date parsedFrom, Date parsedTo, OutputStream out, int filter1Id, int filter2Id) throws ParseException, IOException, DocumentException { Document document = new Document(); /* Basic PDF Creation inside servlet */ PdfWriter writer = PdfWriter.getInstance(document, out); StringBuilder htmlString = new StringBuilder(); htmlString.append(kopf);/* w w w .j a v a 2 s . c o m*/ /* Anwesenheit einfgen */ TypedQuery<AnwesenheitEintrag> query = em.createNamedQuery("findAnwesenheitbyKlasse", AnwesenheitEintrag.class); query.setParameter("paramKName", kl.getKNAME()); query.setParameter("paramFromDate", new java.sql.Date(parsedFrom.getTime())); query.setParameter("paramToDate", new java.sql.Date(parsedTo.getTime())); Log.d("setze From auf " + new java.sql.Date(parsedFrom.getTime())); List<AnwesenheitObjekt> anwesenheit = getData(query); /** * Termindaten holen */ Termine t1 = null; Termine t2 = null; if (filter1Id != -1) { t1 = em.find(Termine.class, filter1Id); } if (filter2Id != -1) { t2 = em.find(Termine.class, filter2Id); } List<Termin> termine = null; TypedQuery<Termin> tquery = null; if (filter1Id != 0) { // zwei Filter if (filter2Id != 0) { tquery = em.createNamedQuery("findAllTermineTwoFilters", Termin.class); tquery.setParameter("filter1", t1.getId()); tquery.setParameter("filter2", t2.getId()); tquery.setParameter("fromDate", new java.sql.Date(parsedFrom.getTime())); tquery.setParameter("toDate", new java.sql.Date(parsedTo.getTime())); termine = tquery.getResultList(); } // nur Filter1 else { tquery = em.createNamedQuery("findAllTermineOneFilter", Termin.class); tquery.setParameter("filter1", t1.getId()); tquery.setParameter("fromDate", new java.sql.Date(parsedFrom.getTime())); tquery.setParameter("toDate", new java.sql.Date(parsedTo.getTime())); termine = tquery.getResultList(); } } else { // nur Filter2 if (filter2Id != 0) { tquery = em.createNamedQuery("findAllTermineOneFilter", Termin.class); tquery.setParameter("filter1", t2.getId()); tquery.setParameter("fromDate", new java.sql.Date(parsedFrom.getTime())); tquery.setParameter("toDate", new java.sql.Date(parsedTo.getTime())); termine = tquery.getResultList(); } // kein Filter, Termine so generieren else { termine = new ArrayList<>(); Date current = new Date(parsedFrom.getTime()); parsedTo.setTime(parsedTo.getTime() + 1000); while (current.before(parsedTo)) { termine.add(new Termin(new Timestamp(current.getTime()))); Log.d("Erzeuge neuen Termin:" + new Termin(new Timestamp(current.getTime()))); current.setTime(current.getTime() + 24 * 60 * 60 * 1000); } } } Log.d("Result List:" + anwesenheit); GregorianCalendar c = (GregorianCalendar) GregorianCalendar.getInstance(); c.setTime(parsedFrom); String tagZeile = ""; document.open(); Query q = em.createNamedQuery("findSchuelerEinerBenanntenKlasse"); q.setParameter("paramNameKlasse", kl.getKNAME()); List<Schueler> schueler = q.getResultList(); Date current = new Date(parsedFrom.getTime()); Log.d("Current=" + current + " TO=" + parsedTo + " From=" + parsedFrom + " Termine=" + termine.size()); int spalte = 0; for (spalte = 0; spalte < termine.size(); spalte++) { tagZeile += "<table align='center' width='100%' style=\"border: 2px solid black; border-collapse: collapse;\">\n"; tagZeile += ("<tr >\n"); tagZeile += ("<td width='25%' style=\"font-size: 14;border: 1px solid black;\"><b>Name</b></td>\n"); // Zeile f. Tage (Headline) Log.d("Spalte ist nun " + spalte); int i = 0; for (i = 0; i < 7 && spalte + i < termine.size(); i++) { current = new Date(termine.get(spalte + i).getDate().getTime()); c.setTime(current); if (c.get(GregorianCalendar.DAY_OF_WEEK) == 1 || c.get(GregorianCalendar.DAY_OF_WEEK) == 7) { tagZeile += ("<td align=\"center\" style=\"padding:5px; background-color: #cccccc; font-size: 12;border: 1px solid black;\">" + DatumUtil.getWochentag(c.get(GregorianCalendar.DAY_OF_WEEK)) + "<br></br>" + c.get(GregorianCalendar.DATE) + "." + (c.get(GregorianCalendar.MONTH) + 1) + "." + c.get(GregorianCalendar.YEAR) + "</td>\n"); } else { tagZeile += ("<td align=\"center\" style=\"padding: 5px; font-size: 12;border: 1px solid black;\">" + DatumUtil.getWochentag(c.get(GregorianCalendar.DAY_OF_WEEK)) + "<br></br>" + c.get(GregorianCalendar.DATE) + "." + (c.get(GregorianCalendar.MONTH) + 1) + "." + c.get(GregorianCalendar.YEAR) + "</td>\n"); } Log.d("Spalte " + (i + spalte) + " Datum=" + current); } Log.d("Head aufgebaut"); tagZeile += "</tr>\n"; // Zeile pro Name for (Schueler s : schueler) { tagZeile += "<tr>\n"; tagZeile += ("<td width='20%' style=\"padding: 5px;font-size: 12;border: 1px solid black;\"><b>" + s.getVNAME() + " " + s.getNNAME() + "</b></td>\n"); // Zeile f. Tage //Log.d("Zeile f. Schler " + s.getNNAME()); for (i = 0; i < 7 && spalte + i < termine.size(); i++) { current = new Date(termine.get(spalte + i).getDate().getTime()); c.setTime(current); if (c.get(GregorianCalendar.DAY_OF_WEEK) == 1 || c.get(GregorianCalendar.DAY_OF_WEEK) == 7) { tagZeile += ("<td style=\"background-color:#cccccc;font-size: 11;border: 1px solid black;\">" + findVermerk(s.getId(), current, anwesenheit) + "</td>\n"); } else { tagZeile += ("<td style=\"font-size: 11;border: 1px solid black;\">" + findVermerk(s.getId(), current, anwesenheit) + "</td>\n"); } Log.d("Zeile f. Schler " + s.getNNAME() + " Datum " + current); } tagZeile += "</tr>\n"; } Log.d("Rumpf aufgebaut"); spalte = spalte + i - 1; // neue Seite bei 7 Terminen if (i == 7) { tagZeile += "</table>\n"; htmlString.append(tagZeile); InputStream is = new ByteArrayInputStream(htmlString.toString().getBytes()); // Bild einfgen String url = "http://www.mmbbs.de/fileadmin/template/mmbbs/gfx/mmbbs_logo_druck.gif"; Image image = Image.getInstance(url); image.setAbsolutePosition(45f, 720f); image.scalePercent(50f); document.add(image); XMLWorkerHelper.getInstance().parseXHtml(writer, document, is); document.newPage(); Log.d("neue Seite"); htmlString = new StringBuilder(); tagZeile = ""; htmlString.append(kopf); } Log.d("SPalte ist " + spalte + " Termine=" + termine.size()); } Log.d("Ende der ForSchleife spalte=" + spalte); // den Rest der Seite noch drucken if (spalte % 7 != 0) { tagZeile += "</table>\n"; htmlString.append(tagZeile); Log.d("Rest Seite erzeugen"); //Log.d("html String =" + htmlString.toString()); //document.add(new Paragraph("Tutorial to Generate PDF using Servlet")); InputStream is = new ByteArrayInputStream(htmlString.toString().getBytes()); // Bild einfgen String url = "http://www.mmbbs.de/fileadmin/template/mmbbs/gfx/mmbbs_logo_druck.gif"; Image image = Image.getInstance(url); image.setAbsolutePosition(45f, 720f); image.scalePercent(50f); document.add(image); Log.d("writer=" + writer + " document=" + document + " is=" + is); XMLWorkerHelper.getInstance().parseXHtml(writer, document, is); } document.close(); return document; }