Is it possible to read PDF files using a Corona App? [import]uid: 64174 topic_id: 35651 reply_id: 335651[/import]
Yes it is…
I get a pdf file sent via JSON and store it in the local directory…
local function networkListener(event)
if ( event.isError ) then
SOC\_Status.text = "Network error!"
else
-- print ( "RESPONSE: " .. event.response )
SOCdata = json.decode(event.response)
--
-- if SOC.pdf already exists, erase it
--
local filepath=system.pathForFile( "SOC.pdf", system.DocumentsDirectory )
print("Deleting " .. filepath)
local results = os.remove( filepath )
local PDFdata = ""
local n=0
local PDFlen=#SOCdata.SendSOCMethodResult[1].SOC\_Data
print("PDF array has " .. PDFlen .. " Bytes")
while n \< PDFlen do
n=n+1
PDFdata=PDFdata .. string.char(SOCdata.SendSOCMethodResult[1].SOC\_Data[n])
end
local file=io.open(filepath,"w")
file:write(PDFdata)
io.close(file)
file=nil
SOCdata=nil
--
-- Now either email PDF or Display in Web window
--
native.setActivityIndicator( false )
local options = { baseUrl=system.DocumentsDirectory }
local mailoptions =
{
to = nil,
subject = "Statement of charges",
body = "Please find attached Statement of Charges",
attachment = { baseDir=system.DocumentsDirectory, filename="SOC.pdf", type="PDF" },
}
if SOC\_Mode == "emailsocbutton" then
native.showPopup("mail", mailoptions)
else
native.showWebPopup(0, 0, 320, 436,"SOC.pdf",options)
bottomBar.isVisible = true
backr.isVisible = true
end
end
end
Note that backr.isVisible refers to a little [I have finished looking at the PDF] button!
Stan
[import]uid: 202067 topic_id: 35651 reply_id: 141749[/import]
Whoops - posted the above whilst logged into our corp account!
Stan [import]uid: 178113 topic_id: 35651 reply_id: 141751[/import]
Hello @Satheesh,
In addition to the code suggested by @manuel5, you might want to investigate the following:
https://github.com/boostup/Corona-SDK-Simple-PDF-Reader
Regards,
Brent [import]uid: 200026 topic_id: 35651 reply_id: 141791[/import]
Your welcome Satheesh!
Stan [import]uid: 178113 topic_id: 35651 reply_id: 142012[/import]
Yes it is…
I get a pdf file sent via JSON and store it in the local directory…
local function networkListener(event)
if ( event.isError ) then
SOC\_Status.text = "Network error!"
else
-- print ( "RESPONSE: " .. event.response )
SOCdata = json.decode(event.response)
--
-- if SOC.pdf already exists, erase it
--
local filepath=system.pathForFile( "SOC.pdf", system.DocumentsDirectory )
print("Deleting " .. filepath)
local results = os.remove( filepath )
local PDFdata = ""
local n=0
local PDFlen=#SOCdata.SendSOCMethodResult[1].SOC\_Data
print("PDF array has " .. PDFlen .. " Bytes")
while n \< PDFlen do
n=n+1
PDFdata=PDFdata .. string.char(SOCdata.SendSOCMethodResult[1].SOC\_Data[n])
end
local file=io.open(filepath,"w")
file:write(PDFdata)
io.close(file)
file=nil
SOCdata=nil
--
-- Now either email PDF or Display in Web window
--
native.setActivityIndicator( false )
local options = { baseUrl=system.DocumentsDirectory }
local mailoptions =
{
to = nil,
subject = "Statement of charges",
body = "Please find attached Statement of Charges",
attachment = { baseDir=system.DocumentsDirectory, filename="SOC.pdf", type="PDF" },
}
if SOC\_Mode == "emailsocbutton" then
native.showPopup("mail", mailoptions)
else
native.showWebPopup(0, 0, 320, 436,"SOC.pdf",options)
bottomBar.isVisible = true
backr.isVisible = true
end
end
end
Note that backr.isVisible refers to a little [I have finished looking at the PDF] button!
Stan
[import]uid: 202067 topic_id: 35651 reply_id: 141749[/import]
Whoops - posted the above whilst logged into our corp account!
Stan [import]uid: 178113 topic_id: 35651 reply_id: 141751[/import]
Hello @Satheesh,
In addition to the code suggested by @manuel5, you might want to investigate the following:
https://github.com/boostup/Corona-SDK-Simple-PDF-Reader
Regards,
Brent [import]uid: 200026 topic_id: 35651 reply_id: 141791[/import]
Your welcome Satheesh!
Stan [import]uid: 178113 topic_id: 35651 reply_id: 142012[/import]