1
0
mirror of https://github.com/pdf2htmlEX/pdf2htmlEX.git synced 2024-06-28 23:09:01 +00:00

better cmake, better installation

This commit is contained in:
Lu Wang 2012-08-14 13:56:41 +08:00
parent fe6d699e44
commit b406fb4e13
8 changed files with 132 additions and 92 deletions

View File

@ -9,16 +9,30 @@ find_package(Boost REQUIRED COMPONENTS program_options)
include_directories(${Boost_INCLUDE_DIRS})
link_directories ( ${Boost_LIBRARY_DIRS} )
set(PDFTOHTMLEX_VERSION "0.1")
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
set(PDF2HTMLEX_VERSION "0.1")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wunused-function")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ggdb")
add_executable(pdftohtmlEX src/pdftohtmlEX.cc src/HTMLRenderer.cc src/HTMLRenderer.h src/BackgroundRenderer.cc src/BackgroundRenderer.h src/Consts.h src/Consts.cc src/util.h)
target_link_libraries(pdftohtmlEX poppler boost_program_options)
configure_file (bin/pdf2htmlEX.in bin/pdf2htmlEX)
configure_file (src/config.h.in src/config.h)
install (TARGETS pdftohtmlEX DESTINATION bin)
add_executable(pdf2htmlEX
src/pdf2htmlEX.cc
src/HTMLRenderer.h
src/HTMLRenderer.cc
src/BackgroundRenderer.h
src/BackgroundRenderer.cc
src/Consts.h
src/Consts.cc
src/util.h
src/config.h)
target_link_libraries(pdf2htmlEX poppler boost_program_options boost_filesystem)
install (TARGETS pdf2htmlEX DESTINATION lib/pdf2htmlEX)
install (PROGRAMS "bin/pdf2htmlEX" DESTINATION bin)
file (GLOB libfiles lib/*)
install (FILES ${libfiles} DESTINATION lib/pdf2htmlEX)

View File

@ -1,18 +1,14 @@
#!/bin/bash
set -e
LIBDIR=@CMAKE_INSTALL_PREFIX@/lib/pdf2htmlEX
TMPDIR=/tmp/pdf2htmlEX
# prepare the temporary directory
test -d $TMPDIR || mkdir -p $TMPDIR
rm -f $TMPDIR/* 2>/dev/null
# Get directory of the script
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done
SCRIPT_DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"/
# Execute
${SCRIPT_DIR}/pdftohtmlEX $*
$LIBDIR/pdf2htmlEX $*
if [ -f $TMPDIR/convert.pe ]; then
echo -n "Converting fonts: "

66
lib/head.html Normal file
View File

@ -0,0 +1,66 @@
<!DOCTYPE html>
<!-- head.html -->
<!-- by WangLu -->
<!-- 2012.08.14 -->
<html>
<head>
<meta charset="utf-8">
<style type="text/css">
#pdf-main {
font-family: sans-serif;
position:absolute;
top:0;
left:0;
bottom:0;
right:0;
overflow:auto;
background-color:grey;
/* for Chrome & Safari */
-webkit-text-stroke-width:0.2px;
}
#pdf-main > .p {
position:relative;
margin:13px auto;
background-color:white;
overflow:hidden;
display:none;
}
.p > .l {
position:absolute;
white-space:pre;
}
.l > .w {
display:inline-block;
font-family: monospace;
}
::selection{
background: rgba(168,209,255,0.5);
}
::-moz-selection{
background: rgba(168,209,255,0.5);
}
.p > .i {
position:absolute;
}
</style>
<link rel="stylesheet" type="text/css" href="all.css" />
<script type="text/javascript">
function show_pages()
{
var pages = document.getElementById('pdf-main').childNodes;
var idx = 0;
var f = function(){
if (idx < pages.length) {
try{
pages[idx].style.display='block';
}catch(e){}
++idx;
setTimeout(f,100);
}
};
f();
};
</script>
</head>
<body onload="show_pages();">
<div id="pdf-main">

6
lib/tail.html Normal file
View File

@ -0,0 +1,6 @@
<!-- tail.html -->
<!-- by WangLu -->
<!-- 2012.08.14 -->
</div>
</body>
</html>

View File

