Showing posts with label centos. Show all posts
Showing posts with label centos. Show all posts

How to convert CHM file to PDF under CentOS

I have an ebook readerso I have been looking at a loot of ebooks lately. There are many free books out there I would have never taught about reading ever again, Sherlock Holmes being one of them. But one problem I am facing is that some books are in the CHM format, I have no idea who came up with this but now it seams sort of outdated and not used for this purpose any more. PDF has won the game. So how do I convert these CHM files to PDF so I can read them on my reader.

Step 1:
Use the program kchmviewer ($ yum install kchmviewer ) to extract the HTML from the CHM. CHM is just a nice wrapper for html with some images, so this is a fairly straight forward task.
Open the file with kchmviewer
Extract it by using the tool found under File -> Extract
Now you should have many HTML files and some images. This might already be enough for you reader but I prefer to have everything in one file and not have 100 of html files clogging everything. So the next task is to convert all these files into one coherent pdf file.

Step 2:
Use these htmldoc ($ yum install htmldoc) to generate a PDF.
Now the only thing you have to do is import all the html files and configure the output you want and you should get a pdf. This might not look 100% like the book but the text and images should be the same.

It is also possible to remove some chapters and modify some stuff. So if you know you are not going to read something you can just leave it out.

The problem with google analytic when you run your own server

On my website www.ribalba.de I run google analytic which lets me see how many people look at my website where they come from and what they are looking for. Not that it really matters but I am just interested in why people would want to read about me. Assuming I should only be interesting for about 50 (+/-) people in the World. But I also run some analyzers on my web server log files and it turns out that the main thing my server is doing is serving files I have outside of my wiki (which I use for my site) they are files that I just have in folders and that can be accessed through directory listing turned on. But these are never accounted for in analytics. So if I direct my browser to http://www.ribalba.de it will be saved in analytics but when I goto http://www.ribalba.de/geek it does not. So in some respect analytics is giving me a wrong picture. Further image downloads from my server are not displayed. So not really useful as you are forgetting a huge junk of data and so your analysis of your site is bound to be wrong.

wrong start data => wrong conclusion

Maybe Google should offer a method by which I can upload the log-files after logrotate has run and so the file is not used anymore. So always take with a grain of salt what google is trying to tell you.

libnice for CentOS

Some guy on the CentOS mailing list needed libnice so I built it. It can be downloaded from:

http://www.ribalba.de/geek/port/

The source package is in the src folder and the builds in the respective directories.

I hope this helped some poor sole :)

Just for your inforamtion:

GLib ICE implementation

libnice is an implementation of the IETF's draft Interactive Connectivity
Establishment standard (ICE). ICE is useful for applications that want to
establish peer-to-peer UDP data streams. It automates the process of traversing
NATs and provides security against some attacks. Existing standards that use
ICE include the Session Initiation Protocol (SIP) and Jingle, XMPP extension
for audio/video calls.

Trac with lighttpd on CentOS

I spent a few hours today trying to figure out how to get trac working with lighttpd on CentOS with the standard packages from rpmforge. Like always this seams to be quite easy but then you spend ages on the little things.

First of all you need to install trac via yum which is quite easy: yum install trac
This is assuming you have lighttpd already installed


So here is the section you have to put in your /etc/lighttpd/lighttpd.conf you will also have to enable a few modules at the start most notably mod_fastcgi but please always check that you have all the modules enabled.

$HTTP["host"] == "trac.mypage.org" {

url.rewrite = ( "^/$" => "/root")

server.document-root = "/var/www/trac"
alias.url = (
"/trac_prefix/chrome/common/" => "/usr/lib/python2.4/site-packages/trac/htdocs/",
)

# rewrite for multiple svn project
url.rewrite-final = (
"^/trac_prefix/[^/]+/chrome/common/(.*)" => "/chrome/common/$1",
)

$HTTP["url"] =~ "^/trac_prefix/chrome/" {
}
else $HTTP["url"] =~ "^/root" {
fastcgi.server = (
"/root" => ( # if trac_prefix is empty, use "/"
(
# options needed to have lighty spawn trac
"bin-path" => "/usr/lib/python2.4/site-packages/trac/web/fcgi_frontend.py",
"min-procs" => 1,
"max-procs" => 1,
"bin-environment" => (
"TRAC_ENV_PARENT_DIR" => "/var/trac/",
),

# options needed in all cases
"socket" => "/tmp/trac.sock",
"check-local" => "disable",

# optional
"disable-time" => 1,

# needed if trac_prefix is empty; and you need >= 1.4.23
"fix-root-scriptname" => "enable",
),
),
)
}
}


