packages feed

pdfsplit (empty) → 0.0

raw patch · 4 files changed

+128/−0 lines, 4 filesdep +basedep +directorydep +pdfinfosetup-changed

Dependencies added: base, directory, pdfinfo, process, temporary

Files

+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c)2010, Daniel Wagner++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Daniel Wagner nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++! This software is provided by the copyright holders and contributors+! "as is" and any express or implied warranties, including, but not+! limited to, the implied warranties of merchantability and fitness for+! a particular purpose are disclaimed. In no event shall the copyright+! owner or contributors be liable for any direct, indirect, incidental,+! special, exemplary, or consequential damages (including, but not+! limited to, procurement of substitute goods or services; loss of use,+! data, or profits; or business interruption) however caused and on any+! theory of liability, whether in contract, strict liability, or tort+! (including negligence or otherwise) arising in any way out of the use+! of this software, even if advised of the possibility of such damage.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ pdfsplit.cabal view
@@ -0,0 +1,29 @@+Name:                pdfsplit+Version:             0.0+Synopsis:            split two-column PDFs, so there is one column per page+Description:         Reading two-column academic papers is awkward on the+                     Kindle; you sort of have to choose between zooming way+                     out, so that the text is unreadably small, or zooming in+                     far enough that the text is readable, but mucking around+                     with the arrow navigation keys and never quite centering+                     the text on the page. This program takes two-column papers+                     on standard US-letter size paper and splits them down the+                     middle, producing a PDF with one page for each column. On+                     the Kindle, this makes the text large enough to read while+                     still allowing the convenient, built-in navigation mode.+Homepage:            http://dmwit.com/pdfsplit+License:             BSD3+License-file:        LICENSE+Author:              Daniel Wagner+Maintainer:          daniel@wagner-home.com+Category:            Utils, PDF+Build-type:          Simple+Cabal-version:       >=1.2+Executable pdfsplit+    Main-is: pdfsplit.hs+    Build-depends:+        base >= 3 && <= 4,+        directory >= 1 && < 2,+        pdfinfo >= 0 && < 1,+        process >= 1 && < 2,+        temporary >= 1
+ pdfsplit.hs view
@@ -0,0 +1,67 @@+import Control.Monad+import Data.List+import System.Directory+import System.Environment+import System.Exit+import System.IO+import System.IO.Temp+import System.Process+import Text.PDF.Info+import Text.Printf++texBegin = "\+	\\\documentclass{article}\+	\\\usepackage[paperwidth=4.25in,paperheight=11in]{geometry}\+	\\\usepackage{pdfpages}\+	\\\begin{document}\+	\"+includeTemplate = "\+	\\\includepdf[pages=%d,noautoscale,offset=2.125in 0]{%s}\+	\\\includepdf[pages=%d,noautoscale,offset=-2.125in 0]{%s}\+	\"+texEnd = "\\end{document}"+usageTemplate = "\+	\USAGE: %s infile.pdf [infile.pdf ...]\n\+	\\n\+	\Each filename given on the command line is treated as a standard US-letter\n\+	\(8.25\" x 11\") sized, two-column PDF, and a new PDF file is produced. If the\n\+	\input file name has the form <file>.pdf, then the new file will be named\n\+	\<file>-split.pdf. Otherwise, the output file name will be identical to the\n\+	\input file name, but with -split.pdf appended. Input filenames must not\n\+	\contain whitespace (not even properly-escaped whitespace!).\n\+	\\n\+	\Also, don't name your input files -h or --help. Come on.\n\+	\"+fixTheHighlighting = "--"++splitPages name n = withTempFile "." "pdfsplit.tex" $ \tmp h -> do+	hPutStr h texBegin+	forM_ [1..n] $ \i -> hPrintf h includeTemplate i name i name+	hPutStr h texEnd+	hFlush h+	readProcess "pdflatex" [tmp] ""+	renameFile (base "tex" tmp ++ ".pdf") (base "pdf" name ++ "-split.pdf")+	forM_ [".aux", ".log"] (removeFile . (base "tex" tmp ++))++base ext s+	| ('.':ext) `isSuffixOf` s = zipWith const s (drop (1 + length ext) s)+	| otherwise = s++problem s = printf (printf "Error processing file <%%s>: %s\n" s)+process name = do+	info <- pdfInfo name+	case (info, words name) of+		(Left error, _) -> problem "%s" name (show error) >> return 1+		(_, _:_:_) -> problem "filenames must not contain whitespace" name >> return 1+		(Right PDFInfo { pdfInfoPages = Nothing }, _) -> problem "can't divine the page count" name >> return 1+		(Right PDFInfo { pdfInfoPages = Just n }, _) -> splitPages name n >> return 0++usage = getProgName >>= printf usageTemplate >> exitWith ExitSuccess++main = do+	names <- getArgs+	when (names `elem` [[], ["--help"], ["-h"]]) usage+	successes <- mapM process names+	case sum successes of+		0 -> exitWith ExitSuccess+		n -> exitWith (ExitFailure n)