Example usage for com.itextpdf.text Image getInstance

List of usage examples for com.itextpdf.text Image getInstance

Introduction

In this page you can find the example usage for com.itextpdf.text Image getInstance.

Prototype

public static Image getInstance(final Image image) 

Source Link

Document

gets an instance of an Image

Usage

From source file:de.earthdawn.ECEPdfExporter.java

License:Open Source License

public void exportAjfelMordom(EDCHARACTER edCharakter, int pdftype, File outFile)
        throws DocumentException, IOException {
    File pdfinputfile;//w  w w .ja v a  2 s .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.extra.xtt.util.pdf.PdfCreatorImpl.java

License:Apache License

/**
 * Diese Methode erzeugt die Titelseite fr das PDF-Dokument mit der
 * Bezeichnung des Verfahrens.//from   w  w  w. j  a v a 2s  .  c o m
 * 
 * @param bezVerfahren
 *            Bezeichnung des profilierten Verfahrens
 * @throws DocumentException
 * @throws MalformedURLException
 * @throws IOException
 */
private void erzeugeTitelSeite() throws DocumentException, MalformedURLException, IOException {
    // Symbol, falls vorhanden
    String pathImage = "./logo_doku.png";
    try {
        // Image image =
        // Image.getInstance(PdfCreatorImpl.class.getResource(pathImage));
        Image image = Image.getInstance(pathImage);
        image.setAlignment(Element.ALIGN_RIGHT);
        docPdf.add(image);
    } catch (Exception e) {
        if (logger.isDebugEnabled()) {
            logger.debug("Fehler beim Einbinden der Grafik '" + pathImage + "'.", e);
        }
    }
    docPdf.add(getEmptyLineText());

    // Restliche Texte werden im Event-Handler geschrieben

    // Seitenumbruch
    docPdf.newPage();
}

From source file:de.jost_net.JVerein.io.Reporter.java

License:Open Source License

public void addColumn(byte[] image, int width, int height, int horizontalalignment)
        throws BadElementException, MalformedURLException, IOException {
    Image i = Image.getInstance(image);
    float w = i.getWidth() / width;
    float h = i.getHeight() / height;
    if (w > h) {
        h = i.getHeight() / w;/*w ww  .  j  a  v a2  s .co m*/
        w = width;
    } else {
        w = i.getHeight() / h;
        h = height;
    }
    i.scaleToFit(w, h);
    PdfPCell cell = new PdfPCell(i, false);
    cell.setPadding(3);
    cell.setHorizontalAlignment(horizontalalignment);
    table.addCell(cell);
}

From source file:de.knurt.heinzelmann.util.itext.ImageFactoryDefault.java

License:Creative Commons License

/**
 * scale image using {@link ResizeMode}/* w w  w. j a v a 2s  . 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.rub.dez6a3.jpdfsigner.control.ITextSigner.java

License:Open Source License

public ByteArrayOutputStream doSign(byte[] pdf, Rectangle stampPos, int pageNmbrForStamp) throws IOException,
        DocumentException, NoSuchAlgorithmException, InvalidKeyException, SignatureException {
    Certificate[] chain = signCert.toArray(new Certificate[0]);

    PdfReader reader = new PdfReader(pdf);
    ByteArrayOutputStream byteOS = new ByteArrayOutputStream();
    PdfStamper stp = PdfStamper.createSignature(reader, byteOS, '\0', null, true);
    PdfSignatureAppearance sap = stp.getSignatureAppearance();
    if (stampPos != null) {
        sap.setVisibleSignature(//from   www.j a v a  2  s  .  com
                new com.itextpdf.text.Rectangle(stampPos.x, stampPos.y, stampPos.width, stampPos.height),
                pageNmbrForStamp, null);
        sap.setRenderingMode(PdfSignatureAppearance.RenderingMode.NAME_AND_DESCRIPTION);
        sap.setAcro6Layers(true);
    }
    //        Siganture Appearance

    PdfSignature dic = new PdfSignature(PdfName.ADOBE_PPKLITE, new PdfName("adbe.pkcs7.detached"));
    log.info("Creating signature with reason: " + ParamValidator.getInstance().getSignatureReason());
    sap.setReason(ParamValidator.getInstance().getSignatureReason());
    sap.setLocation("Ruhr-Universitt Bochum");
    Image i = Image.getInstance(getClass().getResource("/de/rub/dez6a3/jpdfsigner/resources/images/sign.png"));
    sap.setImage(i);
    sap.setCrypto((PrivateKey) signPrivKey, chain, null, PdfSignatureAppearance.WINCER_SIGNED);
    dic.setReason(ParamValidator.getInstance().getSignatureReason());
    dic.setLocation("Ruhr-Universitt Bochum");
    sap.setCryptoDictionary(dic);
    // preserve some space for the contents
    int contentEstimated = 15000;
    HashMap<PdfName, Integer> exc = new HashMap<PdfName, Integer>();
    exc.put(PdfName.CONTENTS, new Integer(contentEstimated * 2 + 2));
    sap.preClose(exc);
    // make the digest
    InputStream data = sap.getRangeStream();
    MessageDigest messageDigest = MessageDigest.getInstance("SHA1");
    byte buf[] = new byte[8192];
    int n;
    while ((n = data.read(buf)) > 0) {
        messageDigest.update(buf, 0, n);
    }
    byte hash[] = messageDigest.digest();
    Calendar cal = Calendar.getInstance();
    // If we add a time stamp:
    TSAClient tsc = new TSAClientBouncyCastle("http://zeitstempel.dfn.de/");
    // Create the signature

    PdfPKCS7 sgn;
    try {
        sgn = new PdfPKCS7((PrivateKey) signPrivKey, chain, null, "SHA1", null, false);
        byte sh[] = sgn.getAuthenticatedAttributeBytes(hash, cal, null);
        sgn.update(sh, 0, sh.length);
        byte[] encodedSig = sgn.getEncodedPKCS7(hash, cal, tsc, null);

        if (contentEstimated + 2 < encodedSig.length) {
            throw new DocumentException("Not enough space");
        }

        byte[] paddedSig = new byte[contentEstimated];
        System.arraycopy(encodedSig, 0, paddedSig, 0, encodedSig.length);
        // Replace the contents
        PdfDictionary dic2 = new PdfDictionary();
        dic2.put(PdfName.CONTENTS, new PdfString(paddedSig).setHexWriting(true));
        sap.close(dic2);
    } catch (NoSuchProviderException ex) {
        ex.printStackTrace();
    }
    return byteOS;
}

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);/*from   w  w w  . j ava2 s  .co  m*/

    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);/* w ww .java  2 s  .  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);//from w  ww.  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  w  w  . ja  v  a  2 s.  co  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);//from ww w.  ja v  a  2 s .  co  m
    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;
}