Accents fichier texte Linux 4.0D

cancel
Showing results for 
Search instead for 
Did you mean: 
Active Member

Accents fichier texte Linux 4.0D

Hello,

Je rencontre des problèmes pour afficher les accents dans les aperçus dans Share. La transformation de base (out-of-box, txt -> swf) n'étant pas concluante, j'utilise une transformation passant par OpenOffice.
Ce fichier par exemple pose problème (en ISO-8859-1) : https://issues.alfresco.com/jira/secure/attachment/29345/TestAccents.txt
[img]https://issues.alfresco.com/jira/secure/attachment/29344/previewInShare.png[/img]
Sous RHEL 5.6 Alfresco 4.0d. J'ai aussi testé avec la version d'OpenOffice 3.3.0.
Ce même fichier fonctionne très bien si l'installation est sous Alfresco 4.0D, Windows (32bits, XP).

tomcat/shared/classes/alfresco/extension/custom-swf-transform-context.xml


<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>

<beans>

   <!– Import the swftools transformer worker from the third party subsystem –>
   <bean id="transformer.worker.Pdf2swf" class="org.alfresco.repo.management.subsystems.SubsystemProxyFactory">
      <property name="sourceApplicationContextFactory">
         <ref bean="thirdparty" />
      </property>
      <property name="sourceBeanName">
         <value>transformer.worker.Pdf2swf</value>
      </property>
      <property name="interfaces">
         <list>
            <value>org.alfresco.repo.content.transform.ContentTransformerWorker</value>
         </list>
      </property>
   </bean>

   <bean id="transformer.Pdf2swf" class="org.alfresco.repo.content.transform.ProxyContentTransformer"
      parent="baseContentTransformer">
      <property name="worker">
         <ref bean="transformer.worker.Pdf2swf"/>
      </property>
      <property name="maxSourceSizeKBytes"><value>${content.transformer.Pdf2swf.maxSourceSizeKBytes}</value></property>
   </bean>

   <bean id="transformer.complex.OpenOffice.Pdf2swf"
        class="org.alfresco.repo.content.transform.ComplexContentTransformer"
        parent="baseContentTransformer" >
      <property name="transformers">
         <list>
            <ref bean="transformer.OpenOffice" />
            <ref bean="transformer.Pdf2swf" />
         </list>
      </property>
      <property name="intermediateMimetypes">
         <list>
            <value>application/pdf</value>
         </list>
      </property>
      <!– Note: there are maxSourceSizeKBytes limits on transformer.OpenOffice for txt->pdf and xlsx->pdf
           which may cause this transformer not to be selected because it is too slow. –>
   </bean>

   <bean id="transformer.complex.iWorks.Pdf2swf"
        class="org.alfresco.repo.content.transform.ComplexContentTransformer"
        parent="baseContentTransformer" >
      <property name="transformers">
         <list>
            <ref bean="transformer.iWorksQuicklooks" />
            <ref bean="transformer.Pdf2swf" />
         </list>
      </property>
      <property name="intermediateMimetypes">
         <list>
            <value>application/pdf</value>
         </list>
      </property>
   </bean>

   <bean id="transformer.complex.Text.Pdf2swf"
        class="org.alfresco.repo.content.transform.ComplexContentTransformer"
        parent="baseContentTransformer" >
      <property name="transformers">
         <list>
                                <ref bean="transformer.complex.OpenOffice.Pdf2swf" />
                                <!–<ref bean="transformer.PdfBox.TextToPdf" />–>
            <ref bean="transformer.Pdf2swf" />
         </list>
      </property>
      <property name="intermediateMimetypes">
         <list>
            <value>application/pdf</value>
         </list>
      </property>
      <!– Note: there are maxSourceSizeKBytes limit on transformer.PdfBox.TextToPdf for txt->pdf
           which may cause this transformer not to be selected because it is too slow and another
           maxSourceSizeKBytes limit on transformer.Pdf2swf, but what is the point of doing the
           first one only to give up on the second when we can guess the pdf size is just a bit
           more than the text. –>
      <property name="maxSourceSizeKBytes"><value>${content.transformer.complex.Text.Pdf2swf.maxSourceSizeKBytes}</value></property>
   </bean>

   <!– This transformer allows for the webpreviewing of zip archive files. –>
   <bean id="transformer.complex.Archive.Pdf2swf"
        class="org.alfresco.repo.content.transform.ComplexContentTransformer"
        parent="baseContentTransformer" >
      <property name="transformers">
         <list>
            <ref bean="transformer.Archive" />
            <ref bean="transformer.PdfBox.TextToPdf" />
            <ref bean="transformer.Pdf2swf" />
         </list>
      </property>
      <property name="intermediateMimetypes">
         <list>
            <value>text/plain</value>
            <value>application/pdf</value>
         </list>
      </property>
      <property name="transformationOptionOverrides">
         <map>
            <entry key="includeEmbedded" value="no" />
         </map>
      </property>
   </bean>

   <!– This transformer allows for the webpreviewing of outlook msg files. –>
   <bean id="transformer.complex.Msg2swf"
        class="org.alfresco.repo.content.transform.ComplexContentTransformer"
        parent="baseContentTransformer" >
      <property name="transformers">
         <list>
            <ref bean="transformer.OutlookMsg" />
            <ref bean="transformer.PdfBox.TextToPdf" />
            <ref bean="transformer.Pdf2swf" />
         </list>
      </property>
      <property name="intermediateMimetypes">
         <list>
            <value>text/plain</value>
            <value>application/pdf</value>
         </list>
      </property>
   </bean>

