cancel
Showing results for 
Search instead for 
Did you mean: 

Set pdf Meta-data from java class

Former Member
0 Kudos

Hi All,

Is there any way to call ADS methods to create pdf and set meta data from a java class in NWDS?

Thanks & Regards,

Sanoosh

Accepted Solutions (1)

Accepted Solutions (1)

OttoGold
Active Contributor
0 Kudos

I believe Java WD is what you´re looking for. I can set meta data in ABAP coding and I believe the same think you should be able to do from Java. Otto

Former Member
0 Kudos

Hi Otto,

Thanks for your response. I am not using Wd Java. It is a Core Java class.

My intension is to use adobe forms in ecc 4.7. For that I will be passing xstring data from ABAP to Java through RFC.

In Java side I have a listener class. It will receive the data in byte-array format.

Now I have to call ADS for pdf creation and meta data setting.

It can be done using iText API but I feel it would be better if the ADS call can be done from the Java class.

Thanks & Regards

Sanoosh

OttoGold
Active Contributor
0 Kudos

I don´t know how to use ADS in this scenario and would use iText myself. Otto

p.s.: but would be cool to understand how to do this using ADS

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

I've got only a method to generate the PDF using an interactive form (note: this code works with the version 7.0.21).

You can then use the byte array to concatenate several form using a library like iText or do some other process.


  public byte[] generatePDF( )
  {
    //@@begin generatePDF()
	byte[] res = null;
	try {
		String templateName = "yourInteractiveForm.xdp";
		IWDPDFDocumentHandler documentHandler = WDPDFDocumentFactory.getDocumentHandler();
		IWDPDFDocumentCreationContext creationContext = documentHandler.getDocumentCreationContext();
		creationContext.setDynamic(false);
		creationContext.setInteractive(false);
 
		ByteArrayOutputStream templateSourceOutputStream = new ByteArrayOutputStream();
		// get template file as InputStream
		String filePath = WDURLGenerator.getPublicResourcePath(wdComponentAPI.getDeployableObjectPart(), templateName);
		InputStream templateSourceInputStream = new FileInputStream(new File(filePath));
		// convert InputStream to OutputStream
		IOUtil.write(templateSourceInputStream,	templateSourceOutputStream);
		templateSourceInputStream.close();
	  
		creationContext.setTemplate(templateSourceOutputStream);
		ByteArrayOutputStream dataStream = com.sap.tc.webdynpro.clientserver.adobe.api.WDInteractiveFormHelper.getContextDataAsStream(wdContext.nodePDFdata());			

		creationContext.setData(dataStream);
		IWDPDFDocument pdfDocument = creationContext.execute();
		res = pdfDocument.getPDF();
	} catch (WDPDFDocumentRenderException e) {
		wdComponentAPI.getMessageManager().reportWarning(wdContext.currentLabelElement().getMsgErrorRenderingPDF() + ": WDPDFDocumentRenderException - " + e.getLocalizedMessage());
	} catch (FileNotFoundException e) {
		wdComponentAPI.getMessageManager().reportWarning(wdContext.currentLabelElement().getMsgErrorRenderingPDF() + ": FileNotFoundException - " + e.getLocalizedMessage());
	} catch (IOException e) {
		wdComponentAPI.getMessageManager().reportWarning(wdContext.currentLabelElement().getMsgErrorRenderingPDF() + ": IOException - " + e.getLocalizedMessage());
	} catch (PDFObjectRuntimeException e){
		wdComponentAPI.getMessageManager().reportWarning(wdContext.currentLabelElement().getMsgErrorRenderingPDF() + ": PDFObjectRuntimeException - " + e.getLocalizedMessage());
	} finally {
		return res;	
	}
    //@@end
  }

When the ADS server is not well configured or else, you've got the WDPDFDocumentRenderException.