Add the capability to load a PDF file using a command-line option
The -i/--images option only accepts jpg, etc, and not PDF files.
There should be an option that accepts PDF files, either by changing the semantics of -i/--images, or as a separate option. I prefer the latter, and suggest -p/--import-pdf.
This patch to implement such an option applies to 0.8.1, as installed by Ubuntu.
--- /usr/lib/python2.7/dist-packages/ocrfeeder/studio/studioBuilder.py~
+++ /usr/lib/python2.7/dist-packages/ocrfeeder/studio/studioBuilder.py
@@ -123,17 +123,29 @@
metavar = 'IMAGE1 [IMAGE2, ...]', default = [],
help = 'images to be automatically added on start-up. '
'Use the option before every image path.')
+ # add import-pdf option
+ parser.add_option('-p', '--import-pdf', dest = 'importpdf',
+ action = 'store', type = 'string', metavar = 'PDF_file',
+ help = 'PDF file to be imported (alternative to --image and --dir)', default = [])
parser.add_option('-d', '--dir', dest = 'directory',
action = 'store', type = 'string',
help = 'directory with images to be added'
' automatically on start-up')
options, args = parser.parse_args()
- imgs = options.images
- if imgs:
- self.__addImagesToReviewer(imgs)
+ # add import-pdf option
+ if (options.images or options.directory) and options.importpdf:
+ parser.error('Please specify images or PDF import, not both.')
+ parser.print_help()
+ exit(0)
+
+ if options.images:
+ self.__addImagesToReviewer(options.images)
if options.directory:
self.__addImagesToReviewer(
lib.getImagesFromFolder(options.directory))
+ # add import-pdf option
+ if options.importpdf:
+ self.__importPdf(options.importpdf)
self.main_window.setHasSelectedBoxes(False)
self.main_window.setHasContentBoxes(False)
@@ -239,6 +251,19 @@
error.run()
Gdk.threads_leave()
+ # add import-pdf option
+ def __importPdf(self, file_name):
+ dialog = widgetPresenter.QueuedEventsProgressDialog(
+ self.main_window)
+ item = AsyncItem(lib.convertPdfToImages,
+ (file_name,
+ self.configuration_manager.TEMPORARY_FOLDER),
+ self.__loadPdfFinishedCb,
+ (dialog,))
+ info = (_('Loading PDF'), _(u'Please wait…'))
+ dialog.setItemsList([(info, item)])
+ dialog.run()
+
def importPdf(self, widget):
file_open_dialog = widgetPresenter.FileDialog(self.main_window,
'open',
@@ -249,16 +274,8 @@
files = file_open_dialog.get_filenames()
file_open_dialog.destroy()
for file_name in files:
- dialog = widgetPresenter.QueuedEventsProgressDialog(
- self.main_window)
- item = AsyncItem(lib.convertPdfToImages,
- (file_name,
- self.configuration_manager.TEMPORARY_FOLDER),
- self.__loadPdfFinishedCb,
- (dialog,))
- info = (_('Loading PDF'), _(u'Please wait…'))
- dialog.setItemsList([(info, item)])
- dialog.run()
+ # add import-pdf option
+ self.__importPdf(file_name)
def __loadPdfFinishedCb(self, dialog, folder, error):
self.__addImagesToReviewer(lib.getImagesFromFolder(folder))