View Full Version : LRF2LRF (Font and Margin modifyer)

06-13-2008, 07:10 PM
Hi All,
Iíve created a tool for my personal usage thought others might find it useful.

The tool is called LRF2LRF. The main design of the tool is to change the font size and margins of LRF books. I designed this tool because I tend to find that most if not all LRF books tend to have huge fonts and large margins making. Of course users of this tool can also use it to increase the font and margin size as well.

The design:
This tool is a Perl script that calls Calibreís lrf2lrs to generate the LRS file. Once the file is modified then calls LRS2LRF to create the LRF file once again.

Known Issues:
- There is a bug in Calibre's lrs2lrf tool that does not create the Header or Footer in the modified LRF file. (Calibre Ticket #909 (
- Right Margin does not change (Top/Bottom/Left) margins can be changed (Calibe Ticket #911 (

Below are some sample LRF files

This tool requires Calibe to run.
1) Put the script in the same location as the Calibe tool. (where lrf2lrs and lrs2lrf is located)
e.g. C:\Program Files\Calibe

The tool is a command line tool to run LRF2LRF

C:\My Books\> lrf2lrf -s 80 myBook.lrf

if no file name is passed "-o mynewname.lrf" the existing LRF (myBook.lrf) file will be modified.
C:\My Books\> lrf2lrf -o myNEWBook.lrf -s 80 myBook.lrf

06-13-2008, 07:44 PM
And where would one find this tool?

06-15-2008, 01:10 AM
X, first of all, have some karma for developing software for the Sony Reader! Secondly, how does one use it? :) Say I want to enlarge the text font for a particular book. I tried several combinations of command strings on my test book, and all I was able to do was enlarge the title.

06-15-2008, 04:55 AM
Hi Jeff,

Thank you.

Just a FYI there is a help just type "lrf2lrf -h" from the command line and the help page will print.

There are two ways to change the fonts.

First if you know the exact font size you want to change type this command.

lrf2lrf -f 100,150 MyeBOOK.lrf

The "100" is the existing 10pnt Fonts that you want to change. The "150" (15pts) is the new font size you want for the book.

100 = 10pts
150 = 15pts
Note this will change every 10pts to 15pts

Second is a tad harder, but very doable. You have to find the TextStyle uinqie ID. There is a uniqe ID for each font style in the reader. This is done by typing the following command

lrf2lrf -e MyeBOOK.lrf

What gets displayed is the listing below
Note the text that occures the most is TextStyle ID 317 it also has a font size of 80 (8pts)

TextStyle ObjId=310 Fontsize = 160
TextStyle ObjId=315 Fontsize = 110
TextStyle ObjId=317 Fontsize = 80
Recommend TextStyle = 317
Found TextStyle = 315 Occurrence = 14
Found TextStyle = 363 Occurrence = 2
Found TextStyle = 317 Occurrence = 79

Now that you have the TextStyle ID (objID) and the Font sizes. Determine which is the one you want to change and pass the ID with the new font size as described below

lrf2lrf -x <TextStyle ID> -s <My New Font size> MyBook.lrf

If my explanation does not clear things up.

Please run lrf2lrf -e <your LRF book> and post the output on the board.


06-15-2008, 05:46 AM
Looks good, very useful for people like me that often want to get rid of margins and make the font size more usable... I'm currently at ~7.8pt and dropping. Looking for the point where I get most on the screen without killing my reading speed through too-small text.


06-30-2008, 02:56 PM
Fixed some defects now on version 1.01

07-03-2008, 03:11 PM
Fixed a defect, the '-x' switch did not work.

The tool now removes the temp files created by the LRF2LRS extraction.


07-24-2008, 04:27 AM
I'm a newb, but I can't get the script to run. I've put the lrf2lrf file in the calibre directory, but when i go to cmd window and type in lrf2lrf or anything else suggested here it says "lrf2lrf is not recognized as an internal or external command, operable program or batch file."

07-24-2008, 10:11 PM
Do you have Perl installed on your OS? What OS are you using?
If No you need to install it.
If you have windows/Mac you can download ActiveState Perl. It's free and works great.

