2012-03-05 01:46:16 +00:00
|
|
|
require "unireader"
|
2012-03-19 23:10:19 +00:00
|
|
|
require "inputbox"
|
2011-12-07 23:45:39 +00:00
|
|
|
|
2012-03-19 17:59:36 +00:00
|
|
|
PDFReader = UniReader:new{}
|
2011-12-07 23:45:39 +00:00
|
|
|
|
|
|
|
-- open a PDF file and its settings store
|
2012-03-19 23:10:19 +00:00
|
|
|
function PDFReader:open(filename)
|
|
|
|
-- muPDF manages its own cache, set second parameter
|
|
|
|
-- to the maximum size you want it to grow
|
|
|
|
local ok
|
2012-03-31 12:09:50 +00:00
|
|
|
ok, self.doc = pcall(pdf.openDocument, filename, self.cache_document_size)
|
2012-03-19 23:10:19 +00:00
|
|
|
if not ok then
|
|
|
|
return false, self.doc -- will contain error message
|
|
|
|
end
|
|
|
|
if self.doc:needsPassword() then
|
|
|
|
local password = InputBox:input(height-100, 100, "Pass:")
|
|
|
|
if not password or not self.doc:authenticatePassword(password) then
|
|
|
|
self.doc:close()
|
|
|
|
self.doc = nil
|
|
|
|
return false, "wrong or missing password"
|
|
|
|
end
|
|
|
|
-- password wrong or not entered
|
|
|
|
end
|
|
|
|
local ok, err = pcall(self.doc.getPages, self.doc)
|
|
|
|
if not ok then
|
|
|
|
-- for PDFs, they might trigger errors later when accessing page tree
|
|
|
|
self.doc:close()
|
|
|
|
self.doc = nil
|
|
|
|
return false, "damaged page tree"
|
|
|
|
end
|
|
|
|
return true
|
2011-12-07 23:45:39 +00:00
|
|
|
end
|