![]() |
#1 | ||||||||||||||
Connoisseur
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 98
Karma: 122982
Join Date: Apr 2010
Location: Humboldt County, California
Device: ipad, iPod touch, JetBook Lite
|
pdfreflow: reflow text PDFs
PDFReflow is a utility that reflows PDF text. Its input is a PDF document, to which it reflows the text, removes page number, header, footers, and hyphenation, and generates an HTML file output.
The reflow logic for PDFReflow is in the command line utility pdfreflow. The graphical user interfaces also uses the pdftohtml command to generate the XML input for pdfreflow Graphical User Interface There is now a graphical user interface for Windows, Mac, and Ubuntu (actually, any platform that runs java) Windows: Download the attached PDFReflow-0.8.6.1-Setup.zip. Extract PDFReflow-0.8.6.1-Setup.exe from the zip file, and run it. It contains all the necessary binaries (ie pdfreflow.exe and pdftohtml.exe) to run. Requires Windows XP or newer. You must have Java installed. You can download java at http://java.com/download. Mac: Download the attached PDFReflow-0.8.6.1.dmg.zip. Extract PDFReflow-0.8.6.1.dmg from the zip file, open it, and copy PDFReflow.app into your /Applications folder. Don't install Java, as Mac comes with Java installed. Requires Mac OS X Leopard and Snow Leopard. Ubuntu, Linux: Download PDFReflow-0.8.6.1.jar.zip. Extract PDFReflow-0.8.6.1.jar from the zip file. You must separately download the pdftohtml and pdfreflow command line utilties, and they must be in your path. Java must be installed. Download java at http://java.com/download. To run: Quote:
In the attached pdfreflow-0.8.6.zip file is a version that will run under Windows XP, Mac OSX 10.5 Leopard, and Ubuntu 8.04 (and later). There is also pdfreflow.html, which is documentation of how to use the command, and how to find a prebuilt version of pdftohtml from Poppler. SynopsisThe open source of pdfreflow is copyrighted under GNU GPL, and source is available at SourceForge. pdfreflow [options] [filename] DescriptionPdfreflow, in conjunction with pdftohtml, will convert a PDF into a reflowed HTML file. Pdfreflow operates on the XML output from pdftohtml (from the Poppler utilities), converting it into an HTML file. To get the XML input for pdfreflow, use pdftohtml as follows: FilesQuote:
General Usage Pdfreflow is oriented for operating on ebook PDFs, text based only, with minimal formatting, the kind of formatting you would get reading a fiction novel. By default pdfreflow expects justified text, but you can specify the input is rag right with the following option: Quote:
You might not want to reflow every page in your ebook. To specify which pages are NOT to be reflowed, use the following option: Quote:
Cropping While pdfreflow does its best to remove page numbers, headers and footers, you may have to assist by specifying the cropping options, ‑‑top=TOP_Y and ‑‑bottom=BOTTOM_Y. To find the Y values of a header or footer, you need to look inside the .xml file and find line of text that contains the header or footer. A sample entry looks as follows: Quote:
Centered Text Pdfreflow does its best to detect centered text. Sometimes, especially with rag right text, it is hard to detect the center point. To improve the center detection, you can specify a line in your document that is centered by specifying the page number and line number of a centered line. For example, if the 2nd line on page 3 is a centered line, you specify this with page:line argument to the ‑‑center option as follows (page numbers and line numbers both start at 1). Quote:
Quote:
It is also possible to only reflow a subset of the ebook by specifying the ‑‑first=FIRSTPAGE and ‑‑last=LASTPAGE options. This is useful if a book has sections with vastly different formatting. Create a different HTML file for each differently formatted section, and either concatenate the files together, or if you are creating an e-book, this step is not necessary as it is possible to specify multiple HTML files as input to ebook creation software. Quote:
If the filename command line argument is specified, file suffix is replace with .html and the ouput is written to that file, i.e. an input file of mybook.xml has an output file mybook.html. If no input file is specified, standard in used as the input, and standard out is the output. OptionsQuote:
Here is the usage output for pdfreflow. ExampleCode:
usage: pdfreflow [options] [inputfile]
Options:
--absolute font sizes are the same as the original document
(not the default)
-b, --bottom=MAXTOP crop text whose top is greater than or equal to maxtop
-c, --center=SPEC argument is page:line, ie 2:1 is line 1 on page 2
is a centered line (sometimes this hint is needed)
-d, --dontreflow=PAGES don't reflow comma separated page ranges,
i.e. "1,2,4-9,100"
-f, --first=FIRSTPAGE starting page (default is 1)
-l, --last=LASTPAGE ending page (default is last page of the document)
‑‑nonfiction for books that use block quoting at the same
inset as the paragraph indent
-r, --ragright text is rag-right, NOT justify (default is justify)
-t, --top=MINTOP crop text whose top is less than or equal to mintop
‑‑shortlines paragraphs end with short lines (only necessary
for rag right documents with no paragraph
indent and no after paragraph spacing.
--showdebug print debugging options
-v, --version print current version
-?, --help print this help
Options can be combined. An example using a combination of the options in the description section is: TroubleshootingQuote:
While pdfreflow tries it best, sometimes it can not correctly reflow all documents. Here are some tips to get a better output document. LimitationsParagraph are too large If your book does not have paragraph indenting or vertical spacing after every paragraph, too much text may be reflowed into each paragraph. You might try the ‑‑shortlines option. The argument is a percentage between 1 and 100. If 0 is specified, you get the default value (currently 80). This percentage is used against the longest line width in the document, and lines that are shorter than this percentage are considered the end of a paragraph. Quote:
If your input document is not justified, make sure you specified the ‑‑ragright option. Pdfreflow is configured to deal with fiction, which often has indented paragraphs and/or vertical spacing after a pararaph. If your book has indenting, but is not fiction with dialog, try using the ‑‑nonfiction option. Quote:
There are binaries for Windows XP, Ubuntu 8.04, and Mac OSX 10.5 (and later) attached to this post. The open source of pdfreflow is copyrighted under GNU GPL, and source is available at SourceForge. Getting pdftohtmlTo get a copy of pdftohtml, without building it from source, here are some options: Ubuntu: Use Synaptic Package Manager to fetch poppler-utils Macintosh: Download Calibre for Mac. There is a copy of pdftohtml inside of Calibre.app under /Applications/calibre.app/Contents/Frameworks/ Quote:
Quote:
Last edited by Pranananda; 05-29-2010 at 04:06 AM. Reason: see release notes for 0.8.6.1 user interface |
||||||||||||||
![]() |
![]() |
![]() |
#2 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,213
Karma: 12890
Join Date: Feb 2009
Location: Amherst, Massachusetts, USA
Device: Sony PRS-505
|
Thanks for uploading this.
Popper's pdftohtml is what calibre uses when converting PDFs, isn't it? So the output should be a lot like calibre's, except it'll give you HTML, which is nice. (You'd have to resort to some workarounds to save it as html using calibre alone...) Or does someone know better than I? I assume the Ubuntu executable will work under 10.04 too? |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Connoisseur
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 98
Karma: 122982
Join Date: Apr 2010
Location: Humboldt County, California
Device: ipad, iPod touch, JetBook Lite
|
frabjous,
Yes, calibre uses pdftohtml. People who don't want to build pdftohtml from source can use the copy found inside of calibre. But if you are on Ubuntu, you can use Synaptic to install poppler-utils. The output of pdfreflow is going to have multiline paragraphs rather than the 1 line paragraphs of the default pdftohtml. The Ubuntu executable will also run on 10.4 (I just tried it.) |
![]() |
![]() |
![]() |
#4 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,213
Karma: 12890
Join Date: Feb 2009
Location: Amherst, Massachusetts, USA
Device: Sony PRS-505
|
Nice tool.
It doesn't seem to work with double spaced PDFs, though you're aiming towards PDF ebooks which are unlikely to come double spaced. (This problem may be on the pdftohtml end... not sure.) |
![]() |
![]() |
![]() |
#5 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 2,623
Karma: 3000161
Join Date: Jan 2009
Device: Kindle PW3 (wifi)
|
![]()
It did process something but I am a little dumb how to use it. I put it in the same folder as my working file to begin with. I thought it could not harm.
![]() roger@roger-laptop:~$ cd /home/roger/Bureau/pdfreflow-0.8.3/ubuntu/ roger@roger-laptop:~/Bureau/pdfreflow-0.8.3/ubuntu$ pdftohtml -xml Bowden\,\ Mark\ -\ Killing\ Pablo.pdf Page-1 Page-2 .../... Page-183 Page-184 roger@roger-laptop:~/Bureau/pdfreflow-0.8.3/ubuntu$ But I do not know what to do with the resulting xml file. Sorry for that. Last edited by roger64; 05-13-2010 at 06:01 AM. |
![]() |
![]() |
Advert | |
|
![]() |
#6 |
Connoisseur
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 98
Karma: 122982
Join Date: Apr 2010
Location: Humboldt County, California
Device: ipad, iPod touch, JetBook Lite
|
Frabjous,
Yes, pdfreflow is not going to like double spaced text, as it will see the double spaced lines as new paragraphs. I can add an option to make this work though. --update I think I can make this work without adding a new option, but just detect that the lines are double spaced. I'll put this in the next update. Last edited by Pranananda; 05-13-2010 at 03:32 AM. |
![]() |
![]() |
![]() |
#7 |
Connoisseur
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 98
Karma: 122982
Join Date: Apr 2010
Location: Humboldt County, California
Device: ipad, iPod touch, JetBook Lite
|
Roger64
Try pdfreflow Bowden\,\ Mark\ -\ Killing\ Pablo.xml Or perhaps ./pdfreflow Bowden\,\ Mark\ -\ Killing\ Pablo.xml Also, read the pdfreflow.html to see the command line options. |
![]() |
![]() |
![]() |
#8 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 2,623
Karma: 3000161
Join Date: Jan 2009
Device: Kindle PW3 (wifi)
|
Thank you
![]() pdfreflow is amazingly quick and efficient for reflowing text-based PDF thru xml !! A great tool. Congratulations and thanks. ![]() PS: With Ubuntu I needed to use: ./pdfreflow ... ![]() Last edited by roger64; 05-13-2010 at 06:07 AM. |
![]() |
![]() |
![]() |
#9 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,213
Karma: 12890
Join Date: Feb 2009
Location: Amherst, Massachusetts, USA
Device: Sony PRS-505
|
|
![]() |
![]() |
![]() |
#10 |
Connoisseur
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 98
Karma: 122982
Join Date: Apr 2010
Location: Humboldt County, California
Device: ipad, iPod touch, JetBook Lite
|
I've posted pdfreflow-0.8.4.zip to the original post. Here are the release notes:
|
![]() |
![]() |
![]() |
#11 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,213
Karma: 12890
Join Date: Feb 2009
Location: Amherst, Massachusetts, USA
Device: Sony PRS-505
|
Seems to work well now with double-spaced PDFs... or at least the one I tried on. Thanks a lot!
My dream tool for something like this would be able to recognize footnotes and treat them appropriately, but knowing how PDFs work (and the fact that they don't semantically mark footnotes as such), this is probably a pipe dream. A more reasonably accomplished feature would break up typographical ligatures, though I could script this myself easily enough with sed or similar. roger, if you want to be able to use it without using ./ before it, just copy the executable into your PATH, such as into the ~/bin/ folder (restart bash if need be). Last edited by frabjous; 05-13-2010 at 09:56 PM. |
![]() |
![]() |
![]() |
#12 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 2,623
Karma: 3000161
Join Date: Jan 2009
Device: Kindle PW3 (wifi)
|
|
![]() |
![]() |
![]() |
#13 |
Connoisseur
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 98
Karma: 122982
Join Date: Apr 2010
Location: Humboldt County, California
Device: ipad, iPod touch, JetBook Lite
|
I've posted pdfreflow‑0.8.5.zip to the original post. Here are the release notes:
Last edited by Pranananda; 05-24-2010 at 03:00 AM. |
![]() |
![]() |
![]() |
#14 |
Connoisseur
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 98
Karma: 122982
Join Date: Apr 2010
Location: Humboldt County, California
Device: ipad, iPod touch, JetBook Lite
|
I've posted pdfreflow-0.8.6.zip to the original post. Here are the release notes:
|
![]() |
![]() |
![]() |
#15 |
Evangelist
![]() ![]() ![]() ![]() ![]() ![]() Posts: 404
Karma: 664
Join Date: Dec 2009
Device: Kindle Paperwhite, Kindle DX, Kobo Aura HD
|
This sounds like a very useful tool. Could you also make a front-end, windows GUI for this? I'm not very good with DOS stuff. Thanks.
|
![]() |
![]() |
![]() |
Tags |
pdf, reflow, utility |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
<pre> tags and no text reflow in EPUB | sergio blum | Calibre | 24 | 10-14-2010 08:07 PM |
What is the best reader read real reflow PDF ( not refow text ) ? | familyhandh | Which one should I buy? | 1 | 08-05-2010 08:44 AM |
Help with reflow text file | siulayhumga | Workshop | 9 | 07-31-2010 06:36 PM |
80-column text reflow - Hanlin V3 | elewton | Other formats | 1 | 02-10-2009 05:00 AM |
Now that the Sony 505 can reflow PDFs ... | mollybo | Sony Reader | 6 | 07-27-2008 11:29 PM |