Locate where the 'perl.exe' is and make sure the path of the perl executable is on the same path of the first line in the script


If you install active state I recommend you use the default path "C:\perl"

Then you can change the first line in the script to



08-15-2008, 08:10 PM
Hi Everyone
I've uploaded an executable version of the perl script. This exe does not require the installation of perl. Just unzip the file and place it in your calibre directory to use the script.


08-25-2008, 12:03 PM
Thank you.

Very useful. I have some Gutenberg books books converted from HTML to .lit and then into .lrf. All of them had varying font and margins depending an when they were downloaded and converted into .lit

This helps me standardize all of them, great work. Have some karma.

PS: I wonder if this sort of feature can be incorporated into Calibre to run from its gui?

08-25-2008, 07:43 PM
Hi EssKayEss,
I'm glad you find the tool useful.

It wouldn't be too hard from the GUI side to add support for a tool called LRF2LRF. However the harder part would be to write the LRF2LRF tool using Calibre's plugin architecture.

I agree a feature like this is probably best kept in the Calibre realm. It doesn't make sense to have a LRF2LRF tool all on it's own.

Unfortunately I do not know Python and am limited in time. So I chose the quickest path to fill my need to be able change the font size and margins of existing LRF files.

Anyhow thank you for the karma.


11-15-2008, 10:00 AM
I would like to use this utility but I can't get it to work. It produces the output file OK, but I can't see any changes - I'm trying to reduce the font from 10 to 8 pt, and reduce margins too.

This is the command line I am using:

lrf2lrf -s 80 -t 0 -b 0 -l 0 -r 0 -o NewLrfFile OldLrfFile

and this is the output:

Reformatting Silverberg-Live-Again.lrf
Parsing LRF...
Creating XML...
LRS written to .Silverberg-Live-Again.lrs.tmp
LOOKING FOR 72, 75, 80
Parsing LRS file...
Writing to output file...
Output written to E:\My Documents\My Library\Reader\Books\Silverberg-Live-Again.

This exe file was created with the evaluation version of Perl2Exe.
For more information visit
(The full version does not display this message with a 2 second delay.)

Any thoughts?

11-15-2008, 03:11 PM
Well written Trouble report, thank you!

The commands you are using is correct. However you'll need to specify yet another switch.

What happens is the software tries to guess which is the font you want to change by looking at the highest occurrence. This works most of the time, but there are a few LRF out there that don't follow this pattern.

What you have to do is run this command

lrf2lrf -e Silverberg-Live-Again.lrs

This will produce a report with the Text and font size

The output looks something like this

Parsing LRF...
Creating XML...
LRS written to .a.lrs.tmp
TextStyle ObjId=52 Fontsize = 100
Recommend PageStyle = 56
Found PageStyle = 56 Occurrence = 2
Found PageStyle = 54 Occurrence = 2
Recommend TextStyle = 52
Found TextStyle = 52 Occurrence = 2

In my example there was only one font used but you'll have more. In the example you'll see I spit out the TextStyle, ObjID, and fontsize. (They are underlined above)

Find the correct Object ID and pass that value using the '-x' switch

lrf2lrf -x 52 -s 80 -t 0 -b 0 -l 0 -r 0 -o NewLrfFile OldLrfFile

Note do not use "52" use the object ID listed when you run the '-e' command. From your trouble report it should be 72,75, or 80.

11-16-2008, 05:20 AM
Thanks for your help, and such a nice little utility! This is just the thing I need as I like to reformat the lrfs I download in order to get as much text as possible on the screen (smaller fonts and margins).

This is the output using -e:

lrf2lrf -e "Silverberg-Live-Again.lrf"
Parsing LRF...
Creating XML...
LRS written to .Silverberg-Live-Again.lrs.tmp
TextStyle ObjId=75 Fontsize = 100
TextStyle ObjId=77 Fontsize = 100
TextStyle ObjId=78 Fontsize = 100
TextStyle ObjId=81 Fontsize = 60
Recommend PageStyle = 72
Found PageStyle = 72 Occurrence = 20
Recommend TextStyle = 75
Found TextStyle = 81 Occurrence = 2
Found TextStyle = 77 Occurrence = 20
Found TextStyle = 75 Occurrence = 22
Found TextStyle = 78 Occurrence = 7

