Page 1 of 2 12 LastLast
Results 1 to 10 of 20

Thread: converting .lit files to PDFs

  1. #1
    Join Date
    Jun 2007
    Beans
    1,745

    converting .lit files to PDFs

    I found this a bit annoying, but the conventional method of converting .lit files to PDFs is to use open office or abiword and copy and paste the contents from firefox, then choose save as PDF or export to PDF. As a result I wrote this shell script, it has two dependencies, convlit and htmldoc
    Code:
    sudo apt-get install convlit htmldoc
    Then you want to download the attachment(to your home folders a good idea), drop into a terminal and run:
    Code:
    chmod +x lit2pdf.txt
    sudo mv lit2pdf.txt /usr/bin/lit2pdf
    Then find any .lit file you want, right click it, and open it with "lit2pdf", using the custom command box. When it is done you will be told how many files were extracted and asked if you wish to delete the .lit file now.

    Let me know if you get any errors etc.
    Attached Files Attached Files
    Last edited by scragar; April 30th, 2009 at 04:24 PM.
    Licat volaré si superturgum Aquila volat

  2. #2
    Join Date
    Aug 2006
    Beans
    171

    Re: converting .lit files to PDFs

    A few things, first, you need to sudo apt-get install convlit htmldoc

    then sudo mv lit2pdf.txt /usr/bin/lit2pdf

    I ran the script on a few .lit files and the dialog comes up saying 0 files were created, then it gives me the option to delete the lit file

    Any suggestions?

    PS thanks for the script

  3. #3
    Join Date
    Nov 2008
    Beans
    58

    Re: converting .lit files to PDFs

    Is there any other simpler way to do it? I am not good with scripts.

  4. #4
    Join Date
    Jun 2007
    Beans
    1,745

    Re: converting .lit files to PDFs

    Quote Originally Posted by graphius View Post
    A few things, first, you need to sudo apt-get install convlit htmldoc

    then sudo mv lit2pdf.txt /usr/bin/lit2pdf

    I ran the script on a few .lit files and the dialog comes up saying 0 files were created, then it gives me the option to delete the lit file

    Any suggestions?

    PS thanks for the script
    That's strange, try this edit:
    Code:
    #!/bin/bash
    
    CONFDIR=~/.lit2pdf
    CONVLIT=****
    MODE=continuous
    DEBUGMODE=1      ## 1 = on, 0 = off
    
    ### please don't go complaining if you edit after here and break it.
    
    FILE=$1  ## basic init
    MSGBOX=$(which gxmessage) || MSGBOX=xmessage
    NUM=0
    
    SUBDIR="$CONFDIR/`basename "$FILE"`" ## generate a sub dir path, more or less anyway :p
    
    function DebugMsg {
    	if [ $DEBUGMODE == 1 ]; then
    		$MSGBOX $1
    	fi
    }
    
    
    if [ -f "$FILE" ]; then ## we are working with a valid input file
    	mkdir -p "$CONFDIR" ## make the config dir if it doesn't exist
    
    	while [ ! mkdir "$SUBDIR-$NUM" ]; do ## generate a unique sub dir
    		NUM=`expr $NUM + 1`
    	done;
    
    	SUBDIR="$SUBDIR-$NUM" ## and a bit more config here, now we know our dir
    	NUM=0
    
    	DebugMsg "$SUBDIR"
    
    	$CONVLIT "$FILE" "$SUBDIR/" ## extract the lit file
    
    	DebugMsg "`ls $SUBDIR`"
    
    	for htm in $SUBDIR/*.htm $SUBDIR/*.html; do ## for all the HTML files
    		if [ -f "$htm" ]; then ## double check it exists
    
    			htmldoc --$MODE -f "./`basename "$htm"`.pdf" "$htm" ## convert it to PDF
    			NUM=`expr $NUM + 1` ## increase counter
    		fi
    	done ## end loop
    
    	rm -rf "$SUBDIR" ## remove our little unique dir now
    
    	## let the user know we are done, and if they click "delete" we remove the input file as well.
    	$MSGBOX -buttons "Delete:0,Leave:1" "$NUM file(s) created."$'\n'"Delete .lit file now?" && rm $FILE;
    
    fi
    And let me know what the first two messageboxes say.
    Licat volaré si superturgum Aquila volat

  5. #5
    Join Date
    Jan 2008
    Beans
    21

    Re: converting .lit files to PDFs

    I didn't post the original question but am seeing the same thing. A couple of points.

    1. when I attempted to sudo apt-get install convlit heredoc I get the complaint that convlit is the lastest already and apt is unable to find heredoc.

    2. Whether I run the initial downloaded script or the new one you posted above I get the same results from X Message:

    0 file(s) created.
    Delete .lit file now?

    I thought at first it might be permission related and made sure the script is owned by me. But no change, same result.

    So I then copied the script to a folder I use as a catchall to run tests in my home and attempted to run the script from the command line as shown below with the results. It looks to me as convlit is choking and perhaps this is about heredoc. I don't know this software and am just about to start Googling. Initially I assumed you meant htmldoc. Maybe this is wrong.


    I hope this helps, this is a great idea, I know Calibre will open Lit files but I really like to keep as little as possible on my netbook and want to reduce apps wherever I can this script would help in that.

    Code:
    stat@stat:~/Music$ ./lit2pdf.txt To\ Kill\ a\ Mockingbird.lit 
    ./lit2pdf.txt: line 19: [: mkdir: unary operator expected
    +---[ ConvertLIT (Version 1.8) ]---------------[ Copyright (c) 2002,2003 ]---
    ConvertLIT comes with ABSOLUTELY NO WARRANTY; for details
    see the COPYING file or visit "http://www.gnu.org/license/gpl.html". 
    This is free software, and you are welcome to redistribute it under 
    certain conditions.  See the GPL license for details.
    LIT INFORMATION.........
    DRM         =  1    
    Timestamp   =  4b302d20 
    Creator     =  00000000 
    Language    =  00000409 
    Writing out "To_Kill_A_Mockingbird" as "To Kill A Mockingbird.htm" ...
    Successfully written to "/home/stat/.lit2pdf/To Kill a Mockingbird.lit-0/To Kill A Mockingbird.htm".
    
    Writing out "RW_~Cover01" as "~Cover01.jpg" ...
    Successfully written to "/home/stat/.lit2pdf/To Kill a Mockingbird.lit-0/~Cover01.jpg".
    
    Writing out "RW_~Cover02" as "~Cover02.jpg" ...
    Successfully written to "/home/stat/.lit2pdf/To Kill a Mockingbird.lit-0/~Cover02.jpg".
    
    Writing out "RW_~Cover03" as "~Cover03.jpg" ...
    Successfully written to "/home/stat/.lit2pdf/To Kill a Mockingbird.lit-0/~Cover03.jpg".
    
    Writing out "RW_~Cover04" as "~Cover04.jpg" ...
    Successfully written to "/home/stat/.lit2pdf/To Kill a Mockingbird.lit-0/~Cover04.jpg".
    
    Writing out "RW_~Cover05" as "~Cover05.jpg" ...
    Successfully written to "/home/stat/.lit2pdf/To Kill a Mockingbird.lit-0/~Cover05.jpg".
    
    Exploded "To Kill a Mockingbird.lit" into "/home/stat/.lit2pdf/To Kill a Mockingbird.lit-0/".

  6. #6
    Join Date
    Jun 2007
    Beans
    1,745

    Re: converting .lit files to PDFs

    Yeah, OP updated, my mistake writing heredoc, it's htmldoc, dunno what made me write heredoc.

    It's not working for you because you didn't install htmldoc, sorry for having written the wrong thing.
    Licat volaré si superturgum Aquila volat

  7. #7
    Join Date
    Jan 2008
    Beans
    21

    Re: converting .lit files to PDFs

    Well, I certainly have done something incorrect but not sure what. I have (and always had htmldoc (version 1.8.27) and convlit.
    1. I downloaded your script again to my home directory - scripts
    2. chmod +x lit2pdf.txt to make it exectuable
    3. sudo mv lit2pdf.txt /usr/bin/lit2bin as shown above in your instructions.
    4. Then I select the lit file I want to convert and select the command I want to use in custom command. Your instructions say to use lit2pdf to convert the file but that seems counter intuitive since in step 3 we changed the name to lit2bin as you instructed above so I chose lit2bin from the usr/bin folder thinking that is what you meant. I also changed the file to lit2pdf but same result so I don't think it has anything to do with the name of the file and probably nothing to do with where it is as long as it is executable.

    Regardless of whether I use that or just use a copy of your script that I downloaded and left in the same folder to test with (after making executable) I get the same results as already noted. Pretty sure I am missing something and just not sure what it is. This would seem relatively straight forward and to be honest at this point it is less about using this tool than trying to figure out what I did wrong or am doing wrong.
    Last edited by statmonkey; April 30th, 2009 at 06:44 AM.

  8. #8
    Join Date
    Aug 2007
    Beans
    2

    Re: converting .lit files to PDFs

    couldn't get this to work so I made this script
    Code:
    #!/bin/bash
    FILE="$1"
    NAME="${FILE%.*}"
    
    if [ -f "$FILE" ]; then # check that input file exists
    	**** "$FILE" "$NAME/" # convert lit to htm
    	for HTM in "$NAME"/*.htm; do
    		htmldoc --continuous --header ... --footer ..1 -f "$NAME.pdf" "$HTM" # convert htm to pdf
    	done
    	rm -rf "$NAME/" # remove temporary files
    fi
    Last edited by qwerty1212; May 28th, 2009 at 04:57 PM.

  9. #9
    Join Date
    Nov 2007
    Location
    Vegas
    Beans
    Hidden!
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: converting .lit files to PDFs

    i just used scragar's script successfully but the thread was a little confusing. anyway it took all of 5 minutes or less to set this up and i just glanced over my newly converted `lit to pdf' book doing this:


    in terminal run:

    $ sudo apt-get install convlit htmldoc
    download lit2pdf.txt (to home folder)

    in terminal run:


    $ chmod +x lit2pdf.txt
    $ sudo mv lit2pdf.txt /usr/bin/lit2pdfv

    open .lit file you want to read by:

    * right click .lit file
    * open with `lit2pdf' (using custom command box)

    says how many files were extracted and asks to delete .lit file

    * hit `delete' button (converts .lit file to pdf automatically)

  10. #10
    Join Date
    Apr 2006
    Beans
    35

    Re: converting .lit files to PDFs

    Hey, great script. Works great, save for one thing. I think you could/should change the following line:
    Code:
    for htm in $SUBDIR/*.htm $SUBDIR/*.html; do ## for all the HTML files
    to have quotes like this:
    Code:
    for htm in "$SUBDIR"/*.htm "$SUBDIR"/*.html; do ## for all the HTML files
    It fixes a problem of spaces in the folder name.

    Before calling htmldoc, I added this line, to change the title of the resulting PDF. It's ugly & hacky, but it gets something better than the 1st line of text as the PDF title.

    Code:
    sed -i "s,\<title\>.*\<,title\>`basename "$htm"`\<\/,g" "$htm"
    I also added
    Code:
    --header /t
    to the htmldoc line, so that I get page numbers & a title on the top of each page.

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •