Commit 2e8b2c2c authored by Baptiste Perraud's avatar Baptiste Perraud

Add input file parameter support and rework of temp files

parent ed7fe11c
Converter hdoc_to_pdf
-----------------------
The purpose of this converter is to obtain a PDF file from a hdoc document.
The purpose of this converter is to obtain a PDF file from a hdoc document.
License GPL3.0
......@@ -28,7 +28,36 @@ This project can be used alone if you only want to convert a hdoc file into a PD
User documentation
------------------
There are two different ways to use the converter hdoc_to_pdf: by running a script run.bat/run.sh or by command line using a terminal (allows the user to specify some parameters).
#### Running the script run.bat/run.sh:
Use this method if you do not want to use a terminal.
1. Download hdoc_converter.zip and unzip it.
2. Add your source file into the input folder. It must be a .hdoc file.
3. Place _only one file_ in that folder.
4. On Linux or Mac, run the script run.sh. On Windows, run the script run.bat.
5. Your file has been converted, the result is in the output folder.
#### Terminal:
By using the terminal you can specify some parameters to the conversion at the moment: the source file.
1. Download hdoc_converter.zip and unzip it.
2. Open your terminal and go into the folder hdoc_to_pdf.
3. Run the following command:
"ant -buildfile hdoc_to_pdf.ant"
You can specify the source file by adding parameters.
Use -DInputFile to specify the source file.
Exemple:
"ant -buildfile hdoc_to_optim.ant -DInputFile=sample.hdoc"
This parameter is optional. Your file has been converted, the result is in the output folder.
Known bugs
......@@ -51,6 +80,7 @@ Generic Todo
Technical notes
---------------
* This converter works with _only one_ hdoc file in the input folder, please ensure to clean the folder before proceeding with the hdoc you want to convert to PDF.
User Story
----------
......@@ -64,5 +94,3 @@ User Story
Capitalisation
--------------
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project name="hdoc_to_pdf" basedir="." default="main">
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="lib/ant-contrib.jar"/>
</classpath>
</taskdef>
<!-- Arguments properties -->
<property name="InputPath" location="input"/>
<property name="OutputPath" location="output"/>
<property name="tmp" location="${basedir}/tmp"/>
<property name="tmpdir" location="${basedir}/tmp"/>
<property name="OutputFileName" location="${OutputPath}/result.pdf"/>
<target name="main" depends="hdocPreparation">
......@@ -16,51 +22,57 @@
<arg value="${OutputFileName}"/>
</exec>
<!-- Temporary files and folders are deleted -->
<!--
<delete dir="${tmp}"/>
<delete file="prepare_hdoc.ant"/>
<delete file="my.properties"/>
-->
</target>
<target name="hdocPreparation">
<echo message="The value of property of InputPath is ${InputPath}"/>
<echo message="The value of property of OutputPath is ${OutputPath}"/>
<echo message="The value of property of tmp is ${tmp}"/>
<!-- Creation of temp dir -->
<delete dir="${tmp}" failonerror="false"/>
<sleep seconds="1"/>
<mkdir dir="${tmp}"/>
<!-- Clean the folders before proceeding -->
<delete>
<fileset dir="${OutputPath}"/>
<fileset dir="${tmpdir}"/>
</delete>
<echo message="Getting input hdoc file..."/>
<condition property="InputFile.set" else="false">
<isset property="InputFile"/>
</condition>
<if>
<equals arg1="${InputFile.set}" arg2="false" />
<then>
<!-- There is no input, check the input folder -->
<echo message="Checking the input folder..."/>
<!-- Get input hdoc file path -->
<fileset id="fileset_hdoc" dir="${InputPath}" casesensitive="yes">
<include name="*.hdoc"/>
</fileset>
<pathconvert property="HdocFile" pathsep="" refid="fileset_hdoc"/>
<!-- Get input hdoc file path -->
<fileset id="fileset_hdoc" dir="${InputPath}" casesensitive="yes">
<include name="*.hdoc"/>
</fileset>
<pathconvert property="InputFile" pathsep="" refid="fileset_hdoc"/>
</then>
</if>
<echo message="Executing conversion..."/>
<!-- Unzips the hdoc to be converted-->
<unzip dest="${tmp}" src="${HdocFile}"/>
<unzip dest="${tmpdir}" src="${InputFile}"/>
<!-- Gives all rights to avoid bugs-->
<chmod dir="${tmp}" perm="777"/>
<chmod dir="${tmpdir}" perm="777"/>
<!-- Launches the XSLT find_content to retrieve the content path -->
<xslt in="${tmp}/META-INF/container.xml" out="prepare_hdoc.ant" classpath="./lib/saxon9he.jar" style="xsl/find_content.xsl">
<xslt in="${tmpdir}/META-INF/container.xml" out="${tmpdir}/prepare_hdoc.ant" classpath="./lib/saxon9he.jar" style="xsl/find_content.xsl">
<param name="BaseDirectory" expression="${basedir}"/>
<param name="TempDirectory" expression="${tmp}"/>
<param name="TempDirectory" expression="${tmpdir}"/>
</xslt>
<chmod file="prepare_hdoc.ant" perm="777"/>
<chmod file="${tmpdir}/prepare_hdoc.ant" perm="777"/>
<!-- Launches the ANT prepare_hdoc.ant resulting from the previous XSLT in order to get a clean xhtml ready for the pdf conversion -->
<ant antfile="prepare_hdoc.ant"/>
<ant antfile="${tmpdir}/prepare_hdoc.ant"/>
<!-- Recover of the dirpath property extracted through find_content.xsl execution -->
<property file="${basedir}/my.properties"/>
<property file="${tmpdir}/my.properties"/>
</target>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<!--find_content.xsl creates a ANT file prepare_hdoc.ant-->
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
......@@ -51,7 +51,7 @@
<xslt in="{$dirpath}/hdoc_nsless.xhtml" out="{$dirpath}/flat_hdoc.xhtml" style="xsl/hdoc_flattenizer.xsl" classpath="./lib/saxon9he.jar"/>
<xslt in="{$dirpath}/flat_hdoc.xhtml" out="{$dirpath}/final.xhtml" style="xsl/last_transformer.xsl" classpath="./lib/saxon9he.jar"/>
<propertyfile file="{$BaseDirectory}/my.properties">
<propertyfile file="{$TempDirectory}/my.properties">
<entry key="dirpath" value="{$dirpath}"/>
</propertyfile>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment