« Return to Thread: Check Box in iText PDF is not printing

Check Box in iText PDF is not printing

by apaul :: Rate this Message:

Reply to Author | View in Thread

Hello
        I have created a PDF using iText API and the PDF was basically a Application form which contains Text as well as check boxes.I was able to create it properly as I can see the soft copy for that; the problem when I tried to print it. In the printed page, I can see only the text lines and the check boxes are missing and only blan white space in stead of the check boxes. After that I took the basic code to create the PDF form iText site, and it is creating the only a check boxes in the PDF and whn I tried to print that, that also not getting printed. I am giving the the basic code for that; it creats the sample PDF which contains the check box but will not print the check box in the printer ;could you please help me fixing the problem.


import java.io.FileOutputStream;
import java.io.IOException;

import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.PageSize;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.PdfAnnotation;
import com.lowagie.text.pdf.PdfAppearance;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfFormField;
import com.lowagie.text.pdf.PdfWriter;

/**
 * Generates an Acroform with a Checkbox
 * @author blowagie
 */
public class FormCheckbox {
    /**
     * Generates an Acroform with a Checkbox
     * @param args no arguments needed here
     */
    public static void main(String[] args) {
       
        System.out.println("Checkbox");
       
        // step 1: creation of a document-object
        Document document = new Document(PageSize.A4);
       
        try {
           
            // step 2:
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("checkbox.pdf"));
           
            // step 3: we open the document
            document.open();
           
            // step 4:
            PdfContentByte cb = writer.getDirectContent();
            cb.moveTo(0, 0);
            PdfFormField field = PdfFormField.createCheckBox(writer);
            PdfAppearance tpOff = cb.createAppearance(20, 20);
            PdfAppearance tpOn = cb.createAppearance(20, 20);
            tpOff.rectangle(1, 1, 18, 18);
            tpOff.stroke();
           
            tpOn.setRGBColorFill(255, 128, 128);
            tpOn.rectangle(1, 1, 18, 18);
            tpOn.fillStroke();
            tpOn.moveTo(1, 1);
            tpOn.lineTo(19, 19);
            tpOn.moveTo(1, 19);
            tpOn.lineTo(19, 1);
            tpOn.stroke();
           
            field.setWidget(new Rectangle(100, 700, 120, 720), PdfAnnotation.HIGHLIGHT_INVERT);
            field.setFieldName("Urgent");
            field.setValueAsName("Off");
            field.setAppearanceState("Off");
            field.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Off", tpOff);
            field.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, "On", tpOn);
            writer.addAnnotation(field);
           
        }
        catch(DocumentException de) {
            System.err.println(de.getMessage());
        }
        catch(IOException ioe) {
            System.err.println(ioe.getMessage());
        }
       
        // step 5: we close the document
        document.close();
    }
}

--
Thanx & Regards,
Amitava Paul
901 361 8080

------------------------------------------------------------------------------

_______________________________________________
iText-questions mailing list
iText-questions@...
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php
Check the site with examples before you ask questions: http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/

 « Return to Thread: Check Box in iText PDF is not printing