Skip to Content
avatar image
Former Member

Sample project how to use Itext (pdf) in webdynpro

Hi all,

Have someone a sample how to use Itext in a webdynpro.


Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    avatar image
    Former Member
    Jan 09, 2007 at 10:32 AM

    Hi Bala,

    I want to create a look and feel and think it is easer to do this with Itext than with XML.


    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi Richard,

      In my WebDynpro Application I want to generate a PDF (using ITEXT API's) out of the data retrieved from back end system .

      I used this source code.

      Document document = new Document(PageSize.A4);;
      PdfPTable table = new PdfPTable(1);
      PdfPCell cell;
      cell = new PdfPCell(new Paragraph("ONE"));
      cell = new PdfPCell(new Paragraph("TWO")); 	
      byte[] b = new byte[100 * 1024];
      b =  document.toString().getBytes("UTF-8");
      IWDCachedWebResource pdfRes = WDWebResource.getPublicCachedWebResource(b, WDWebResourceType.PDF, WDScopeType.CLIENTSESSION_SCOPE, 	wdThis.wdGetAPI().getComponent().getDeployableObjectPart(),"FileNameHelloText"));

      I have used Window Manager to create a external window with the URL from pdfRes.getUrl() method.

      After execution i get a pop up window with out PDF document.

      Please let me know where i am making the mistake ?



  • Jan 09, 2007 at 09:56 AM

    Thanks to you :-D

    now i know iText!

    I used the FOP library, the idea is different but for how to use must be the same.

    With iText you can create physically the PDF on your server, after done it you can bind the binary file to a UIDownload element of a webdyndro, so the user can download it!

    Add comment
    10|10000 characters needed characters exceeded

    • Can use also UILinkToUrl element.

      	// Deserialize from a file
      	File file = new File("EquipmentFromFo.pdf");// from iText library
      	// Get some byte array data
      	pdfFile = getBytesFromFile(file);
      	//pdfFoXMLFile = this.toFoXML().getBytes("UTF-8");
      	// create a cached Web Dynpro XLS Resource for the given byte array and filename
      	cachedPdfResource = this.getCachedWebResource(pdfFile, fileName, WDWebResourceType.PDF);
      	// Store URL and filename of cached excel resource in context. 
      	if (cachedPdfResource != null) {
      	} else {
      	  ret = 1;

      where the method are:

         public static byte[] getBytesFromFile(File file) throws IOException {
      		   InputStream is = new FileInputStream(file);
      		   // Get the size of the file
      		   long length = file.length();
      		   // You cannot create an array using a long type.
      		   // It needs to be an int type.
      		   // Before converting to an int type, check
      		   // to ensure that file is not larger than Integer.MAX_VALUE.
      		   if (length > Integer.MAX_VALUE) {
      			   // File is too large
      		   // Create the byte array to hold the data
      		   byte[] bytes = new byte[(int)length];
      		   // Read in the bytes
      		   int offset = 0;
      		   int numRead = 0;
      		   while (offset < bytes.length
      				  && (, offset, bytes.length-offset)) >= 0) {
      			   offset += numRead;
      		   // Ensure all the bytes have been read in
      		   if (offset < bytes.length) {
      			   throw new IOException("Could not completely read file "+file.getName());
      		   // Close the input stream and return bytes
      		   return bytes;
         private IWDCachedWebResource getCachedWebResource(byte[] file, String name, WDWebResourceType type) {
      	 IWDCachedWebResource cachedWebResource = null;
      	 if (file != null) {
      	   cachedWebResource = WDWebResource.getWebResource(file, type);
      	 return cachedWebResource;

  • avatar image
    Former Member
    Jan 09, 2007 at 10:03 AM

    Hi Roberto,

    Thanks for your quick response. I want to show the PDF file in new window!. I looking for a sample that I can use. I'am not a die hard developer.


    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 09, 2007 at 10:07 AM


    You may refer <a href="/people/prakash.singh4/blog/2005/04/05/create-a-pdf-file-using-java a PDF file using JAVA</a> for the usage of the IText APIs.

    But, why do you want to use IText APIs? You can use the WD APIs for generating a PDF provided you have the data in the form of bytes. A pointer code will look like this.

        IWDResource wr = WDResourceFactory.createCachedResource(<i>YourByteArray/i], "PDF Report", WDWebResourceType.PDF);
        IWDWindow w = wdComponentAPI.getWindowManager().createNonModalExternalWindow(wr.getUrl(0), "PDF Report");;
    catch (Exception e)
        wdComponentAPI.getMessageManager().reportException(e.getLocalizedMessage(), false);


    Add comment
    10|10000 characters needed characters exceeded