Package com.lowagie.examples.forms.create

Source Code of com.lowagie.examples.forms.create.StudentCard

/*
* $Id$
*
* This code is part of the 'iText Tutorial'.
* You can find the complete tutorial at the following address:
* http://itextdocs.lowagie.com/tutorial/
*
* This code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* itext-questions@lists.sourceforge.net
*/

package com.lowagie.examples.forms.create;


import java.awt.Color;
import java.io.FileOutputStream;
import java.io.IOException;

import com.lowagie.text.LwgDocument;
import com.lowagie.text.DocumentException;
import com.lowagie.text.LwgElement;
import com.lowagie.text.LwgFont;
import com.lowagie.text.FontFactory;
import com.lowagie.text.LwgImage;
import com.lowagie.text.Paragraph;
import com.lowagie.text.LwgRectangle;
import com.lowagie.text.pdf.Barcode;
import com.lowagie.text.pdf.BarcodeEAN;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.LwgPdfPTable;
import com.lowagie.text.pdf.PdfWriter;

/**
* Generates a StudentCard
* @author blowagie
*/
public class StudentCard {
    /**
     * Generates a StudentCard
     * @param args no arguments needed here
     */
    public static void main(String[] args) {
       
        System.out.println("StudentCard");
       
        // step 1: creation of a document-object
        LwgRectangle rect = new LwgRectangle(243, 153);
        rect.setBackgroundColor(new Color(0xFF, 0xFF, 0xCC));
        LwgDocument document = new LwgDocument(rect, 10, 10, 10, 10);
       
        try {
           
            // step 2:
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("studentcard.pdf"));
           
            // step 3: we open the document
            document.open();
           
            // step 4:
            LwgFont font = FontFactory.getFont(FontFactory.HELVETICA, 14, LwgFont.BOLD, Color.BLUE);
            Paragraph p = new Paragraph("Ghent University", font);
            p.setAlignment(LwgElement.ALIGN_CENTER);
            document.add(p);
            PdfContentByte cb = writer.getDirectContent();
            LwgFont f = FontFactory.getFont(FontFactory.HELVETICA, 8);
            LwgPdfPTable outertable = new LwgPdfPTable(3);
            outertable.setTotalWidth(200);
            outertable.getDefaultCell().setBorder(LwgRectangle.NO_BORDER);
            float[] outer = { 60, 25, 15 };
            outertable.setWidths(outer);
            LwgPdfPTable innertable = new LwgPdfPTable(2);
            float[] inner = {35, 65};
            innertable.setWidths(inner);
            innertable.add(new Paragraph("name:", f));
            innertable.add(new Paragraph("Bruno Lowagie", f));
            innertable.add(new Paragraph("date of birth:", f));
            innertable.add(new Paragraph("June 10th, 1970", f));
            innertable.add(new Paragraph("Study Program:", f));
            innertable.add(new Paragraph("master in civil engineering", f));
            innertable.add(new Paragraph("option:", f));
            innertable.add(new Paragraph("architecture", f));
            outertable.add(innertable);
      outertable.getDefaultCell().setBackgroundColor(new Color(0xFF, 0xDE, 0xAD));
      outertable.add(LwgImage.getInstance("bruno.jpg"));
            BarcodeEAN codeEAN = new BarcodeEAN();
            codeEAN.setCodeType(Barcode.EAN13);
            codeEAN.setCode("8010012529736");
      LwgImage imageEAN = codeEAN.createImageWithBarcode(cb, null, null);           
      imageEAN.setRotationDegrees(90);
      outertable.getDefaultCell().setBackgroundColor(Color.WHITE);
      outertable.add(imageEAN);
            outertable.writeSelectedRows(0, -1, 20, 100, writer.getDirectContent());
        }
        catch(DocumentException de) {
            System.err.println(de.getMessage());
        }
        catch(IOException ioe) {
            System.err.println(ioe.getMessage());
        }
       
        // step 5: we close the document
        document.close();
    }
}
TOP

Related Classes of com.lowagie.examples.forms.create.StudentCard

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.