03-01-2012 02:24 AM
<?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>
03-01-2012 04:42 AM
Un fichier en format UTF-8 donne un bon aperçu.
03-01-2012 07:47 AM
03-02-2012 02:24 AM
<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>
<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>
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>
03-06-2012 05:12 AM
…
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);
…
03-12-2012 08:24 AM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.