mirror of
https://github.com/Alfresco/alfresco-transform-core.git
synced 2025-07-31 17:38:33 +00:00
ATS-675/ATS-695 Added PdfRendererApadpter.java
Added dependency to pom.xml Required transformation of String to Long, method added to Util.java
This commit is contained in:
@@ -30,6 +30,11 @@
|
|||||||
<artifactId>alfresco-transform-tika</artifactId>
|
<artifactId>alfresco-transform-tika</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.alfresco</groupId>
|
||||||
|
<artifactId>alfresco-transform-pdf-renderer</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
|
@@ -0,0 +1,83 @@
|
|||||||
|
/*
|
||||||
|
* #%L
|
||||||
|
* Alfresco Transform Core
|
||||||
|
* %%
|
||||||
|
* Copyright (C) 2005 - 2020 Alfresco Software Limited
|
||||||
|
* %%
|
||||||
|
* This file is part of the Alfresco software.
|
||||||
|
* -
|
||||||
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
|
* provided under the following open source license terms:
|
||||||
|
* -
|
||||||
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
* -
|
||||||
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
* -
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
* #L%
|
||||||
|
*/
|
||||||
|
package org.alfresco.transformer.transformers;
|
||||||
|
|
||||||
|
import static org.alfresco.transformer.util.Util.stringToLong;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.alfresco.transformer.executors.PdfRendererCommandExecutor;
|
||||||
|
import org.alfresco.transformer.PdfRendererOptionsBuilder;
|
||||||
|
|
||||||
|
|
||||||
|
public class PdfRendererAdapter extends AbstractTransformer
|
||||||
|
{
|
||||||
|
private static String CONFIG_PREFIX = "pdf-renderer";
|
||||||
|
private PdfRendererCommandExecutor pdfExecutor;
|
||||||
|
|
||||||
|
//TODO move key strings to a central class
|
||||||
|
private final static String PAGE_REQUEST_PARAM = "page";
|
||||||
|
private final static String WIDTH_REQUEST_PARAM = "width";
|
||||||
|
private final static String HEIGHT_REQUEST_PARAM = "height";
|
||||||
|
private final static String ALLOW_PDF_ENLARGEMENT = "allowPdfEnlargement";
|
||||||
|
private final static String MAINTAIN_PDF_ASPECT_RATIO = "maintainPdfAspectRatio";
|
||||||
|
private final static String TIMEOUT_REQUEST_PARAM = "timeout";
|
||||||
|
|
||||||
|
|
||||||
|
public PdfRendererAdapter() throws Exception
|
||||||
|
{
|
||||||
|
super();
|
||||||
|
pdfExecutor = new PdfRendererCommandExecutor();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
String getTransformerConfigPrefix()
|
||||||
|
{
|
||||||
|
return CONFIG_PREFIX;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void transform(File sourceFile, File targetFile, String sourceMimetype, String targetMimetype,
|
||||||
|
Map<String, String> transformOptions) throws Exception
|
||||||
|
{
|
||||||
|
|
||||||
|
final String options = PdfRendererOptionsBuilder
|
||||||
|
.builder()
|
||||||
|
.withPage(transformOptions.get(PAGE_REQUEST_PARAM))
|
||||||
|
.withWidth(transformOptions.get(WIDTH_REQUEST_PARAM))
|
||||||
|
.withHeight(transformOptions.get(HEIGHT_REQUEST_PARAM))
|
||||||
|
.withAllowPdfEnlargement(transformOptions.get(ALLOW_PDF_ENLARGEMENT))
|
||||||
|
.withMaintainPdfAspectRatio(transformOptions.get(MAINTAIN_PDF_ASPECT_RATIO))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Long timeout = stringToLong(transformOptions.get(TIMEOUT_REQUEST_PARAM));
|
||||||
|
|
||||||
|
pdfExecutor.run(options, sourceFile, targetFile, timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -52,4 +52,15 @@ public class Util
|
|||||||
{
|
{
|
||||||
return param == null ? null : Boolean.parseBoolean(param);
|
return param == null ? null : Boolean.parseBoolean(param);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Safely converts a {@link String} to a {@link Long}
|
||||||
|
*
|
||||||
|
* @param param String to be converted
|
||||||
|
* @return Null if param is null or converted value as {@link Boolean}
|
||||||
|
*/
|
||||||
|
public static Long stringToLong(final String param)
|
||||||
|
{
|
||||||
|
return param == null ? null : Long.parseLong(param);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user