views:

2056

answers:

6

I'm using iText to dynamically generate PDF docs. Now I'm trying to dynamically create a barcode in this PDF. Adobe Live Cycle has a barcode function built-in. You can just drag the barcode text box on the page and it's created.

Problem:
I placed the barcode field in the PDF. Then pass a number to the barcode field from the JSP page. But only the number appears. The barcode lines never display

The number, 20099002, is visible on the PDF doc, but the barcode lines fail to appear. I tried several other barcode options in LiveCycle but the all give the same result.

    OurJavaPage.java 
    public class ExampleForm extends BaseOutput { 
    private static final Log LOG = LogFactory.getLog(ExampleForm.class); 
    public OutputStream generate() throws IOException, DocumentException { 
        ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
        PdfReader reader; 
        reader = new PdfReader(BASEDIR + "MailingExample.pdf"); 

        PdfStamper stamper = new PdfStamper(reader, baos); 
        Participant participantHome = home.getParticipant(); 
        Set<Location> homeLocs = participantHome.getLocations(); 

        final AcroFields form = stamper.getAcroFields(); 

        setFormField(form, "addrNumber[0]", addrMaster.getStreetNum()); 
        setFormField(form, "dateMiddle[0]", formatDate("MM-dd-yyyy", new Date())); 

// *********** Here's the problem *****************************
        setFormField(form, "Code128ABarcode1[0]", "20099002");
// ************************************************************

        debugAcrobatForm("ExampleForm", form); 
        stamper.setFormFlattening(true); 
        stamper.close(); 

        return baos; 
    } 
}

Operating System: Linux
Programming: Java, .jsp, iText
Software: Adobe Live Cycle Designer ES 8.1

+1  A: 

Does your software embed the barcode as a graphic or as a font representation of characters?

If the latter, is it embedding the font into the PDF?

Michael Trausch
A: 

Did you ask on the very active IText mailing list?

+3  A: 

Problem solved!!!

I contacted iText and they suggested that I change this line.

From: stamper.setFormFlattening(true);
To: stamper.setFormFlattening(false);

It worked.

A: 

If this was a dynamic XFA form created with LiveCycle, then using form flattening will cause you to lose your form fields. Static XFA forms should work though.

Reference: http://itext.ugent.be/library/question.php?id=30

XFA support in iText is improving but spotty at best.

JonMR
A: 

u have to add barcode font in ur system (font library), then it will be visible in ur font drop-down. Use acro-field (text) and set that font in this acro-field. Ur problem will be solved. also, use setformflattening=true as it will make pdf uneditable

A: 

it works just fine for me.. maybe its got to do with the way you make the template in livecycle designer (static or dynamic)...

see sample here http://1t3xt.info/examples/browse/?page=example&amp;id=433

Regards Raghavendra Samant