List of usage examples for com.itextpdf.text.pdf PdfStamper getAcroFields
public AcroFields getAcroFields()
AcroFields
object that allows to get and set field values and to merge FDF forms. From source file:com.stee.emer.util.PdfGenerator.java
License:Open Source License
public static byte[] generate(Map<String, String> map) throws IOException, DocumentException { URL classPath = PdfGenerator.class.getClassLoader().getResource(""); PdfReader pdfReader = new PdfReader(classPath + "com/stee/emer/model/model.pdf"); ByteArrayOutputStream os = new ByteArrayOutputStream(); PdfStamper pdfStamper = new PdfStamper(pdfReader, os); AcroFields acroFields = pdfStamper.getAcroFields(); BaseFont baseFont = BaseFont.createFont(classPath + "MSYH.TTF", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); ArrayList<BaseFont> list = new ArrayList<BaseFont>(); list.add(baseFont);/* w w w.j av a 2 s . com*/ acroFields.setSubstitutionFonts(list); Iterator<Entry<String, String>> iterator = map.entrySet().iterator(); while (iterator.hasNext()) { Entry<String, String> next = iterator.next(); acroFields.setField(next.getKey(), next.getValue()); } pdfStamper.setFormFlattening(true); pdfStamper.close(); // File file = new File("e:/temp.pdf"); // FileOutputStream fileOutputStream = new FileOutputStream(file); // fileOutputStream.write(os.toByteArray()); // fileOutputStream.flush(); // fileOutputStream.close(); return os.toByteArray(); }
From source file:com.swisscom.ais.itext.PDF.java
License:Open Source License
/** * Add external revocation information to DSS Dictionary, to enable Long Term Validation (LTV) in Adobe Reader * //from w ww. j a va2 s .c o m * @param ocspArr List of OCSP Responses as base64 encoded String * @param crlArr List of CRLs as base64 encoded String * @throws Exception */ public void addValidationInformation(ArrayList<String> ocspArr, ArrayList<String> crlArr) throws Exception { if (ocspArr == null && crlArr == null) return; PdfReader reader = new PdfReader(outputFilePath); // Check if source pdf is not protected by a certification if (reader.getCertificationLevel() == PdfSignatureAppearance.CERTIFIED_NO_CHANGES_ALLOWED) throw new Exception( "Could not apply revocation information (LTV) to the DSS Dictionary. Document contains a certification that does not allow any changes."); Collection<byte[]> ocspColl = new ArrayList<byte[]>(); Collection<byte[]> crlColl = new ArrayList<byte[]>(); // Decode each OCSP Response (String of base64 encoded form) and add it to the Collection (byte[]) if (ocspArr != null) { for (String ocspBase64 : ocspArr) { OCSPResp ocspResp = new OCSPResp(new ByteArrayInputStream(Base64.decode(ocspBase64))); BasicOCSPResp basicResp = (BasicOCSPResp) ocspResp.getResponseObject(); if (Soap._debugMode) { System.out.println("\nEmbedding OCSP Response..."); System.out.println("Status : " + ((ocspResp.getStatus() == 0) ? "GOOD" : "BAD")); System.out.println("Produced at : " + basicResp.getProducedAt()); System.out.println("This Update : " + basicResp.getResponses()[0].getThisUpdate()); System.out.println("Next Update : " + basicResp.getResponses()[0].getNextUpdate()); System.out.println("X509 Cert Issuer : " + basicResp.getCerts()[0].getIssuer()); System.out.println("X509 Cert Subject : " + basicResp.getCerts()[0].getSubject()); System.out.println( "Responder ID X500Name : " + basicResp.getResponderId().toASN1Object().getName()); System.out.println("Certificate ID : " + basicResp.getResponses()[0].getCertID().getSerialNumber().toString() + " (" + basicResp.getResponses()[0].getCertID().getSerialNumber().toString(16).toUpperCase() + ")"); } ocspColl.add(basicResp.getEncoded()); // Add Basic OCSP Response to Collection (ASN.1 encoded representation of this object) } } // Decode each CRL (String of base64 encoded form) and add it to the Collection (byte[]) if (crlArr != null) { for (String crlBase64 : crlArr) { X509CRL x509crl = (X509CRL) CertificateFactory.getInstance("X.509") .generateCRL(new ByteArrayInputStream(Base64.decode(crlBase64))); if (Soap._debugMode) { System.out.println("\nEmbedding CRL..."); System.out.println("IssuerDN : " + x509crl.getIssuerDN()); System.out.println("This Update : " + x509crl.getThisUpdate()); System.out.println("Next Update : " + x509crl.getNextUpdate()); System.out.println( "No. of Revoked Certificates : " + ((x509crl.getRevokedCertificates() == null) ? "0" : x509crl.getRevokedCertificates().size())); } crlColl.add(x509crl.getEncoded()); // Add CRL to Collection (ASN.1 DER-encoded form of this CRL) } } byteArrayOutputStream = new ByteArrayOutputStream(); PdfStamper stamper = new PdfStamper(reader, byteArrayOutputStream, '\0', true); LtvVerification validation = stamper.getLtvVerification(); // Add the CRL/OCSP validation information to the DSS Dictionary boolean addVerification = false; for (String sigName : stamper.getAcroFields().getSignatureNames()) { addVerification = validation.addVerification(sigName, // Signature Name ocspColl, // OCSP crlColl, // CRL null // certs ); } validation.merge(); // Merges the validation with any validation already in the document or creates a new one. stamper.close(); reader.close(); // Save to (same) file OutputStream outputStream = new FileOutputStream(outputFilePath); byteArrayOutputStream.writeTo(outputStream); if (Soap._debugMode) { if (addVerification) System.out.println("\nOK merging LTV validation information to " + outputFilePath); else System.out.println("\nFAILED merging LTV validation information to " + outputFilePath); } byteArrayOutputStream.close(); outputStream.close(); }
From source file:com.test.itext.Renderer.java
private byte[] populateXFA(byte[] templateBytes, byte[] xfaDataBytes) throws RuntimeException { // Create an output stream for the rendered doc ByteArrayOutputStream rendered = new ByteArrayOutputStream(); try {//from w w w. ja va2 s. c om PdfReader reader = new PdfReader(templateBytes); PdfStamper stamper = new PdfStamper(reader, rendered); AcroFields form = stamper.getAcroFields(); XfaForm xfa = form.getXfa(); xfa.fillXfaForm(new ByteArrayInputStream(xfaDataBytes)); stamper.close(); reader.close(); } catch (IOException e) { String msg = "An IOException was thrown while trying to populate the XFA form. Msg=" + e.getMessage(); e.printStackTrace(); throw new RuntimeException(msg); } catch (DocumentException e) { String msg = "A DocumentException was thrown while trying to populate the XFA form. Msg=" + e.getMessage(); e.printStackTrace(); throw new RuntimeException(msg); } return rendered.toByteArray(); }
From source file:com.wabacus.system.assistant.PdfAssistant.java
License:Open Source License
private ByteArrayOutputStream showReportOneRowDataOnPdf(ReportRequest rrequest, Map<String, AbsReportType> mReportTypeObjs, IComponentConfigBean ccbean, PDFExportBean pdfbean, int rowidx) throws Exception { PdfReader pdfTplReader = null;//ww w . j a v a 2s .co m InputStream istream = null; ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { istream = WabacusAssistant.getInstance().readFile(pdfbean.getPdftemplate()); if (istream == null) return null; pdfTplReader = new PdfReader(new BufferedInputStream(istream)); PdfStamper stamp = new PdfStamper(pdfTplReader, baos); /* ?? */ AcroFields form = stamp.getAcroFields(); form.addSubstitutionFont(bfChinese); boolean flag = true; if (pdfbean != null && pdfbean.getInterceptorObj() != null) { flag = pdfbean.getInterceptorObj().beforeDisplayPdfPageWithTemplate(ccbean, mReportTypeObjs, rowidx, stamp); } if (flag) { Map<String, Item> mFields = form.getFields(); if (mFields != null) { String fieldValueTmp = null; for (String fieldNameTmp : mFields.keySet()) { fieldValueTmp = getPdfFieldValueByName(rrequest, mReportTypeObjs, ccbean, fieldNameTmp, rowidx);//? if (pdfbean != null && pdfbean.getInterceptorObj() != null) { fieldValueTmp = pdfbean.getInterceptorObj().beforeDisplayFieldWithTemplate(ccbean, mReportTypeObjs, rowidx, stamp, fieldNameTmp, fieldValueTmp); } if (fieldValueTmp != null) form.setField(fieldNameTmp, fieldValueTmp); } } } if (pdfbean != null && pdfbean.getInterceptorObj() != null) { pdfbean.getInterceptorObj().afterDisplayPdfPageWithTemplate(ccbean, mReportTypeObjs, rowidx, stamp); } stamp.setFormFlattening(true); stamp.close(); } finally { try { if (istream != null) istream.close(); } catch (IOException e) { e.printStackTrace(); } if (pdfTplReader != null) pdfTplReader.close(); } return baos; }
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 ); //}//from ww w . j a va 2 s . co m // +++ ~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 ); //}/*w ww. ja v a2 s . c om*/ // +++ ~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.ja va 2 s .c om*/ 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 w ww.j a v a 2 s . com*/ 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:ExternalForms.Browser.java
public String getDataFromPDF() { String all_inputs = ""; //concatenated string of inputs in order try {/* w w w.ja va2 s . com*/ final int MAX_VARIABLES = connect.getFormVarCount(formID); //get from db System.out.println("MAX VARIABLES: " + MAX_VARIABLES); //---------------------------------------------------------- final String DELIMITER = "~"; //pwede mani i-change dumbNavigate(); PdfReader pdfTemplate = new PdfReader(documentsPath + "\\" + formName + ".pdf"); FileOutputStream fileOutputStream = new FileOutputStream( dirPrintables.getAbsolutePath() + "\\" + formName + ".pdf"); PdfStamper stamper = new PdfStamper(pdfTemplate, fileOutputStream); //System.out.println("TRY: " + stamper.getAcroFields().getField("1")); stamper.setFormFlattening(true); System.out.println("Display Inputs Per Variable and Concatenate after\n"); //change textFields-------------------------------------------------------------------- for (int var = 1; var <= MAX_VARIABLES; var++) { String input_from_pdf_field = stamper.getAcroFields().getField("" + var); //get field input using variable System.out.println("Input #" + var + " = " + input_from_pdf_field); //display all_inputs += DELIMITER + input_from_pdf_field; //concatenate } stamper.close(); pdfTemplate.close(); //-------------------------------------------------------------------------------------- System.out.println("\nConcatenated String to Store to DB\n"); System.out.println("\n" + all_inputs + "\n"); try { File pdfFile = new File(documentsPath + "\\" + formName + ".pdf"); if (pdfFile.exists()) { if (pdfFile.delete()) { //Desktop.getDesktop().open(pdfFile); System.out.println("Form in Documents Deleted"); } } else { System.out.println("File to delete in My Documents does not exists!"); } } catch (Exception ex) { } b.setVisible(false); c.setText("Done"); j.navigate(dirPrintables.getAbsolutePath() + "\\" + formName + ".pdf"); System.out.println(dirPrintables.getAbsolutePath() + "\\" + formName + ".pdf"); } catch (IOException | DocumentException ex) { Logger.getLogger(Browser.class.getName()).log(Level.SEVERE, null, ex); } return all_inputs; }
From source file:ExternalForms.Browser.java
public void setDataToPdf(String fName, String formEntryID) { try {//from w w w . j av a 2s .c om String all_inputs = connect.getFormEntryFormData(formEntryID); //assuming na gusto ka magbutang ug tulo ka value sa first 3 fields final String DELIMITER = "~"; System.out.println("\nSplit Concatenated String and Display\n"); String split_inputs[] = all_inputs.split(DELIMITER); PdfReader pdfTemplate = new PdfReader( dirTemplates.getAbsolutePath() + "\\" + (formName = fName) + ".pdf"); //navigate("temp", "x"); postFix = checkIfSameNameFileExists(this.dirPrintables, formName + ".pdf"); System.out.println("FILENAME TO FETCH: " + formName + postFix + "|"); FileOutputStream fileOutputStream = new FileOutputStream( dirPrintables.getAbsolutePath() + "\\" + formName + postFix + ".pdf"); PdfStamper stamper = new PdfStamper(pdfTemplate, fileOutputStream); stamper.setFormFlattening(true); //change textFields-------------------------------------------------------------------- for (int var = 1; var < split_inputs.length; var++) { stamper.getAcroFields().setField("" + var, split_inputs[var]); //get field input using variable System.out.println("Input #" + var + " = " + split_inputs[var]); //display } //-------------------------------------------------------------------------------------- stamper.close(); pdfTemplate.close(); b.setVisible(false); c.setText("Done"); j.navigate(dirPrintables.getAbsolutePath() + "\\" + formName + postFix + ".pdf"); this.setVisible(true); System.out.println(dirPrintables.getAbsolutePath() + "\\" + formName + postFix + ".pdf"); } catch (IOException | DocumentException ex) { Logger.getLogger(Browser.class.getName()).log(Level.SEVERE, null, ex); } }