List of usage examples for com.itextpdf.text.pdf PdfReader PdfReader
public PdfReader(final PdfReader reader)
From source file:de.earthdawn.ECEPdfExporter.java
License:Open Source License
public void exportRedbrickSimple(EDCHARACTER edCharakter, File outFile) throws DocumentException, IOException { PdfReader reader = new PdfReader(new FileInputStream(new File("./templates/ed3_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 ); //}/*ww w. java 2 s . com*/ // +++ ~DEBUG ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ exportCommonFields(character, 16, 41); acroFields.setField("Shield", "none"); acroFields.setField("ShieldDeflectionBonus", "na"); 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.size() > 0) { DISCIPLINEType discipline1 = disciplines.get(0); List<TALENTType> disziplinetalents = discipline1.getDISZIPLINETALENT(); Collections.sort(disziplinetalents, new TalentComparator()); HashMap<String, ATTRIBUTEType> attributes = character.getAttributes(); int counter = 0; for (TALENTType talent : disziplinetalents) { if ((talent.getCircle() > 4) && (counter < 9)) { counter = 9; } 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 < 4)) { counter = 4; } setTalent(13 + 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 = 0; for (WEAPONType weapon : weapons) { acroFields.setField("Weapon." + counter, weapon.getName()); acroFields.setField("WeaponDmgStep." + counter, String.valueOf(weapon.getDamagestep())); acroFields.setField("Weapon Size." + counter, String.valueOf(weapon.getSize())); acroFields.setField("WeaponTimesForged." + counter, String.valueOf(weapon.getTimesforged())); acroFields.setField("WeaponShortRange." + counter, String.valueOf(weapon.getShortrange())); acroFields.setField("Weapon Long Range." + counter, String.valueOf(weapon.getLongrange())); counter++; } } 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(50, 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; } } List<THREADITEMType> magicitems = character.getThreadItem(); if (!magicitems.isEmpty()) { THREADITEMType magicitem = character.getThreadItem().get(0); if (magicitem != null) { int counterThreadItem = 0; int weaventhreadrank = magicitem.getWeaventhreadrank(); acroFields.setField("MagicalTreasureName", magicitem.getName()); acroFields.setField("MagicalTreasureSpellDefense", String.valueOf(magicitem.getSpelldefense())); acroFields.setField("MagicalTreasureMaxThreads", String.valueOf(magicitem.getMaxthreads())); int counterMagicItemDescription = 0; for (String description : wrapString(50, magicitem.getDESCRIPTION())) { acroFields.setField("MagicalTreasureDesc." + counterMagicItemDescription, 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 : magicitem.getTHREADRANK()) { acroFields.setField("MagicalTreasureRank." + counterMagicItemRank, String.valueOf(counterMagicItemRank + 1)); acroFields.setField("MagicalTreasureLPCost." + counterMagicItemRank, String.valueOf(rank.getLpcost())); acroFields.setField("MagicalTreasureKeyKnowledge." + counterMagicItemRank, rank.getKeyknowledge()); acroFields.setField("MagicalTreasureEffect." + counterMagicItemRank, rank.getEffect()); if (counterMagicItemRank < weaventhreadrank) { acroFields.setField("ThreadMagicTarget." + counterThreadItem, magicitem.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++; } } } 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 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 w w w . j a v 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;/*ww 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:de.earthdawn.ECEPdfExporter.java
License:Open Source License
public void exportSpellcards(EDCHARACTER edCharakter, File outFile, int version) throws DocumentException, IOException { CharacterContainer character = new CharacterContainer(edCharakter); File template = null;/*from www. j a v a 2 s . co m*/ int maxSpellPerPage = 1; switch (version) { case 0: default: template = new File("./templates/spellcards_portrait_2x2.pdf"); maxSpellPerPage = 4; break; case 1: template = new File("./templates/spellcards_landscape_2x2.pdf"); maxSpellPerPage = 4; break; } String filename = outFile.getCanonicalPath(); String filenameBegin = ""; String filenameEnd = ""; int dotPosition = filename.lastIndexOf('.'); if (dotPosition >= 0) { filenameBegin = filename.substring(0, dotPosition); filenameEnd = filename.substring(dotPosition); } else { filenameBegin = filename; } int counterFile = 0; int counterSpells = maxSpellPerPage; PdfStamper stamper = null; PdfReader reader = null; HashMap<String, SpelldescriptionType> spelldescriptions = ApplicationProperties.create() .getSpellDescriptions(); List<List<SPELLType>> spellslist = new ArrayList<List<SPELLType>>(); List<String> disciplineNames = new ArrayList<String>(); spellslist.add(character.getOpenSpellList()); disciplineNames.add(""); for (DISCIPLINEType discipline : character.getDisciplines()) { spellslist.add(discipline.getSPELL()); disciplineNames.add(discipline.getName()); } int spelllistnr = 0; for (List<SPELLType> spells : spellslist) { Collections.sort(spells, new SpellComparator()); for (SPELLType spell : spells) { if (counterSpells < maxSpellPerPage) { counterSpells++; } else { if (stamper != null) stamper.close(); if (reader != null) reader.close(); reader = new PdfReader(new FileInputStream(template)); stamper = new PdfStamper(reader, new FileOutputStream( new File(filenameBegin + String.format("%02d", counterFile) + filenameEnd))); acroFields = stamper.getAcroFields(); counterSpells = 1; counterFile++; } acroFields.setField("Discipline" + counterSpells, disciplineNames.get(spelllistnr)); acroFields.setField("Spell Name" + counterSpells, spell.getName()); acroFields.setField("Spell Circle" + counterSpells, String.valueOf(spell.getCircle())); acroFields.setField("Spellcasting" + counterSpells, spell.getCastingdifficulty()); acroFields.setField("Threads" + counterSpells, spell.getThreads()); acroFields.setField("Weaving" + counterSpells, spell.getWeavingdifficulty()); acroFields.setField("Reattuning" + counterSpells, String.valueOf(spell.getReattuningdifficulty())); acroFields.setField("Range" + counterSpells, spell.getRange()); acroFields.setField("Duration" + counterSpells, spell.getDuration()); acroFields.setField("Effect" + counterSpells, spell.getEffect()); acroFields.setField("Page reference" + counterSpells, String.valueOf(spell.getBookref())); acroFields.setField("Air" + counterSpells, "No"); acroFields.setField("Earth" + counterSpells, "No"); acroFields.setField("Fear" + counterSpells, "No"); acroFields.setField("Fire" + counterSpells, "No"); acroFields.setField("Illusion" + counterSpells, "No"); acroFields.setField("Illusion N" + counterSpells, "Yes"); acroFields.setField("Water" + counterSpells, "No"); acroFields.setField("Wood" + counterSpells, "No"); switch (spell.getElement()) { case AIR: acroFields.setField("Air" + counterSpells, "Yes"); break; case EARTH: acroFields.setField("Earth" + counterSpells, "Yes"); break; case FEAR: acroFields.setField("Fear" + counterSpells, "Yes"); break; case FIRE: acroFields.setField("Fire" + counterSpells, "Yes"); break; case ILLUSION: acroFields.setField("Illusion" + counterSpells, "Yes"); acroFields.setField("Illusion N" + counterSpells, "No"); break; case WATER: acroFields.setField("Water" + counterSpells, "Yes"); break; case WOOD: acroFields.setField("Wood" + counterSpells, "Yes"); break; case UNDEFINED: break; } SpelldescriptionType spelldescription = spelldescriptions.get(spell.getName()); if ((spelldescription == null) || (spelldescription.getValue() == null)) acroFields.setField("Spell description" + counterSpells, ""); else acroFields.setField("Spell description" + counterSpells, spelldescription.getValue()); } spelllistnr++; } stamper.close(); }
From source file:de.extra.xtt.util.pdf.PdfCreatorImpl.java
License:Apache License
/** * Erzeugt das Inhaltsverzeichnis aus den bereits vorhandenen Elementen in * der Liste <code>listEntries</code>. * /* w ww .java 2 s .c o m*/ * @param docPdf * Zieldokument, falls Inhaltsverzeichnis nicht temporr erzeugt * wird * @param temp * Gibt an, ob das Inhaltsverzeichnis temporr in einer neuen * Datei/Dokument erzeugt werden soll * @return Anzahl der Seiten * @throws DocumentException * @throws IOException */ private int erzeugeInhaltsverzeichnis(Document docPdf, boolean temp) throws DocumentException, IOException { int anzPages = 0; Document docInhalt = docPdf; String filePathTempInhaltString = ""; if (temp) { // temp. Dateinamen bestimmen File fileDokuFile = new File(dateiname); filePathTempInhaltString = fileDokuFile.getParent() + "/tmp_inhalt.pdf"; // Neues Dokument erzeugen docInhalt = initPdfWriterAndDocument(filePathTempInhaltString, false); } // berschrift Chapter currChapter = new Chapter(getParagraphChapter("Inhaltsverzeichnis"), 0); // 0, damit keine Nummerierung currChapter.setNumberDepth(0); docInhalt.add(currChapter); // eine Zeile Abstand docInhalt.add(getEmptyLineTextHalf()); for (ContPdfEntry currEntry : listEntries) { // Eintrag erzeugen inkl. Abstand String strEintrag = currEntry.getBezeichnung() + " "; Chunk chunkBezeichnung; Chunk chunkSeitenzahlChunk; if (currEntry.getParentEntry() == null) { // 1. Ebene => fett, Abstand davor einfgen docInhalt.add(getEmptyLineTextHalf()); chunkBezeichnung = getChunkTextBold(strEintrag); chunkSeitenzahlChunk = getChunkTextBold("" + currEntry.getPageNumber()); } else { // 2. Ebene chunkBezeichnung = getChunkText(strEintrag); chunkSeitenzahlChunk = getChunkText("" + currEntry.getPageNumber()); } // Referenz setzen chunkBezeichnung.setLocalGoto(currEntry.getDestination()); chunkSeitenzahlChunk.setLocalGoto(currEntry.getDestination()); // Abstandzeichen generieren, Breite auffllen float widthAbstand = docInhalt.getPageSize().getWidth() * 0.81f; ; while (chunkBezeichnung.getWidthPoint() <= widthAbstand) { chunkBezeichnung.append("."); } // Tabelle erzeugen und formatieren PdfPTable currTable = new PdfPTable(2); currTable.setWidthPercentage(100f); currTable.setWidths(new int[] { 96, 4 }); // Inhalte einfgen // Zelle Bezeichnung PdfPCell currCellBezeichnung = new PdfPCell(new Phrase(chunkBezeichnung)); currCellBezeichnung.setBorder(0); currCellBezeichnung.setHorizontalAlignment(Element.ALIGN_JUSTIFIED_ALL); // Zelle Seitennummer PdfPCell currCellPageNumberCell = new PdfPCell(new Phrase(chunkSeitenzahlChunk)); currCellPageNumberCell.setBorder(0); currCellPageNumberCell.setHorizontalAlignment(Element.ALIGN_RIGHT); // Zellen zur Tabelle hinzufgen currTable.addCell(currCellBezeichnung); currTable.addCell(currCellPageNumberCell); docInhalt.add(currTable); } if (temp) { // Dokument schlieen docInhalt.close(); // Anzahl der Seitenzahlen bestimmen PdfReader reader = new PdfReader(filePathTempInhaltString); anzPages = reader.getNumberOfPages(); reader.close(); // temp. Datei lschen File currFileInhaltFile = new File(filePathTempInhaltString); currFileInhaltFile.delete(); } return anzPages; }
From source file:de.gbv.marginalia.Marginalia.java
License:Open Source License
/** * Inspect a PDF file and write the info to a writer * @param writer Writer to a text file//from www. jav a2 s .co m * @param filename Path to the PDF file * @throws IOException */ public static void inspect(PrintWriter writer, String filename) throws IOException, SAXException { // writer.println(filename); writer.flush(); PdfReader reader = new PdfReader(filename); ContentHandler xmlhandler = new SimpleXMLWriter(writer); xmlhandler.startDocument(); SimpleXMLCreator xml = new SimpleXMLCreator(xmlhandler, Annotation.namespaces, true); /* writer.println("Number of pages: "+reader.getNumberOfPages()); Rectangle mediabox = reader.getPageSize(1); writer.print("Size of page 1: ["); writer.print(mediabox.getLeft()); writer.print(','); writer.print(mediabox.getBottom()); writer.print(','); writer.print(mediabox.getRight()); writer.print(','); writer.print(mediabox.getTop()); writer.println("]"); writer.print("Rotation of page 1: "); writer.println(reader.getPageRotation(1)); writer.print("Page size with rotation of page 1: "); writer.println(reader.getPageSizeWithRotation(1)); writer.println(); writer.flush(); */ List<Annotation> annots = new LinkedList<Annotation>(); xml.startElement("annots"); // TODO: The following elements may be added: // - optionally write <f href="Document.pdf"/> // - optionally write <ids original="ID" modified="ID" /> xml.startElement("m", "pages"); for (int pageNum = 1; pageNum <= reader.getNumberOfPages(); pageNum++) { PdfDictionary pageDic = reader.getPageN(pageNum); Map<String, String> attr = new HashMap<String, String>(); attr.put("number", "" + pageNum); attr.put("rotate", "" + reader.getPageRotation(pageNum)); Rectangle mediabox = reader.getPageSize(pageNum); attr.put("left", "" + mediabox.getLeft()); attr.put("bottom", "" + mediabox.getBottom()); attr.put("right", "" + mediabox.getRight()); attr.put("top", "" + mediabox.getTop()); xml.contentElement("m", "page", "", attr); PdfArray rawannots = pageDic.getAsArray(PdfName.ANNOTS); if (rawannots == null || rawannots.isEmpty()) { // writer.println("page "+pageNum+" contains no annotations"); continue; } // writer.println("page "+pageNum+" has "+rawannots.size()+" annotations"); for (int i = 0; i < rawannots.size(); i++) { PdfObject obj = rawannots.getDirectObject(i); if (!obj.isDictionary()) continue; Annotation a = new Annotation((PdfDictionary) obj, pageNum); annots.add(a); } /** // Now we have all highlight and similar annotations, we need // to find out what words are actually highlighted! PDF in fact // is a dump format to express documents. // For some hints see // http://stackoverflow.com/questions/4028240/extract-each-column-of-a-pdf-file // We could reuse code from LocationTextExtractionStrategy (TODO) // LocationTextExtractionStrategy extr = new LocationTextExtractionStrategy(); String fulltext = PdfTextExtractor.getTextFromPage(reader,pageNum);//,extr writer.println(fulltext); */ } xml.endElement(); for (Annotation a : annots) { a.serializeXML(xmlhandler); } // TODO: add page information (page size and orientation) xml.endAll(); }
From source file:de.jost_net.JVerein.io.FormularAufbereitung.java
License:Open Source License
public void writeForm(Formular formular, Map<String, Object> map) throws RemoteException { try {// w w w.ja v a2 s .co m PdfReader reader = new PdfReader(formular.getInhalt()); int numOfPages = reader.getNumberOfPages(); for (int i = 1; i <= numOfPages; i++) { doc.setPageSize(reader.getPageSize(i)); doc.newPage(); PdfImportedPage page = writer.getImportedPage(reader, i); PdfContentByte contentByte = writer.getDirectContent(); contentByte.addTemplate(page, 0, 0); DBIterator<Formularfeld> it = Einstellungen.getDBService().createList(Formularfeld.class); it.addFilter("formular = ? and seite = ?", new Object[] { formular.getID(), i }); while (it.hasNext()) { Formularfeld f = (Formularfeld) it.next(); goFormularfeld(contentByte, f, map.get(f.getName())); } } } catch (IOException e) { throw new RemoteException("Fehler", e); } catch (DocumentException e) { throw new RemoteException("Fehler", e); } }
From source file:de.mat.utils.pdftools.PdfAddPageNum.java
License:Mozilla Public License
/** * <h4>FeatureDomain:</h4>//w w w . j a v a 2 s .com * PublishingTools * <h4>FeatureDescription:</h4> * read srcFile, adds pagenum and writes pages to destFile * <h4>FeatureResult:</h4> * <ul> * <li>creates destFile - output to destFile * </ul> * <h4>FeatureKeywords:</h4> * PDF Publishing * @param srcFile - source-file * @param destFile - destination-file * @param pageOffset - offset added to pagenumber * @throws Exception */ public void addPageNumber(String srcFile, String destFile, int pageOffset) throws Exception { PdfReader reader = null; PdfStamper stamper = null; try { // open files reader = new PdfReader(srcFile); stamper = new PdfStamper(reader, new FileOutputStream(destFile)); // add pagenum addPageNumber(reader, stamper, pageOffset); } catch (Exception ex) { // return Exception throw new Exception(ex); } finally { //close everything if (stamper != null) { stamper.close(); } if (reader != null) { reader.close(); } } }
From source file:de.mat.utils.pdftools.PdfExtractEmptyPages.java
License:Mozilla Public License
/** * <h4>FeatureDomain:</h4>//from w w w . j a v a 2 s. c om * PublishingTools * <h4>FeatureDescription:</h4> * reads pdfSourceFile and adds pages to pdfRemovedFile if empty, or to * pdfDestinationFile if not empty * <h4>FeatureResult:</h4> * <ul> * <li>updates pdfDestinationFile - add all pages which are not empty * <li>updates pdfRemovedFile - add all empty pages * </ul> * <h4>FeatureKeywords:</h4> * PDF Publishing * @param pdfSourceFile - source pdf-file * @param pdfDestinationFile - pdf with all not empty pages * @param pdfRemovedFile - pdf with all empty pages * @throws Exception */ public static void removeBlankPdfPages(String pdfSourceFile, String pdfDestinationFile, String pdfRemovedFile) throws Exception { // create readerOrig PdfReader readerOrig = new PdfReader(pdfSourceFile); // create writerTrimmed which bases on readerOrig Document documentTrimmed = new Document(readerOrig.getPageSizeWithRotation(1)); PdfCopy writerTrimmed = new PdfCopy(documentTrimmed, new FileOutputStream(pdfDestinationFile)); documentTrimmed.open(); // create writerRemoved which bases on readerOrig Document documentRemoved = new Document(readerOrig.getPageSizeWithRotation(1)); PdfCopy writerRemoved = new PdfCopy(documentRemoved, new FileOutputStream(pdfRemovedFile)); documentRemoved.open(); // extract and copy empty pages addTrimmedPages(pdfSourceFile, readerOrig, writerTrimmed, writerRemoved, true); // close everything documentTrimmed.close(); writerTrimmed.close(); documentRemoved.close(); writerRemoved.close(); readerOrig.close(); }
From source file:de.mat.utils.pdftools.PdfMerge.java
License:Mozilla Public License
/** * <h4>FeatureDomain:</h4>/* w w w . j a va 2 s . c o m*/ * PublishingTools * <h4>FeatureDescription:</h4> * merge pdfs from lstBookMarks to fileNew and trim empty pages if flgTrim * is set * <h4>FeatureResult:</h4> * <ul> * <li>create PDF - fileNew * <li>updates lstBookMarks - updates PAGE (firstPageNum) and * PAGES (countPage= per Bookmark * </ul> * <h4>FeatureKeywords:</h4> * PDF Publishing * @param lstBookMarks - list of Bookmark (files to merge) * @param fileNew - destination PDF filename * @param flgTrim - trim empty pages * @throws Exception */ public static void mergePdfs(List<Bookmark> lstBookMarks, String fileNew, boolean flgTrim) throws Exception { // FirstFile Map curBookMark = (Map) lstBookMarks.get(0); String curFileName = (String) curBookMark.get("SRC"); // Neues Dokument anlegen aus 1. Quelldokument anlegen PdfReader reader = new PdfReader(curFileName); Document documentNew = new Document(reader.getPageSizeWithRotation(1)); reader.close(); PdfCopy writerNew = new PdfCopy(documentNew, new FileOutputStream(fileNew)); documentNew.open(); int siteNr = 1; for (Iterator iter = lstBookMarks.iterator(); iter.hasNext();) { curBookMark = (Map) iter.next(); curFileName = (String) curBookMark.get("SRC"); if (LOGGER.isInfoEnabled()) LOGGER.info("add File:" + curFileName); // copy Page reader = new PdfReader(curFileName); int newPages = PdfExtractEmptyPages.addTrimmedPages(curFileName, reader, writerNew, (PdfCopy) null, flgTrim); reader.close(); // update BookMark curBookMark.put("PAGE", new Integer(siteNr)); curBookMark.put("PAGES", new Integer(newPages)); siteNr += newPages; } documentNew.close(); writerNew.close(); }