There is nothing special with the paths and the rest if quite standard. The one thing to note is that I couldn't get trac to live properly in the root directory. As soon as you select a project it will error => So we rewrite the url to add "root" to the end. The rest should be pretty straight forward. There is no authentication in this example but this will follow in a further post.

CentOS help

Something people have asked me about is what to do when yum gives you the error
There are unfinished transactions remaining. You might consider running yum-complete-transaction first to finish them.
This is very simple

$ yum install yum-utils
$ /usr/sbin/yum-complete-transaction

Finished ;) Just a little cleanup of the completed transactions file

detex for CentOS

So another little porting effort. This time it is detex
DeTeX is a filter program that removes the LaTeX (or TeX) control sequences from the input so that the real content can be passed to a spell or diction checker.
I am using this for my dissertation to count the words used
detex dissertation.tex | wc
Quite a useful little tool. When I get time I might rewrite it in perl to make it more portable.

Download the [RPM]

[SRPM] and spec file:

Summary: Strips Tex and LaTex commands from a file
Name: detex
Version: 2.8
Release: 1
License: BSD
Group: Applications/Text
URL: http://www.cs.purdue.edu/homes/trinkle/detex/

Source: http://www.cs.purdue.edu/homes/trinkle/detex/%{name}-%{version}.tar
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root

Patch0: mallocandtroff.patch

BuildRequires: flex
BuildRequires: groff

%description
DeTeX is a filter program that removes the LaTeX (or TeX)
control sequences from the input so that the real content can be
passed to a spell or diction checker


%prep
%setup
%patch -p0

%build
%{__make} detex man-page prefix="%{_prefix}" CFLAGS="%{optflags} -DNO_MALLOC_DECL"

%install
%{__rm} -rf %{buildroot}
#%{__make} install DESTDIR="%{buildroot}"
%{__install} -Dp -m0755 detex %{buildroot}%{_bindir}/detex
%{__install} -Dp -m0644 detex.1 %{buildroot}%{_mandir}/man1/detex.1

%clean
%{__rm} -rf %{buildroot}

%files
%defattr(-, root, root, 0755)
%doc %{_mandir}/man1/detex.1*
%{_bindir}/detex

%changelog
* Tue Apr 21 2009 Hoffmann Geerd-Dietger - 2.8-1
- Initial package.


You will also need the little patch file
--- Makefile.orig 2009-04-21 01:50:44.735919044 +0100
+++ Makefile 2009-04-21 01:51:18.237692007 +0100
@@ -49,7 +49,7 @@
# Compile time flags, just uncomment the necessary lines
# Some say GNU make does not correctly handle += -- you may have to use :=
#
-DEFS =
+DEFS += -DNO_MALLOC_DECL
#
# Add -traditional for GNU cc on ISC 386/ix system and possibly others
# (reported by pinard@iro.umontreal.ca)
@@ -116,7 +116,7 @@
mv detex.c lexout.c

man-page:
- troff -man detex.1l
+ nroff -man detex.1l > detex.1

# If you want detex available as delatex, uncomment the last two lines of
# this target

lacheck port

And another port. This time a very useful little tool if you create latex documents.
Lacheck
LaCheck is a general purpose consistency checker for LaTeX documents.
It reads a LaTeX document and displays warning messages, if it finds
bad sequences. It should be noted, that the badness is very subjective.
LaCheck is designed to help find common mistakes in LaTeX documents,
especially those made by beginners.

Source RPM can be found at www.ribalba.de/geek/port/lacheck-1.26-1.src.rpm

Update: This RPM has been added to rpmforge

xpdf in CentOs

I wanted Xpdf on my Centos machine, but I could not find a binary that had the newest patch level. So I used http://mbrisby.blogspot.com/2007/06/xpdf.html and extended it. I respect poppler and just add the program xpdf. Further I patch some known bugs.
Download the source rpm here : xpdf-3.02-5.src.rpm

Thank you Carl for the nice spec file. Here is my extended one.

%define _prefix /usr
%define _version 3.02

Summary: open source viewer for Portable Document Format (PDF) files
Name: xpdf
Version: %{_version}
Release: 5
Source0: ftp://ftp.foolabs.com/pub/xpdf/xpdf-3.02.tar.gz
URL: http://www.foolabs.com/xpdf/
Group: Applications/Publishing
License: GPLv2
Patch0: ftp://ftp.foolabs.com/pub/xpdf/xpdf-3.02pl1.patch
Patch1: ftp://ftp.foolabs.com/pub/xpdf/xpdf-3.02pl2.patch
Patch2: patch-doc_sample-xpdfrc
Patch3: patch-xpdf_Object_h
BuildRoot: %{_topdir}/BUILD/%{name}-buildroot
Prefix: %{_prefix}



