Example usage for com.lowagie.text PageSize POSTCARD

List of usage examples for com.lowagie.text PageSize POSTCARD

Introduction

In this page you can find the example usage for com.lowagie.text PageSize POSTCARD.

Prototype

Rectangle POSTCARD

To view the source code for com.lowagie.text PageSize POSTCARD.

Click Source Link

Document

This is the postcard format

Usage

From source file:questions.images.OverlappingImages.java

public static void main(String[] args) {
    // step 1: creation of a document-object
    Document document = new Document(PageSize.POSTCARD);
    try {//from www . jav a2 s  .com
        // step 2:
        // we create a writer
        PdfWriter.getInstance(
                // that listens to the document
                document,
                // and directs a PDF-stream to a file
                new FileOutputStream(RESULT));
        // step 3: we open the document
        document.open();
        // step 4: we add a paragraph to the document
        Image img1 = Image.getInstance(RESOURCE1);
        img1.scaleToFit(PageSize.POSTCARD.getWidth(), 10000);
        img1.setAbsolutePosition(0, 0);
        document.add(img1);
        Image img2 = Image.getInstance(RESOURCE2);
        img2.setTransparency(new int[] { 0x00, 0x10 });
        img2.setAbsolutePosition(PageSize.POSTCARD.getWidth() - img2.getScaledWidth(),
                PageSize.POSTCARD.getHeight() - img2.getScaledHeight());
        document.add(img2);
        Image img3 = Image.getInstance(RESOURCE3);
        img3.setTransparency(new int[] { 0xF0, 0xFF });
        img3.setAbsolutePosition((PageSize.POSTCARD.getWidth() - img3.getScaledWidth()) / 2,
                (PageSize.POSTCARD.getHeight() - img3.getScaledHeight()) / 2);
        document.add(img3);
    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    }

    // step 5: we close the document
    document.close();

}

From source file:questions.images.PostCard.java

public static void main(String[] args) {
    // step 1: creation of a document-object
    Document document = new Document(PageSize.POSTCARD);
    try {//from w  ww.  j  a  va  2s.  c  o  m
        // step 2:
        // we create a writer
        PdfWriter.getInstance(
                // that listens to the document
                document,
                // and directs a PDF-stream to a file
                new FileOutputStream(RESULT));
        // step 3: we open the document
        document.open();
        // step 4: we add a paragraph to the document
        Image img = Image.getInstance(RESOURCE);
        img.scaleToFit(PageSize.POSTCARD.getWidth(), 10000);
        img.setAbsolutePosition(0, 0);
        document.add(img);
    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    }

    // step 5: we close the document
    document.close();
}

From source file:questions.images.PostCardExtra.java

public static void main(String[] args) {
    // step 1: creation of a document-object
    Document document = new Document(PageSize.POSTCARD);
    try {//from  w  w w . jav  a2 s  . c  o m
        // step 2:
        // we create a writer
        PdfWriter writer = PdfWriter.getInstance(
                // that listens to the document
                document,
                // and directs a PDF-stream to a file
                new FileOutputStream(RESULT));
        // step 3: we open the document
        document.open();
        // step 4: we add a paragraph to the document
        Image img = Image.getInstance(RESOURCE);
        img.scaleToFit(PageSize.POSTCARD.getWidth(), 10000);
        img.setAbsolutePosition(0, 0);
        PdfImage stream = new PdfImage(img, "", null);
        stream.put(new PdfName("MySpecialId"), new PdfName("123456789"));
        PdfIndirectObject ref = writer.addToBody(stream);
        img.setDirectReference(ref.getIndirectReference());
        document.add(img);
    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    }

    // step 5: we close the document
    document.close();
}

From source file:questions.images.TransparentEllipse1.java

public static void main(String[] args) {
    Document document = new Document(PageSize.POSTCARD);
    try {//w  ww. j a  va2 s  . com
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT));
        document.open();
        Image img = Image.getInstance(RESOURCE);
        byte[] bytes = new byte[2500];
        int byteCount = 0;
        int bitCount = 6;
        for (int x = -50; x < 50; x++) {
            for (int y = -50; y < 50; y++) {
                double rSquare = Math.pow(x, 2) + Math.pow(y, 2);
                if (rSquare <= 1600) { // 40
                    bytes[byteCount] += (3 << bitCount);
                } else if (rSquare <= 2025) { // 45
                    bytes[byteCount] += (2 << bitCount);
                } else if (rSquare <= 2500) { // 50
                    bytes[byteCount] += (1 << bitCount);
                }
                bitCount -= 2;
                if (bitCount < 0) {
                    bitCount = 6;
                    byteCount++;
                }
            }
        }
        Image smask = Image.getInstance(100, 100, 1, 2, bytes);
        smask.makeMask();
        img.setImageMask(smask);
        img.setAbsolutePosition(0, 0);
        img.scaleToFit(PageSize.POSTCARD.getWidth(), PageSize.POSTCARD.getHeight());
        writer.getDirectContent().addImage(img);
    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    }
    document.close();
}

From source file:questions.images.TransparentEllipse2.java

public static void main(String[] args) {

    Document document = new Document(PageSize.POSTCARD);
    try {// ww  w .j ava2  s . c  o m
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT));
        document.open();
        PdfContentByte cb = writer.getDirectContent();

        // clipped image
        cb.ellipse(1, 1, PageSize.POSTCARD.getWidth() - 2, PageSize.POSTCARD.getHeight() - 2);
        cb.clip();
        cb.newPath();
        Image img = Image.getInstance(RESOURCE);
        img.scaleToFit(PageSize.POSTCARD.getWidth(), PageSize.POSTCARD.getHeight());
        cb.addImage(img, PageSize.POSTCARD.getWidth(), 0, 0, PageSize.POSTCARD.getHeight(), 0, 0);

        //Prepare gradation list
        int gradationStep = 40;
        float[] gradationRatioList = new float[gradationStep];
        for (int i = 0; i < gradationStep; i++) {
            gradationRatioList[i] = 1 - (float) Math.sin(Math.toRadians(90.0f / gradationStep * (i + 1)));
        }

        //Create template
        PdfTemplate template = cb.createTemplate(PageSize.POSTCARD.getWidth(), PageSize.POSTCARD.getHeight());

        //Prepare transparent group
        PdfTransparencyGroup transGroup = new PdfTransparencyGroup();
        transGroup.put(PdfName.CS, PdfName.DEVICEGRAY);
        transGroup.setIsolated(true);
        transGroup.setKnockout(false);
        template.setGroup(transGroup);

        //Prepare graphic state
        PdfGState gState = new PdfGState();
        PdfDictionary maskDict = new PdfDictionary();
        maskDict.put(PdfName.TYPE, PdfName.MASK);
        maskDict.put(PdfName.S, new PdfName("Luminosity"));
        maskDict.put(new PdfName("G"), template.getIndirectReference());
        gState.put(PdfName.SMASK, maskDict);
        cb.setGState(gState);

        //Create gradation for mask
        for (int i = 1; i < gradationStep + 1; i++) {
            template.setLineWidth(gradationStep + 1 - i);
            template.setGrayStroke(gradationRatioList[gradationStep - i]);
            template.ellipse(0, 0, PageSize.POSTCARD.getWidth(), PageSize.POSTCARD.getHeight());
            template.stroke();
        }

        //Place template
        cb.addTemplate(template, 0, 0);
    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    }

    document.close();
}