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

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/ or by command line using a terminal (allows the user to specify some parameters).
#### Running the script run.bat/
Use this method if you do not want to use a terminal.
1. Download 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 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 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.
"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
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project name="hdoc_to_pdf" basedir="." default="main">
<taskdef resource="net/sf/antcontrib/antlib.xml">
<pathelement location="lib/ant-contrib.jar"/>
<!-- 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}"/>
<!-- Temporary files and folders are deleted -->
<delete dir="${tmp}"/>
<delete file="prepare_hdoc.ant"/>
<delete file=""/>
<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 -->
<fileset dir="${OutputPath}"/>
<fileset dir="${tmpdir}"/>
<echo message="Getting input hdoc file..."/>
<condition property="InputFile.set" else="false">
<isset property="InputFile"/>
<equals arg1="${InputFile.set}" arg2="false" />
<!-- 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"/>
<pathconvert property="HdocFile" pathsep="" refid="fileset_hdoc"/>
<!-- Get input hdoc file path -->
<fileset id="fileset_hdoc" dir="${InputPath}" casesensitive="yes">
<include name="*.hdoc"/>
<pathconvert property="InputFile" pathsep="" refid="fileset_hdoc"/>
<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}"/>
<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}/"/>
<property file="${tmpdir}/"/>
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<!--find_content.xsl creates a ANT file prepare_hdoc.ant-->
xmlns:xsl="" 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}/">
<propertyfile file="{$TempDirectory}/">
<entry key="dirpath" value="{$dirpath}"/>
Supports Markdown
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