阅读alfresco中的pdf文件

时间:2014-07-02 11:23:48

标签: excel pdf alfresco

我已经向alfresco添加了一个UI动作,它将nodeRef作为一个参数,试图用

来阅读内容
contentService.getReader(nodeRef, ContentModel.TYPE_CONTENT).getContentString()

但它只能使用.txt文件而不能使用.pdf,.xlsx,.docx ..... 我尝试阅读pdf文件时的示例:

S#?_#3C??  R/Metadata 64 0 R/OCProperties<</D<</Order[]/R .....

使用word文档并优于其数字。

有解决方案吗?

2 个答案:

答案 0 :(得分:2)

是。请尝试使用contentService.getReader(nodeRef, ContentModel.TYPE_CONTENT).getContentInputStream()。如果您需要查找某些文本,请将流中的数据提供给PDF库,并使用其API访问内容。

答案 1 :(得分:1)

实际上Alfresco有他自己的读者,转换器和所有工作人员所以从我使用此代码的任何内容中读取它的工作

ContentReader reader = contentService.getReader(nodeRef, ContentModel.PROP_CONTENT);
       String content="";
        if (reader != null && reader.exists())
        {
                // get the transformer
                ContentTransformer transformer = contentService.getTransformer(reader.getMimetype(), MimetypeMap.MIMETYPE_TEXT_PLAIN);
                // is this transformer good enough?
                if (transformer != null)
                {
                    // We have a transformer that is fast enough
                    ContentWriter writer = contentService.getTempWriter();
                    writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);

                    try
                    {
                        transformer.transform(reader, writer);
                        // point the reader to the new-written content
                        reader = writer.getReader();
                        // Check that the reader is a view onto something concrete
                        if (!reader.exists())
                        {
                            logging(new ContentIOException("The transformation did not write any content, yet: \n"
                                    + "   transformer:     " + transformer + "\n" + "   temp writer:     " + writer+"")+"");

                            throw new ContentIOException("The transformation did not write any content, yet: \n"
                                    + "   transformer:     " + transformer + "\n" + "   temp writer:     " + writer);

                        }else {
                               content = reader.getContentString();
                               logging("------------------------------------------------------------");
                               logging(content);
                        }
                    }
                    catch (ContentIOException e)
                    {


                    }
                }
            }