#Requires: t1lib
Requires: freetype > 2.0.5
Requires: htmlview
Requires: urw-fonts
Requires: xdg-utils
Requires: poppler-utils
Requires: xorg-x11-fonts-ISO8859-1-75dpi

BuildRequires: t1lib
BuildRequires: wxGTK
BuildRequires: t1lib-devel
BuildRequires: libpaper-devel
BuildPrereq: openmotif-devel
BuildPrereq: libX11-devel
BuildPrereq: freetype-devel >= 2.1.7
BuildPrereq: fileutils

%description
Xpdf is an open source viewer for Portable Document Format (PDF)
files. (These are also sometimes also called 'Acrobat' files, from
the name of Adobe's PDF software.) The Xpdf project also includes a
PDF text extractor, PDF-to-PostScript converter, and various other
utilities.

Xpdf runs under the X Window System on UNIX, VMS, and OS/2. The non-X
components (pdftops, pdftotext, etc.) also run on Win32 systems and
should run on pretty much any system with a decent C++ compiler.

Xpdf is designed to be small and efficient. It can use Type 1 or
TrueType fonts.

%prep
%setup -q
%patch -p1

%build

./configure --prefix=%{_prefix} --mandir=%{_mandir} --sysconfdir=/etc --with-freetype2-includes=/usr/include/freetype2

# ./configure \
# --prefix=%{_prefix}
# --mandir=%{_mandir}
# --sysconfdir=/etc
# --enable-multithreaded \
# --enable-wordlist \
# --with-x \
# --with-gzip \
# --enable-opi \
# # --with-appdef-dir=%{_datadir}/X11/app-defaults/ \
# --without-Xp-library \
# --with-t1-library \
# --with-freetype2-includes=/usr/include/freetype2/

make

%install
rm -rf $RPM_BUILD_ROOT
make DESTDIR=$RPM_BUILD_ROOT install

#poppler does this now. Stupid but works
rm $RPM_BUILD_ROOT%{_bindir}/pdffonts
rm $RPM_BUILD_ROOT%{_bindir}/pdfimages
rm $RPM_BUILD_ROOT%{_bindir}/pdfinfo
rm $RPM_BUILD_ROOT%{_bindir}/pdftops
rm $RPM_BUILD_ROOT%{_bindir}/pdftotext
rm $RPM_BUILD_ROOT%{_bindir}/pdftoppm

rm $RPM_BUILD_ROOT%{_mandir}/man1/pdffonts.1*
rm $RPM_BUILD_ROOT%{_mandir}/man1/pdfimages.1*
rm $RPM_BUILD_ROOT%{_mandir}/man1/pdfinfo.1*
rm $RPM_BUILD_ROOT%{_mandir}/man1/pdftops.1*
rm $RPM_BUILD_ROOT%{_mandir}/man1/pdftotext.1*
rm $RPM_BUILD_ROOT%{_mandir}/man1/pdftoppm.1*


%clean
rm -rf $RPM_BUILD_ROOT

%files
%defattr(-,root,root)
%doc ANNOUNCE COPYING CHANGES INSTALL README
%{_prefix}/bin/*
%{_mandir}/man1/*
%{_mandir}/man5/xpdfrc*
/etc/xpdfrc

%changelog
* Thu Nov 20 2008 Hoffmann Geerd-Dietger
- added 3.02pl2.patch
* Fri Aug 24 2007 Martin Brisby
- added 3.02pl1 patch
* Sat Jun 16 2007 Martin Brisby
- initial specfile



If you want to avoid the Pdf passwords I recommend to add this patch:

$OpenBSD: patch-xpdf_XRef_cc,v 1.4 2008/04/25 19:19:05 deanna Exp $
--- xpdf/XRef.cc.orig Thu Apr 24 19:13:00 2008
+++ xpdf/XRef.cc Thu Apr 24 19:50:06 2008
@@ -771,19 +771,19 @@ void XRef::setEncryption(int permFlagsA, GBool ownerPa
}

GBool XRef::okToPrint(GBool ignoreOwnerPW) {
- return (!ignoreOwnerPW && ownerPasswordOk) || (permFlags & permPrint);
+ return (1);
}

GBool XRef::okToChange(GBool ignoreOwnerPW) {
- return (!ignoreOwnerPW && ownerPasswordOk) || (permFlags & permChange);
+ return (1);
}

GBool XRef::okToCopy(GBool ignoreOwnerPW) {
- return (!ignoreOwnerPW && ownerPasswordOk) || (permFlags & permCopy);
+ return (1);
}

GBool XRef::okToAddNotes(GBool ignoreOwnerPW) {
- return (!ignoreOwnerPW && ownerPasswordOk) || (permFlags & permNotes);
+ return (1);
}

Object *XRef::fetch(int num, int gen, Object *obj) {