@ -9,87 +9,24 @@
const double EPS = 1e-6;
// The style "-webkit-text-stroke-width:0.2px;" is used in #pdf-main to
// improve some font of small size, which looks really bad in Chrome & Safari
const std::string HTML_HEAD = "<!DOCTYPE html>\n\
<html><head>\
<meta charset=\"utf-8\">\
<style type=\"text/css\">\
#pdf-main {\
font-family: sans-serif;\
position:absolute;\
top:0;\
left:0;\
bottom:0;\
right:0;\
overflow:auto;\
background-color:grey;\
-webkit-text-stroke-width:0.2px; \
}\
#pdf-main > .p {\
position:relative;\
margin:13px auto;\
background-color:white;\
overflow:hidden;\
display:none;\
}\
.p > .l {\
position:absolute;\
white-space:pre;\
}\
.l > .w {\
display:inline-block;\
font-family: monospace;\
}\
::selection{\
background: rgba(168,209,255,0.5);\
}\
::-moz-selection{\
background: rgba(168,209,255,0.5);\
}\
.p > .i {\
position:absolute;\
}\
</style><link rel=\"stylesheet\" type=\"text/css\" href=\"all.css\" />\
<script type=\"text/javascript\">\
function show_pages()\
{\
var pages = document.getElementById('pdf-main').childNodes;\
var idx = 0;\
var f = function(){\
if (idx < pages.length) {\
try{\
pages[idx].style.display='block';\
}catch(e){}\
++idx;\
setTimeout(f,100);\
}\
};\
f();\
};\
</script>\
</head><body onload=\"show_pages();\"><div id=\"pdf-main\">";
const std::string TMP_DIR="/tmp/pdf2htmlEX";
const std::string HTML_TAIL = "</div></body></html>";
const std::string TMP_DIR = "/tmp/pdf2htmlEX";
const std::map<std::string, std::string> BASE_14_FONT_CSS_FONT_MAP({\
{ "Courier", "Courier,monospace" },\
{ "Helvetica", "Helvetica,Arial,\"Nimbus Sans L\",sans-serif" },\
{ "Times", "Times,\"Time New Roman\",\"Nimbus Roman No9 L\",serif" },\
{ "Symbol", "Symbol,\"Standard Symbols L\"" },\
{ "ZapfDingbats", "ZapfDingbats,\"Dingbats\"" },\
const std::map<std::string, std::string> BASE_14_FONT_CSS_FONT_MAP({
{ "Courier", "Courier,monospace" },
{ "Helvetica", "Helvetica,Arial,\"Nimbus Sans L\",sans-serif" },
{ "Times", "Times,\"Time New Roman\",\"Nimbus Roman No9 L\",serif" },
{ "Symbol", "Symbol,\"Standard Symbols L\"" },
{ "ZapfDingbats", "ZapfDingbats,\"Dingbats\"" },
});
const double id_matrix[6] = {1.0, 0.0, 0.0, 1.0, 0.0, 0.0};
const std::map<std::string, std::string> GB_ENCODED_FONT_NAME_MAP({\
{"\xCB\xCE\xCC\xE5", "SimSun"},\
{"\xBA\xDA\xCC\xE5", "SimHei"},\
{"\xBF\xAC\xCC\xE5_GB2312", "SimKai"},\
{"\xB7\xC2\xCB\xCE_GB2312", "SimFang"},\
{"\xC1\xA5\xCA\xE9", "SimLi"},\
const std::map<std::string, std::string> GB_ENCODED_FONT_NAME_MAP({
{"\xCB\xCE\xCC\xE5", "SimSun"},
{"\xBA\xDA\xCC\xE5", "SimHei"},
{"\xBF\xAC\xCC\xE5_GB2312", "SimKai"},
{"\xB7\xC2\xCB\xCE_GB2312", "SimFang"},
{"\xC1\xA5\xCA\xE9", "SimLi"},
});

View File

@ -17,6 +17,7 @@
#include <boost/format.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/filesystem/fstream.hpp>
// for gil bug
const int *int_p_NULL = nullptr;
#include <boost/gil/gil_all.hpp>
@ -32,6 +33,7 @@ const int *int_p_NULL = nullptr;
#include "BackgroundRenderer.h"
#include "Consts.h"
#include "util.h"
#include "config.h"
/*
* CSS classes
@ -120,12 +122,12 @@ void HTMLRenderer::process(PDFDoc *doc)
void HTMLRenderer::write_html_head()
{
html_fout << HTML_HEAD << endl;
html_fout << boost::filesystem::ifstream(PDF2HTMLEX_LIB_PATH / "head.html", ifstream::binary).rdbuf();
}
void HTMLRenderer::write_html_tail()
{
html_fout << HTML_TAIL << endl;
html_fout << boost::filesystem::ifstream(PDF2HTMLEX_LIB_PATH / "tail.html", ifstream::binary).rdbuf();
}
void HTMLRenderer::startPage(int pageNum, GfxState *state)

20
src/config.h.in Normal file
View File

@ -0,0 +1,20 @@
/*
* config.h
* Compile time constants
*
* by WangLu
*/
#ifndef CONFIG_H__
#define CONFIG_H__
#include <string>
#include <boost/filesystem.hpp>
static const std::string PDF2HTMLEX_VERSION = "@PDF2HTMLEX_VERSION@";
static const std::string PDF2HTMLEX_PREFIX = "@CMAKE_INSTALL_PREFIX@";
static const boost::filesystem::path PDF2HTMLEX_LIB_PATH = boost::filesystem::path(PDF2HTMLEX_PREFIX) / "lib" / "pdf2htmlEX";
#endif //CONFIG_H__

View File

@ -27,8 +27,7 @@
#include "HTMLRenderer.h"
#include "Param.h"
#define PDFTOHTMLEX_VERSION "0.1"
#include "config.h"
namespace po = boost::program_options;
using namespace std;
@ -102,7 +101,7 @@ static GooString* getInfoDate(Dict *infoDict, char *key) {
void show_usage(void)
{
cerr << "pdftohtmlEX version " << PDFTOHTMLEX_VERSION << endl;
cerr << "pdftohtmlEX version " << PDF2HTMLEX_VERSION << endl;
cerr << endl;
cerr << "Copyright 2011 Hongliang Tian (tatetian@gmail.com)" << endl;
cerr << "Copyright 2012 Lu Wang (coolwanglu<at>gmail.com)" << endl;