__copyright__ = '2009, James Beal <james_@catbus.co.uk>, 2009, John Schember <john@nachtimwald.com>'
__docformat__ = 'restructuredtext en'
import sys
import re
from decimal import Decimal
from optparse import OptionGroup, Option
from calibre.ebooks.metadata.meta import metadata_from_formats
from calibre.ebooks.metadata import authors_to_string
from calibre.utils.config import OptionParser
from calibre.utils.logging import Log
from calibre.constants import preferred_encoding
from calibre.customize.conversion import OptionRecommendation
from calibre.ebooks.pdf.verify import is_valid_pdf, is_encrypted
from pyPdf import PdfFileWriter, PdfFileReader
DEFAULT_CROP = 10
USAGE = '\n%prog %%name ' + _('[options] file.pdf\n\nCrop a PDF file.\n')
OPTIONS = set([
OptionRecommendation(name = 'output', recommended_value = 'cropped.pdf', level = OptionRecommendation.HIGH, long_switch = 'output', short_switch = 'o', help = _('Path to output file. By default a file is created in the current directory.')),
OptionRecommendation(name = 'bottom_left_x', recommended_value = DEFAULT_CROP, level = OptionRecommendation.LOW, long_switch = 'left-x', short_switch = 'x', help = _('Number of pixels to crop from the left most x (default is %s)') % DEFAULT_CROP),
OptionRecommendation(name = 'bottom_left_y', recommended_value = DEFAULT_CROP, level = OptionRecommendation.LOW, long_switch = 'left-y', short_switch = 'y', help = _('Number of pixels to crop from the left most y (default is %s)') % DEFAULT_CROP),
OptionRecommendation(name = 'top_right_x', recommended_value = DEFAULT_CROP, level = OptionRecommendation.LOW, long_switch = 'right-x', short_switch = 'v', help = _('Number of pixels to crop from the right most x (default is %s)') % DEFAULT_CROP),
OptionRecommendation(name = 'top_right_y', recommended_value = DEFAULT_CROP, level = OptionRecommendation.LOW, long_switch = 'right-y', short_switch = 'w', help = _('Number of pixels to crop from the right most y (default is %s)') % DEFAULT_CROP),
OptionRecommendation(name = 'bounding', recommended_value = None, level = OptionRecommendation.LOW, long_switch = 'bounding', short_switch = 'b', help = _('A file generated by ghostscript which allows each page to be individually cropped `gs -dSAFER -dNOPAUSE -dBATCH -sDEVICE=bbox file.pdf 2> bounding`'))])
def print_help(parser, log):
help = parser.format_help().encode(preferred_encoding, 'replace')