</beans>

Un fichier en format UTF-8 donne un bon aperçu.
Quels adaptations doit-on faire pour un meilleur aperçu de fichiers textes sous Linux ?

Support
Bug OpenOffice : Server conversion failed : https://forums.alfresco.com/fr/viewtopic.php?f=8&t=5402#p24815
Bug inscrit dans Jira : https://issues.alfresco.com/jira/browse/ALF-13025
5 Replies
Active Member

Re: Accents fichier texte Linux 4.0D

Un fichier en format UTF-8 donne un bon aperçu.

La locale de votre système est UTF-8 j'imagine. c'est ce qui est recommandé.
La commande pdf2swf qui est éxécutée s'attend donc à trouver un fichier UTF-8.

Peut être donc dans votre cas faut-il chaîner une transformation iso-8859 => UTF-8 ?
Cette transformation est réalisée lorsque l'on indexe des fichiers texte.
Active Member

Re: Accents fichier texte Linux 4.0D

Merci bien.

Si j'ai bien compris, je devrais ajouter une nouvelle transformation.

Par défaut, un fichier texte est converti selon :
TXT->PDF->SWF
Problèmes (apostrophe ne s'affiche pas, des caractères spéciaux en début de ligne…)

Nous avons amélioré ceci en passant par
TXT->OpenOffice(OOO)->PDF->SWF
Problème d'accents si fichier n'est pas UTF-8

Votre proposition serait de passer par
TXT - TXT(UTF8) -> …
Active Member

Re: Accents fichier texte Linux 4.0D

J'ai intégré le transformer.StringExtracter, mais cela n'a rien changé aux aperçus…

<bean id="transformer.complex.Text.Pdf2swf"
        class="org.alfresco.repo.content.transform.ComplexContentTransformer"
        parent="baseContentTransformer" >
      <property name="transformers">
         <list>
                <ref bean="transformer.StringExtracter" />
                <!– <ref bean="transformer.complex.OpenOffice.Pdf2swf" /> –>
                <ref bean="transformer.PdfBox.TextToPdf" />
                <ref bean="transformer.Pdf2swf" />
         </list>
      </property>
      <property name="intermediateMimetypes">
         <list>
                <value>text/plain</value>
            <value>application/pdf</value>
         </list>
      </property>
      <!– Note: there are maxSourceSizeKBytes limit on transformer.PdfBox.TextToPdf for txt->pdf
           which may cause this transformer not to be selected because it is too slow and another
           maxSourceSizeKBytes limit on transformer.Pdf2swf, but what is the point of doing the
           first one only to give up on the second when we can guess the pdf size is just a bit
           more than the text. –>
      <property name="maxSourceSizeKBytes"><value>${content.transformer.complex.Text.Pdf2swf.maxSourceSizeKBytes}</value></property>
   </bean>

Et ceci :
<bean id="transformer.complex.Text.Pdf2swf"
        class="org.alfresco.repo.content.transform.ComplexContentTransformer"
        parent="baseContentTransformer" >
      <property name="transformers">
         <list>
                <ref bean="transformer.StringExtracter" />
                <ref bean="transformer.complex.OpenOffice.Pdf2swf" />
                <!– <ref bean="transformer.PdfBox.TextToPdf" /> –>
                <ref bean="transformer.Pdf2swf" />
         </list>
      </property>
      <property name="intermediateMimetypes">
         <list>
                <value>text/plain</value>
            <value>application/pdf</value>
         </list>
      </property>
      <!– Note: there are maxSourceSizeKBytes limit on transformer.PdfBox.TextToPdf for txt->pdf
           which may cause this transformer not to be selected because it is too slow and another
           maxSourceSizeKBytes limit on transformer.Pdf2swf, but what is the point of doing the
           first one only to give up on the second when we can guess the pdf size is just a bit
           more than the text. –>
      <property name="maxSourceSizeKBytes"><value>${content.transformer.complex.Text.Pdf2swf.maxSourceSizeKBytes}</value></property>
   </bean>

J'ai aussi tenté de faire la conversion manuellement, mais j'obtiens toujours ces carrés avec des points d'interrogations…

Tranformer


package ch.custom.manageoffice.transformer;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.nio.charset.Charset;

import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.TransformationOptions;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.pdfbox.TextToPDF;
import org.apache.pdfbox.cos.COSName;
import org.apache.pdfbox.encoding.EncodingManager;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.font.PDTrueTypeFont;
import org.apache.pdfbox.pdmodel.font.PDType1Font;

import org.alfresco.repo.content.transform.AbstractContentTransformer2;
public class TextUtfToPdfContentTransformer extends AbstractContentTransformer2
{
    private static final Log logger = LogFactory.getLog(TextUtfToPdfContentTransformer.class);
   
    private TextToPDF transformer;
   
    public TextUtfToPdfContentTransformer()
    {
        transformer = new TextToPDF();
    }
   
    public void setStandardFont(String fontName)
    {
        try
        {
            transformer.setFont(PDType1Font.getStandardFont(fontName));
        }
        catch (Throwable e)
        {
            throw new AlfrescoRuntimeException("Unable to set Standard Font for PDF generation: " + fontName, e);
        }
    }
   
    public void setTrueTypeFont(String fontName)
    {
        try
        {
            transformer.setFont(PDTrueTypeFont.loadTTF(null, fontName));
        }
        catch (Throwable e)
        {
            throw new AlfrescoRuntimeException("Unable to set True Type Font for PDF generation: " + fontName, e);
        }
    }
   
    public void setFontSize(int fontSize)
    {
        try
        {
            transformer.setFontSize(fontSize);
        }
        catch (Throwable e)
        {
            throw new AlfrescoRuntimeException("Unable to set Font Size for PDF generation: " + fontSize);
        }
    }
   
    /**
     * Only supports Text to PDF
     */
    public boolean isTransformable(String sourceMimetype, String targetMimetype, TransformationOptions options)
    {
        if ( (!MimetypeMap.MIMETYPE_TEXT_PLAIN.equals(sourceMimetype) &&
              !MimetypeMap.MIMETYPE_TEXT_CSV.equals(sourceMimetype) &&
              !MimetypeMap.MIMETYPE_XML.equals(sourceMimetype) ) ||
            !MimetypeMap.MIMETYPE_PDF.equals(targetMimetype))
        {
            // only support (text/plain OR text/csv OR text/xml) to (application/pdf)
            return false;
        }
        else
        {
            return true;
        }
    }

    @Override
    protected void transformInternal(
            ContentReader reader,
            ContentWriter writer,
            TransformationOptions options) throws Exception
    {
        PDDocument pdf = null;
        InputStream is = null;
        InputStreamReader ir = null;
        OutputStream os = null;
        try
        {
           logger.debug("Working…");

            is = reader.getContentInputStream();
           
            EncodingManager encodingManager = new EncodingManager();
           // transformer.getFont().setEncoding(encodingManager.getEncoding(COSName.WIN_ANSI_ENCODING));
           
            pdf = transformer.createPDFFromText(new InputStreamReader(is, "UTF-8"));
            // dump it all to the writer
            os = writer.getContentOutputStream();
            pdf.save(os);
           
             ir = buildReader(is, reader.getEncoding(), reader.getContentUrl());
            
             pdf = transformer.createPDFFromText(ir);
             // dump it all to the writer
             os = writer.getContentOutputStream();
             pdf.save(os);
        }
        finally
        {
            if (pdf != null)
            {
                try { pdf.close(); } catch (Throwable e) {e.printStackTrace(); }
            }
            if (ir != null)
            {
                try { ir.close(); } catch (Throwable e) {e.printStackTrace(); }
            }
            if (is != null)
            {
                try { is.close(); } catch (Throwable e) {e.printStackTrace(); }
            }
            if (os != null)
            {
                try { os.close(); } catch (Throwable e) {e.printStackTrace(); }
            }
        }
    }
   
    protected InputStreamReader buildReader(InputStream is, String encoding, String node)
    {
        // If they gave an encoding, try to use it
        if(encoding != null)
        {
            Charset charset = null;
            try
            {
                charset = Charset.forName(encoding);
            } catch(Exception e)
            {
                logger.warn("JVM doesn't understand encoding '" + encoding +
                        "' when transforming " + node);
            }
            if(charset != null)
            {
                logger.debug("Processing plain text in encoding " + charset.displayName());
                return new InputStreamReader(is, charset);
            }
        }
       
        // Fall back on the system default
        logger.debug("Processing plain text using system default encoding");
        return new InputStreamReader(is);
    }
}
Démarré par :
 <bean id="transformer.PdfBox.TextUtfToPdf"
         class="ch.custom.manageoffice.transformer.TextUtfToPdfContentTransformer"
         parent="baseContentTransformer" >
      <property name="explicitTransformations">
         <list>
            <bean class="org.alfresco.repo.content.transform.ExplictTransformationDetails" >
                <constructor-arg><value>text/plain</value></constructor-arg>
                <constructor-arg><value>application/pdf</value></constructor-arg>
            </bean>
         </list>
      </property>
   </bean>
    <!– Text to PDF (overide tomcat/webapps/alfresco/WEB-INF/classes/alfresco/swf-transform-context.xml)–>
    <bean id="transformer.complex.Text.Pdf2swf"
        class="org.alfresco.repo.content.transform.ComplexContentTransformer"
        parent="baseContentTransformer" >
      <property name="transformers">
         <list>
           <!–<ref bean="transformer.PdfBox.TextToPdf" />–>
        <ref bean="transformer.PdfBox.TextUtfToPdf" />
            <ref bean="transformer.Pdf2swf" />
         </list>
      </property>
      <property name="intermediateMimetypes">
         <list>
            <value>application/pdf</value>
         </list>
      </property>
   </bean>
Active Member

Re: Accents fichier texte Linux 4.0D

Comme source d'inspiration, je parlais de la classe : ADMLuceneIndexerImpl. voir :


if (!EqualsHelper.nullSafeEquals(reader.getMimetype(), MimetypeMap.MIMETYPE_TEXT_PLAIN) || !EqualsHelper.nullSafeEquals(reader.getEncoding(), "UTF-8"))
// get the transformer
                        ContentTransformer transformer = contentService.getTransformer(reader.getMimetype(), MimetypeMap.MIMETYPE_TEXT_PLAIN);
…                                        

Soit vous reutilisez ce mécanisme dans votre code, soit vous utilisez la config spring. exercise for the reader.
Active Member

Re: Accents fichier texte Linux 4.0D

J'ai remarqué que le fichier n'est pas détecté correctement.

Si l'on ajoute dans Share un fichier ISO-8859-1, et que l'on va par le client Explorer, on voit l'encodage windows-1252. A ce moment-là, si l'on change pour du ISO-8859-1, et que l'on revient dans Share, l'aperçu est correcte.

Sous Windows, la détection est aussi erronée (il voit du windows-1252), mais l'aperçu est correct en laissant cet encodage.