Skip to Content
author's profile photo Former Member
Former Member

Thumbnail preview of .pdf and .psd files are not getting

Hi Gurus,

I am facing a pblm in KM portal, were thumbnail previews for

.pdf and .psd files are not getting. But its working fine with jpg files. Can any one give me the exact steps to get the thumbnail previews.

With regards

Vipin

Add a comment
10|10000 characters needed characters exceeded

Related questions

6 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on May 26, 2008 at 07:58 AM

    Hi,

    Thanks for u r replay. Please forword that par file.

    My ids vipin.paul at ril dot com

    waiting for u r replay

    Regards

    Vipin

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Apr 07, 2008 at 02:16 PM

    Hi,

    Currently SAP delivers a thumbnail generator plugin only for JPG and GIF. If you want to use thumbnails for other file formats, you have to implement your own plug-ins.

    See this: [http://help.sap.com/saphelp_nw04s/helpdata/en/6b/2e47403c3d1059e10000000a155106/frameset.htm]

    Best regards,

    Avishai Zamir

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi,

      The class is in km.appl.repository.manager.thumbnail_core.jar which is under \usr\sap\J2E\JCXX\j2ee\cluster\server0\apps\sap.com\irj\servlet_jsp\irj\root\WEB-INF\portal\portalapps\com.sap.km.cm.repository.manager\private\lib.

      I would not recomend on changing the default class. what you should do is add a plugin that handles PDFs.

      I cooked up an example for you. It's pretty slow and not thoroughly checked but I tested it and it works:

      package com.sapportals.wcm.repository.manager.thumbnail; 
      
      import java.awt.Color; 
      import java.awt.Graphics2D; 
      import java.awt.RenderingHints; 
      import java.awt.image.BufferedImage; 
      import java.io.ByteArrayInputStream; 
      import java.io.ByteArrayOutputStream; 
      import java.io.InputStream; 
      
      import org.jpedal.PdfDecoder; 
      import org.jpedal.objects.PdfFileInformation; 
      
      import com.sap.tc.logging.Location; 
      import com.sapportals.wcm.repository.IResource; 
      import com.sapportals.wcm.util.content.IContent; 
      import com.sun.image.codec.jpeg.JPEGCodec; 
      import com.sun.image.codec.jpeg.JPEGEncodeParam; 
      import com.sun.image.codec.jpeg.JPEGImageEncoder; 
      
      // Referenced classes of package com.sapportals.wcm.repository.manager.thumbnail: 
      //   IResourceThumbnailPlugIn, ThumbnailPlugInInfo 
      
      public class ResourcePDFThumbnailPlugIn implements IResourceThumbnailPlugIn { 
      PdfDecoder decode_pdf = null; 
      String[] ocr = { "TeleForm" }; 
      
      public ResourcePDFThumbnailPlugIn() { 
      decode_pdf = null; 
      } 
      
      public IResourceThumbnailPlugIn.StreamedImage getContentThumbnail( 
      IResource resource, 
      ThumbnailPlugInInfo filterInfo) { 
      BufferedImage thumbImage = null; 
      ByteArrayOutputStream outStream = new ByteArrayOutputStream(); 
      try { 
      if (resource 
      .getContent() 
      .getContentType() 
      .equalsIgnoreCase("application/pdf")) { 
      thumbImage = decodeFile(resource, filterInfo); 
      } 
      if (thumbImage == null) { 
      log.warningT( 
      "Thumbnail pdf PlugIn: Could not generate a thumbnail for the resource :" 
      + resource); 
      return null; 
      } 
      
      JPEGImageEncoder encoder = 
      JPEGCodec.createJPEGEncoder( 
      outStream, 
      JPEGCodec.getDefaultJPEGEncodeParam(thumbImage)); 
      JPEGEncodeParam param = 
      encoder.getDefaultJPEGEncodeParam(thumbImage); 
      param.setQuality(1.0F, true); 
      encoder.encode(thumbImage, param); 
      } catch (Exception e) { 
      log.errorT(e.toString()); 
      } finally { 
      try { 
      outStream.close(); 
      } catch (Exception e) { 
      log.errorT(e.toString()); 
      } 
      } 
      ByteArrayInputStream is = 
      new ByteArrayInputStream(outStream.toByteArray()); 
      if (is == null) 
      return null; 
      IResourceThumbnailPlugIn.StreamedImage si = 
      new IResourceThumbnailPlugIn.StreamedImage(); 
      if (si == null) { 
      log.warningT( 
      "Thumbnail pdf PlugIn: Out of memory for streamed image."); 
      return null; 
      } else { 
      si.streamImage = is; 
      si.streamLength = outStream.size(); 
      return si; 
      } 
      } 
      /** 
      * routine to decode a pdf file 
      */ 
      private BufferedImage decodeFile( 
      IResource resource, 
      ThumbnailPlugInInfo filterInfo) { 
      //PdfDecoder returns a PdfException if there is a problem 
      try { 
      decode_pdf = new PdfDecoder(true); 
      
      /**optional JAI code for faster rendering*/ 
      //org.jpedal.external.ImageHandler myExampleImageHandler=new org.jpedal.examples.handlers.ExampleImageDrawOnScreenHandler(); 
      //decode_pdf.addExternalHandler(myExampleImageHandler, Options.ImageHandler); 
      
      /**/ 
      
      /** 
         * font mappings 
         */ 
      //set specific cases for Windows 
      String[] aliases1 = { "helvetica", "arial" }; 
      decode_pdf.setSubstitutedFontAliases("arial", aliases1); 
      
      String[] aliases2 = { "Helvetica-Bold" }; 
      decode_pdf.setSubstitutedFontAliases("Arial-BoldMT", aliases2); 
      
      String[] aliases3 = { "Times-Bold", "Times-Roman" }; 
      decode_pdf.setSubstitutedFontAliases("timesbd", aliases3); 
      
      //set general mappings for non-embedded fonts (assumes names the same) 
      PdfDecoder.setFontDirs( 
      new String[] { 
      "C:/windows/fonts/", 
      "C:/winNT/fonts/", 
      "/System/Library/Fonts/", 
      "/Library/Fonts/" }); 
      
      //true as we are rendering page 
      decode_pdf.setExtractionMode(0, 72, 72 / 72); 
      //don't bother to extract text and images 
      
      /** 
      * open the file (and read metadata including pages in  file) 
      */ 
      IContent con = resource.getUnfilteredContent(); 
      int len = (int) con.getContentLength(); 
      byte[] bArray = new byte[len]; 
      InputStream is = con.getInputStream(); 
      is.read(bArray, 0, len); 
      is.close(); 
      decode_pdf.openPdfArray(bArray); 
      
      } catch (Exception e) { 
      e.printStackTrace(); 
      
      //System.exit(1); 
      } 
      
      /** 
      * extract data from pdf (if allowed). 
      */ 
      if ((decode_pdf.isEncrypted() && (!decode_pdf.isPasswordSupplied())) 
      && (!decode_pdf.isExtractionAllowed())) { 
      return null; 
      } else { 
      
      try { 
      
      int page = 1; 
      
      /** 
      * get PRODUCER and if OCR disable text printing 
      */ 
      PdfFileInformation currentFileInformation = 
      decode_pdf.getFileInformationData(); 
      
      String[] values = currentFileInformation.getFieldValues(); 
      String[] fields = currentFileInformation.getFieldNames(); 
      
      for (int i = 0; i < fields.length; i++) { 
      
      if (fields<i>.equals("Creator")) { 
      
      for (int j = 0; j < ocr.length; j++) { 
      
      if (values<i>.equals(ocr[j])) { 
      
      decode_pdf.setRenderMode( 
      PdfDecoder.RENDERIMAGES); 
      
      /** 
      * if we want to use java 13 JPEG conversion 
      */ 
      decode_pdf.setEnableLegacyJPEGConversion(true); 
      } 
      } 
      } 
      } 
      //get the current page as a BufferedImage 
      BufferedImage imageJava = decode_pdf.getPageAsImage(page); 
      if (imageJava != null) { 
      int nImageHeight = imageJava.getHeight(null); 
      int nImageWidth = imageJava.getWidth(null); 
      if (nImageHeight > filterInfo.getHeight() 
      || nImageWidth > filterInfo.getWidth()) { 
      if (nImageHeight > filterInfo.getHeight()) { 
      nImageWidth = 
      (nImageWidth * filterInfo.getHeight()) 
      / nImageHeight 
      + 1; 
      nImageHeight = filterInfo.getHeight(); 
      } 
      if (nImageWidth > filterInfo.getWidth()) { 
      nImageHeight = 
      (nImageHeight * filterInfo.getWidth()) 
      / nImageWidth 
      + 1; 
      nImageWidth = filterInfo.getWidth(); 
      } 
      } 
      if (nImageHeight <= 0 || nImageWidth <= 0) { 
      log.warningT("Thumbnail pdf PlugIn:  Could not generated: Cannot detect image size from: " + resource); 
      return null; 
      } 
      BufferedImage thumbBufferedImage = new BufferedImage(filterInfo.getWidth(), filterInfo.getHeight(), 1); 
      if (thumbBufferedImage == null) { 
      log.warningT("Thumbnail pdf PlugIn:  Out of memory for thumbBufferedImage."); 
      return null; 
      } 
      Graphics2D graphics = thumbBufferedImage.createGraphics(); 
      if (graphics == null) { 
      log.warningT("Thumbnail pdf PlugIn: Could not generate a graphic context."); 
      return null; 
      } 
      graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); 
      graphics.setBackground(new Color(255, 255, 255)); 
      graphics.clearRect(0, 0, nImageWidth, nImageHeight); 
      graphics.drawImage(imageJava, 0, 0, nImageWidth, nImageHeight, null); 
      graphics.dispose(); 
      return thumbBufferedImage; 
      } 
      
      } catch (Exception e) { 
      decode_pdf.closePdfFile(); 
      System.err.println("Exception " + e.getMessage() + " with thumbnails"); 
      } 
      } 
      
      /**close the pdf file*/ 
      decode_pdf.closePdfFile(); 
      return null; 
      } 
      
      static Class _mthclass$(String x0) { 
      try { 
      return Class.forName(x0); 
      } catch (ClassNotFoundException x1) { 
      throw new NoClassDefFoundError(x1.getMessage()); 
      } 
      } 
      
      private static Location log; 
      
      static { 
      log = Location.getLocation((com.sapportals.wcm.repository.manager.thumbnail.ResourcePDFThumbnailPlugIn.class).getName()); 
      } 
      }

      Please note that you need the jpedalSTD.jar for it to work.

      best regards,

      Avishai Zamir

  • author's profile photo Former Member
    Former Member
    Posted on Apr 08, 2008 at 11:58 AM

    Hi Vipin:

    Did you checked the below thread, its works fine..!

    https://www.sdn.sap.com/irj/sdn/thread?messageID=4836850#4836850

    Tnx,

    MS

    points for useful answers

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 23, 2008 at 06:28 AM

    Hi Zamir,

    Thanks for your valuable inputs.

    The program is running successfully. We made a jar file for the java class using Web Dynpro.

    We tried all the possibilities of deployment -

    1 We deployed it through EAR project and changed the default java class name in the thumbnail Plug in.

    it did not work, we noticed that the deployed file was not visible at the server at the path you mentioned , we also noticed , there was no entry of PDF thumbnail file in the root>system>thumbnail folder.

    Could you please help with the step by step solution after this.

    Its very urgent.

    Thanks

    Vipin

    PS - Full marks will be awarded for the solution.

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi Vipin,

      Create a par file from the portal project and deploy it through NWDS or with the Administration Console under System Administration -> Support -> Portal Runtime -> Administration Console.. If you want, give me your email and I'll send you a par file I created with the above mentioned example.

      A restart of the system is usualy needed after the deployment of the par file.

      Don't change the default java class name, create a new plug-in, name it, (PDFs for example) and set the java class to the class you deployed.

      (If you're using my par file then set it to com.sapportals.wcm.repository.manager.thumbnail.ResourcePDFThumbnailPlugIn) then check the "pdf" entry in the MIME Type List.

      Once it is working you'll start seeing entries under root>system>thumbnail folder for each file that a thumbnail was created for.

      Best regards,

      Avishai Zamir

  • author's profile photo Former Member
    Former Member
    Posted on May 26, 2008 at 11:42 AM

    Hi Avishai Zamir

    PDF is working fine now

    Thanks for the support.

    Regards

    Vipin

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 28, 2009 at 11:58 AM

    Hello Everybody,

    My problem is:

    I could uploaded pictures to KM folders using by webdynpro . But I would like to create thumbnail in km while i am uploading picture. And I want to use "IResourceThumbnailPlugIn" from webdynpro. But I couldnt call this class. I added "km.appl.repository.manager.thumbnail_core.jar " for external jar file in my project folders. But i dont know how can i call this procedure?

    Thanks in advance for your helps.

    Kind Regards,

    Rasim

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.