10-19-2010, 11:19 AM | #16 |
Connoisseur
Posts: 79
Karma: 10
Join Date: Oct 2010
Device: Kindle 3
|
Still getting a funky bunch of errors, after which the Terminal hangs and doesn't give back the "$":
usage: mktemp [-d] [-q] [-t prefix] [-u] template ... mktemp [-d] [-q] [-u] -t prefix usage: mktemp [-d] [-q] [-t prefix] [-u] template ... mktemp [-d] [-q] [-u] -t prefix rm: : No such file or directory Reading metadata... ./pdfstretch.sh: line 14: ebook-meta: command not found ./pdfstretch.sh: line 15: ebook-meta: command not found ./pdfstretch.sh: line 16: ebook-meta: command not found Author(s) recognized as . Title recognized as . Language recognized as . Analyzing page geometry... ./pdfstretch.sh: line 23: : No such file or directory usage: mktemp [-d] [-q] [-t prefix] [-u] template ... mktemp [-d] [-q] [-u] -t prefix usage: mktemp [-d] [-q] [-t prefix] [-u] template ... mktemp [-d] [-q] [-u] -t prefix ./pdfstretch.sh: line 26: : No such file or directory ./pdfstretch.sh: line 27: : No such file or directory cp: fts_open: No such file or directory |
10-19-2010, 04:21 PM | #17 |
Wizard
Posts: 1,213
Karma: 12890
Join Date: Feb 2009
Location: Amherst, Massachusetts, USA
Device: Sony PRS-505
|
Sorry. It's very hard to write software for a platform without the ability to test it on that platform.
But Let's try this one more time. I guess the mac syntax for mktemp is more different than I thought! I've changed the script so that it doesn't use mktemp at all. The cost of this is that if the script hangs in the middle and you have to manually kill it, it may leave behind some temporary files. You can safely delete them. I'm still perplexed by ebook-meta. Did you check to see whether or not your version of calibre has it installed? Or what version of calibre you're using? I tried to make the script smart about trying to find it on its own--and hopefully that won't break it! Similarly, have you tried gs -v from the terminal? What happens? (You did install ghostscript, right?) Again, I'll swap out the attachment above. Last edited by frabjous; 10-19-2010 at 04:23 PM. |
Advert | |
|
10-19-2010, 04:34 PM | #18 |
Connoisseur
Posts: 79
Karma: 10
Join Date: Oct 2010
Device: Kindle 3
|
Now it's getting more interesting
First off, I'm running the current Ghostscript, as per your instructions and "gs - v". Calibre got updated today to 7.2.4. From what I can tell, all PDF-related extensions are enabled, but there's a lot of random stuff in there. Not finding pdfmanipulate is totally weird, right? Funny thing is, it's claiming this locate.database issue but I've built that database a few times now. Thoughts? ERROR: home: noah$ ./pdfstretch.sh 3x7=21.pdf Looking for ebook-meta ... WARNING: The locate database (/var/db/locate.database) does not exist. To create the database, run the following command: sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist Please be aware that the database can take some time to generate; once the database has been created, this message will no longer appear. Could not find ebook-meta calibre subprogram. Skipping metadata steps. Looking for pdfmanipulate... WARNING: The locate database (/var/db/locate.database) does not exist. To create the database, run the following command: sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist Please be aware that the database can take some time to generate; once the database has been created, this message will no longer appear. Error, Could not find calibre's pdfmanipulate subprogram. The script cannot work without it. |
10-19-2010, 04:38 PM | #19 | ||
Wizard
Posts: 1,213
Karma: 12890
Join Date: Feb 2009
Location: Amherst, Massachusetts, USA
Device: Sony PRS-505
|
Quote:
The problem is, the script won't run on Windows. There might be someone who knows how to change a bash script into a Windows/DOS or powershell batch file, but this one is too complicated for me, and I'm not going to install Windows to test on just for this purpose. If this were really important to you, however, you could install a linux distribution and use that. (If you wanted to keep Windows untouched, you could install linux inside a virtual machine like VirtualBox or something.) But that's pretty extreme, unless you were curious about linux anyway. (Which I do encourage. I'll never go back to the dark days of using Windows.) Another alternative would be to go back to my original advice and install pdfLaTeX; if you want to try it that way, I can try to help. I have a lot more experience with LaTeX than I do with ghostscript anyway. Quote:
|
||
10-19-2010, 04:48 PM | #20 | |
Wizard
Posts: 1,213
Karma: 12890
Join Date: Feb 2009
Location: Amherst, Massachusetts, USA
Device: Sony PRS-505
|
Quote:
Here's what I suggest.
If you manage to find them, then you can edit the script yourself. Open it in a text editor, and replace the portion: Code:
echo -n "Looking for ebook-meta ..." if which "ebook-meta" ; then emexec=$(which "ebook-meta") else if locate "ebook-meta" ; then emexec=$(locate "ebook-meta" | head -n1) else echo "" echo "Could not find ebook-meta calibre subprogram. Skipping metadata steps." emexec="notfound" fi fi echo "" Code:
emexec="/usr/bin/ebook-meta" Code:
echo -n "Looking for pdfmanipulate..." if which "pdfmanipulate" ; then pdmexec=$(which "pdfmanipulate") else if locate "pdfmanipulate" ; then pdmexec=$(locate "pdfmanipulate" | head -n1) else echo "" echo "Error, Could not find calibre's pdfmanipulate subprogram." echo "The script cannot work without it." exit 3 fi fi echo "" Code:
pdmexec="/usr/bin/pdfmanipulate" Last edited by frabjous; 10-19-2010 at 04:51 PM. |
|
Advert | |
|
10-19-2010, 04:56 PM | #21 |
Wizard
Posts: 1,213
Karma: 12890
Join Date: Feb 2009
Location: Amherst, Massachusetts, USA
Device: Sony PRS-505
|
Ack! I figured it out. Calibre does not install these tools by default on a mac.
You need to run calibre and go into Preferences->Advanced->Miscellaneous and click "install command line tools". Source: http://calibre-ebook.com/user_manual/cli/cli-index.html I guess Kovid is figuring that mac users are too scared of the command line. Prove 'em wrong! |
10-19-2010, 09:57 PM | #22 |
Connoisseur
Posts: 79
Karma: 10
Join Date: Oct 2010
Device: Kindle 3
|
Oh, I'm posturing now...
Heads up... $ Looking for ebook-meta .../usr/bin/ebook-meta Looking for pdfmanipulate.../usr/bin/pdfmanipulate Looking for ghostscript.../usr/local/bin/gs Reading metadata... Author(s) recognized as Unknown. Title recognized as 3x7=21. Language recognized as und. Analyzing page geometry... GPL Ghostscript 8.71 (2010-02-10) Copyright (C) 2010 Artifex Software, Inc. All rights reserved. This software comes with NO WARRANTY: see the file PUBLIC for details. Processing pages 1 through 103. Page 1 Page 2 Page 3 Page 4 |
10-19-2010, 10:07 PM | #23 |
Connoisseur
Posts: 79
Karma: 10
Join Date: Oct 2010
Device: Kindle 3
|
Oh my...
Page 102 Page 103 Now cropping the pages... done. Reinstating metadata... Original metadata:: Title : 3x7=21-stretched Author(s) : Unknown Language : und Changed metadata:: Title : 3x7=21-stretched Author(s) : Unknown Language : und Finished. Output saved as 3x7=21-stretched.pdf. |
10-19-2010, 10:13 PM | #24 |
Connoisseur
Posts: 79
Karma: 10
Join Date: Oct 2010
Device: Kindle 3
|
Looks great - I need to charge my Kindle (I leave wifi/3G on, so it only lasts a few days) to get it delivered and see it on the screen...
The auto-crop kind of puts Briss to shame, as awesome as Briss is. For my purposes, just seeing the text and now squeezed into the right aspect, I'm really confident this could make a huge difference for a lot of PDF readers, and a big population of folks who want to read text-based PDFs like screenplays. You're all the way across the country, but next time you're in L.A., I'm buying you a beer. Now comes the major question: What is the process of turning this into an executable application outside of the Shell? I know that's something that's built-in with Applescript/Automator (obviously Mac-centric), but I've never messed with it. Maybe that's a weekend project to learn... UPDATE: So here's something interesting; Because the script crops not to a set margin, but to the widest point the text hits, most pages are slightly different in width. What we end up with is a stretched full-page but somehow, the Kindle is still attaching margins. See attached. Why are there still margins? The point of squeezing was to get the text tight enough to fill the page, right? The next experiment is going to be cropping the pages in half as per Briss (it's back in action, I shouldn't have opened my big mouth!) and then running the script, to see if it evokes the right aspect but on a smaller page. Is there a way to adjust the script to actually output "Kindle-sized" (as opposed to aspect-ratio) pages? Would that make a difference? Last edited by kidblue; 10-19-2010 at 10:44 PM. |
10-20-2010, 01:33 AM | #25 |
Wizard
Posts: 1,213
Karma: 12890
Join Date: Feb 2009
Location: Amherst, Massachusetts, USA
Device: Sony PRS-505
|
The issue there is that it scales/distorts the pages by a fixed percentage, and that fixed percentage is based on what it needs to scale the wider pages by in order to get them to 3:4. So pages that aren't as wide aren't stretched all the way to 3:4; the aspect ratio of the page is therefore less than 3:4, and the Kindle has no choice but to leave gaps on the sides. (There's not margins, since they're "off the page", but the effect is the same.)
I actually had it work that way deliberately, because I thought it would be jarring if some pages were stretched in a much different way or amount than others. Consider, for example, the last page of a chapter. If there were only two lines on the page, it would make each character 2 or 3 inches tall without changing its width! But I guess you could try it if you really want. It would mean changing the script so that it processed each page one at a time rather than all of them as a group. I don't have time to work more on it today, but maybe sometime in the next few days. P.S. About turning it into a program that ran outside of a shell... well, it's all automated, so there would be no point to having a GUI except a big button that said "Go!" or something like that. Could you make a GUI with a single button, which when the button was clicked, ran this script? I'm sure it's possible. I would know how to do it for Windows and linux, but I know nothing about such things for a mac. If you sat me in front of a mac, I'm not even sure I'd be able to find the File Manager or "Finder" or whatever it is called. All I really know about OS X is that it's Unix-based underneath and can run Bash. But what I would suggest is something like an "Context Menu" option associated with PDFs that would run the script on them. (By "context menu" I mean the menu you get in your File Manager when you right click (or hold the mouse button down or whatever you do with those funny 1-button mice macs sometimes have).) For all intents and purposes, the script is a program, and the File Manager probably already has a way of adding "Open With..." options to the context menu, and you'd just need to add this script as an Open With option. But don't ask me how to do that on a mac. I don't have any clue. Last edited by frabjous; 10-20-2010 at 01:45 AM. |
10-20-2010, 09:51 AM | #26 |
Wizard
Posts: 1,213
Karma: 12890
Join Date: Feb 2009
Location: Amherst, Massachusetts, USA
Device: Sony PRS-505
|
It occurred to that one way to get what you want (or what I think you want) is to simply burst the PDF into separate pages, in effect run the old script on each page, and them reassemble them, and so making the changes to the script are actually fairly simple.
So here's a new script you can try if you want. I also made some other minor changes, mainly suppressing some of the terminal noise ghostscript makes (--which may end up suppressing error messages, but I'm not sure they'd be meaningful to you anyway--), and forcing each page into the exact Kindle page size. (Well, 3.54 × 4.72 inches, which is 90x120 rounded off the nearest 100th of an inch.) One disadvantage, in addition to some strangely skewed pages, is that the script is a lot slower. I already thought the script was slow compared to BRISS, and compared to sopdf, it's a dead snail. This is in part because it does each page separately, and also in part because of the variation in stretching, it takes it longer to figure out how to crop the page. I've giving this script a different name, and posting it separately, rather than replacing the one above, since some people might prefer to use the one above instead. They both have their advantages, I suppose. This one is called pdf3to4.sh (to mark that all pages have a 3:4 ratio). The instructions for using it are the same. Download the tarball, extract the file pdf3to4.sh, and then: Code:
cd "/path/where/you/saved/it" chmod a+x pdf3to4.sh ./pdf3to4.sh "example.pdf" Last edited by frabjous; 10-20-2010 at 06:26 PM. |
10-20-2010, 10:57 AM | #27 |
Connoisseur
Posts: 79
Karma: 10
Join Date: Oct 2010
Device: Kindle 3
|
Thanks for this new script, but no dice on it. See the "spoiler" below.
You make some awesome points. I completely agree that a contextual menu would be the way to go, even a shortcut that could be applied to a selected folder or file. Heck, that'd be the way to go with Briss, too, for that matter. From a GUI perspective, that would be the most efficient. I imagine there's an easy way to convert a Bash file to Applescript for it, and that'll be a little fun research for me, getting my feet wet. And we Mac users haven't had one-button mice for a few years I think this is the issue with the concept overall - In dealing with a PDF, the Kindle (and I imagine most readers of the ilk) will expand the text of a given page as far as the margins or "dead" space will allow. In other words, if dealing with a screenplay and center-justified "dialogue" text with no left-justified descriptive text, it will expand the size of that text greatly and on the next page, if there is left-justified text, go back to a smaller size. What I propose is this (and it may be in the new script, I just haven't seen it yet): A formatting that cuts down on the margins (auto-crop) and confirms that each page is exactly the same size (as per Kindle) as opposed to the same aspect ratio. Because the reader will simply stretch and/or squeeze the page "to fit", we need to "trick" it into seeing each page as exactly the same size. In this case, it's something that PDfs are actually useful for! I think that's exactly what you did This is interesting in that it still doesn't quite take the place of what Briss does, although I'd like it to. Looking at the average screenplay document, each page, without the margins or dead-space is only 15x20 cm. Comparing that to a Kindle screen (9x12 cm), we're only talking about approximately a 30% reduction, which should be still totally readable. If we could factor in what Briss does and split it vertically, we should be able to end up with a consistently-sized document that is readable, with a "constant" in the size of each page, don't you think? Error: (my shell is "noah" and the PDF is "3x7=21.pdf") Spoiler:
|
10-20-2010, 01:45 PM | #28 |
Wizard
Posts: 1,213
Karma: 12890
Join Date: Feb 2009
Location: Amherst, Massachusetts, USA
Device: Sony PRS-505
|
macs don't have seq? wtf? How can it be unix and not have seq? ("JOBS!" I scream in a Kirk-hating-Khan-voice.)
Anyway, I've swapped out the script in post #26 with one that doesn't use seq. I also tried to make a minor speed improvement, but I doubt it will matter much. I'm not actually sure the chmod step is even necessary, but it may depend on your tar.gz archive extraction program. It won't hurt though you might as well keep doing it. So now we can see how this one breaks. P.S. Of course this doesn't replace BRISS. If nothing else, this script is incapable of removing headers and footers, which BRISS is. BRISS is also more useful for scanned PDFs and multicolumn PDFs and a lot more. I love BRISS and use it a lot. P.P.S. I know nothing about Applescript, but I imagine the way to go would be to call the bash script from the Applescript, rather than trying to convert the one to the other... just use one inside the other, so to speak. Last edited by frabjous; 10-20-2010 at 01:56 PM. |
10-20-2010, 06:03 PM | #29 |
Connoisseur
Posts: 79
Karma: 10
Join Date: Oct 2010
Device: Kindle 3
|
Now we're cooking with gas. This was exactly what I was looking for; A way to "crop-and-zoom", fit the PDF pages to the screen at the largest possible type in a full page!
Seriously, it is amazing to see this kind of help from a fellow forum-member. Thanks don't begin to describe it. I'm looking into Applescript right now. It's easy enough to basically create a script that calls up yours and sticks it in a Finder's contextual menu, but it's going to require a bit of research to allow it to "do its thing" from another folder other than the one it resides in, if that makes sense. It has been leaving "tmppdf3to4dirkk" with various PDF files (each page's "crop", "out" and "skew") - Should it be doing that or should it automatically be trashing that folder of what's obviously temporary files when done with the conversion? I also love and appreciate BRISS, but in the case of what you've done here, by scaling (if that's the correct term) is almost make the headers and footers inconsequential, whether they are they or not. Obviously, I don't see them on the screen since they stay fit to the widest margin set by the actual type. Again, sincere thanks. |
10-20-2010, 06:24 PM | #30 | ||
Wizard
Posts: 1,213
Karma: 12890
Join Date: Feb 2009
Location: Amherst, Massachusetts, USA
Device: Sony PRS-505
|
Quote:
Quote:
I commented out the line that is responsible for deleting the temporary folder when I was testing the script (so I could see where things went wrong when they did), but then I forgot to restore the line. I'll put an update to the script above, and you can download that if you want. Or if you prefer, you can edit the script directly in a text editor. You just need to change line 136 (about 8 lines from the bottom of the file) from: Code:
# rm -rf "$wd" Code:
rm -rf "$wd" Oh, and don't name any folders you want to keep "tmppdf3to4dirkk", no matter how cool it seems, or they'll get gobbled. |
||
Thread Tools | Search this Thread |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Changing a PDF file to custom margins ? | masa6614 | General Discussions | 0 | 06-08-2010 04:21 PM |
Changing DPI in a PDF | ardeegee | 3 | 02-18-2010 01:39 PM | |
Changing font size in pdf | mrgiedrnkr | Amazon Kindle | 1 | 12-01-2009 05:33 PM |
Changing pdf properties | Puddytat purr | 2 | 02-22-2008 09:27 AM | |
pdf page changing speed ? | bugsbunny14 | Sony Reader | 15 | 10-19-2006 05:28 PM |