cancel
Showing results for 
Search instead for 
Did you mean: 

Create a pdf without showing it in the UI?

Former Member
0 Kudos

Hello!

I'm trying out Interactive Forms for Java for the first time, so please bear with me if this is obvious.

Is there a way to create a pdf and not display it in the ui? If I for example just want to download or email it.

I've tried setting visibility to None and Blank but that prevents the PDF from being generated at all.

It sort of works if I use FireFox and choose DisplayType activeX since FireFox can't display ActiveX. Our customer runs IE so that is not an option however.

Thank you for any input!

Kind regards,

Richard Linnander

Edited by: Richard Linnander on Jun 18, 2010 1:49 PM

Edited by: Richard Linnander on Jun 18, 2010 1:52 PM

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Richard,

You can create a pdf without displying it in UI.

Follow the below steps :

1. Copy your xdp file under mimes folder.

2. create a pdfsource context and DataSource node for pdf.

3. Create a File Download UI element in Ui and bind the data property with pdf source context.

4. Now copy the below code in wdDoInit() which is genrating the pdf from xdp.

wdContext.getNodeInfo().getAttribute("pdfSource").getModifiableSimpleType();

ByteArrayInputStream pdfInputStream = null;

String templateUrl = null;

try {

templateUrl = WDURLGenerator.getResourcePath(wdComponentAPI.getDeployableObjectPart(),"Name of XDP with extension");

} catch (WDAliasResolvingException e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

}

try {

IWDPDFDocumentHandler pdfDocumentHandler = WDPDFDocumentFactory.getDocumentHandler();

IWDPDFDocumentCreationContext pdfDocumentCreationContext = pdfDocumentHandler.getDocumentCreationContext();

pdfDocumentCreationContext.setData(WDInteractiveFormHelper.getContextDataAsStream(wdContext.nodeDataSource()));

pdfDocumentCreationContext.setTemplate(getByteArrayFromResourcePath(templateUrl));

//pdfDocumentCreationContext.setDynamic(true);

IWDPDFDocument pdfDocument = pdfDocumentCreationContext.execute();

pdfInputStream = (ByteArrayInputStream)pdfDocument.getPDFAsStream();

wdContext.currentContextElement().setPdfSource(pdfDocument.getPDF());

} catch (WDPDFDocumentRenderException e) {

wdComponentAPI.getMessageManager().reportException("An error occured: "+e.toString(), true);

}catch(Exception e){

wdComponentAPI.getMessageManager().reportException("An error occured: "+e.toString(),true);

}

5. create a another method in global section

private byte[] getByteArrayFromResourcePath(String resourcePath)

throws FileNotFoundException, IOException {

FileInputStream in = new FileInputStream(new File(resourcePath));

ByteArrayOutputStream out = new ByteArrayOutputStream();

int length;

byte[] part = new byte[10 * 1024];

while ((length = in.read(part)) != -1) {

out.write(part, 0, length);

}

in.close();

return out.toByteArray();

}

Former Member
0 Kudos

Thank you very much!

Answers (0)