I have converted the lrf to lrs and found that 75 is used for chapter numbers, whereas 77 is used for the actual body text. Note that objid 77 has 20 occurrences, whereas objid 75 has 2 more - so when I used the -s switch before, it would have changed object 75 and not 77.

I also tried the following command:

lrf2lrf -f 100,80 -o "" "Silverberg-Live.Again.lrf"
Parsing LRF...
Creating XML...
LRS written to .Silverberg-Live-Again.lrs.tmp
LOOKING FOR 72, 100,80, 80
Parsing LRS file...
Writing to output file...
Output written to E:\My Documents\My Library\Reader\Books\

This did not work - for some reason it is not looking for objid 77. If we could get this to work it would be great - I could automate conversions by just using -f, and not have to use -e and -x for each book.

I got what I wanted using this command:

lrf2lrf -x 77 -s 80 -o "Silverberg-Live-Again.lrf" "Silverberg-Live-Again.lrf"
Parsing LRF...
Creating XML...
LRS written to .Silverberg-Live-Again.lrs.tmp
LOOKING FOR 72, 77, 80
Parsing LRS file...
Writing to output file...
Output written to E:\My Documents\My Library\Reader\Books\Silverberg-Live-Again.lrf

I probably want to change the font size for the chapter numbers too - is it possible to have multiple objids for the -x command? (But fixing the -f command would be just as good).

The other thing that occurs to me :bulb2: - when using -s without -x, I believe lrf2lrf uses the maximum number of occurrences to decide which objid to change. This does not work with the Silverberg book because there are in fact more chapter numbers; could the size of the textblock be considered too?

As an example, here are the first two textblocks from a page from the book:

<Page pagestyle="72" objid="28">

<TextBlock objid="20" blockstyle="76" textstyle="75">
<P>1</P><CR /></TextBlock>

<TextBlock objid="21" blockstyle="76" textstyle="77">
<P>The lamasery rose steeply from the top of the bluff on the Marin County side of the Golden Gate. Feeling a faint cramp in his left calf, John Roditis got out of the car near the toll plaza and, stretching and kicking, looked across the water at the gleaming yellow building, windowless, sleek, ineffably holy as a fountainhead of good karma. It was an extraordinarily warm day. yada yada yada</P><CR /></TextBlock>


The length of the inner xml for TextBlock 77 is always much longer than for 75, so that should be the objid to change. I guess this will be true for most ebooks - there will always be an TextBlock element that is much longer than all the others.

I hope you don't mind my suggestions and that they are of some help.


11-16-2008, 09:09 PM
Thanks for point out the broken '-f' switch. It must have broke when I added the -x -s options.

As for the multi objID that is a good idea, I'll look into it.


07-23-2009, 04:24 PM

This project and program is still alive and current?

I was searching for a time for such tool, I don't know why it's not more popular, since .lrf conversions from many people suffers from terrible font sizes and types.

Maybe, would not be a good suggestion and add-on to merge inside Calibre full project?


07-24-2009, 03:21 PM
HI Jotas,

Well I'm still around as I wrote the tool, but there hasn't been much additional work to it. It did what it was designed to do which was remove the margins and change the font size, I haven't needed more features or have been asked for more features.

Of late I'm finding out I don't store LRF anymore as a format it is too difficult to convert and get good results, so most of my books are in MOBI/LIT/ePUB and I convert them to LRF when I want to read them on my reader.

However I do use the tool when I find books exclusive to the LRF format (mainly older books here at mobileread.)

The Calibre folks are open to adding this feature to their tool their restriction however is it must be in Python and that is a language I do not know this tool was written in Perl.


07-25-2009, 12:20 PM

I understand. Yes, I agree, .LRF and Sony continues to be tricky.

Thanks anyway for your program and work. Hope Calibre can consider add such a basic and useful idea in future versions for existing .LRF library files.