Trouble displaying HTML files on Android

Hi All,

I’m having trouble displaying a converted pdf (To HTML) on Android.

I can view it fine on iOS. It just displays as a simple web page, however when I come to view it on Android it doesn’t seem to work.

I’ve posted the code below and attached the files - any help would be greatly appreciated.

framework = {} function framework:copyToDocumentsDirectory(params) local overwrite = params.overwrite or false local fileName = params.fileName -- See if Database File Already Exists in Documents Directory path = system.pathForFile( fileName, system.DocumentsDirectory ) file = io.open( path, "r" ) if ( file ~= nil and overwrite == true ) or (file == nil ) then -- Doesn't Already Exist, So Copy it In From Resource Directory pathSource = system.pathForFile( fileName, system.RecourceDirectory ) fileSource = io.open( pathSource, "r" ) contentsSource = fileSource:read( "\*a" ) -- Write Destination File in Documents Directory pathDest = system.pathForFile( fileName, system.DocumentsDirectory ) fileDest = io.open( pathDest, "w" ) fileDest:write( contentsSource ) -- Done io.close( fileSource ) io.close( fileDest ) end end local function modifySourceAndCreateCopyToDocumentsDirectory(params) local overwrite = params.overwrite or false local srcFileName = params.srcFileName local destFileName = params.destFileName path = system.pathForFile( destFileName, system.DocumentsDirectory ) file = io.open( path, "r" ) --if ( file ~= nil and overwrite == true ) or (file == nil ) then pathSource = system.pathForFile( srcFileName, system.ResourceDirectory ) fileSource = io.open( pathSource, "r" ) contentsSource = fileSource:read( "\*a" ) pathDest = system.pathForFile( destFileName, system.DocumentsDirectory ) fileDest = io.open( pathDest, "w" ) for i = 1, #params.lookFor do contentsSource = string.gsub ( contentsSource, params.lookFor[i], params.replace[i] ) end fileDest:write(contentsSource ) io.close( fileSource ) io.close( fileDest ) --end end local function prepareHtmlForPDF(params) --print("will display: " .. params.fileName) local destFile = params.fileName .. ".html" local params = { srcFileName="pdf\_viewer\_template.html", destFileName=destFile, lookFor= { "##pdf\_file\_name##", "##html\_obj\_height##" }, replace= { params.fileName, params.htmlObjHeight } , overwrite=true, } modifySourceAndCreateCopyToDocumentsDirectory( params ) return destFile end function framework:displayPdfFile ( params ) --print(params) local fileName = params.pdfFileName self:copyToDocumentsDirectory( { fileName= fileName} ) local destFile = prepareHtmlForPDF( { fileName= fileName, htmlObjHeight= params.documentHeight } ) local options = { hasBackground=true, baseUrl=system.DocumentsDirectory } end local webView = native.newWebView( 0, 0, display.contentWidth, display.contentHeight) webView:request("fsuserforms.pdf.html", system.DocumentsDirectory) framework:displayPdfFile( { pdfFileName = "fsuserforms.pdf", webViewY = 70, documentHeight=10000 } )

The attached files are the ones for conversion and the pdf i want to read.

Ok, so after some playing around I think I have determined that the problem is that when the device goes to look for another file (from the HTML file), the device is unable to locate it.

How would I go about copying a pdf from one location to another without damaging the contents?

Ok, with some more playing around I have come to the conclusion that it is impossible to get a pdf to display in a webview on Android.

Sample code:

    local webView = native.newWebView( 0, 0, display.contentWidth, display.contentHeight)
    webView:request(“http://www.selab.isti.cnr.it/ws-mate/example.pdf”)
 

Anybody have any suggestions to get around this problem?

Ok, so after some playing around I think I have determined that the problem is that when the device goes to look for another file (from the HTML file), the device is unable to locate it.

How would I go about copying a pdf from one location to another without damaging the contents?

Ok, with some more playing around I have come to the conclusion that it is impossible to get a pdf to display in a webview on Android.

Sample code:

    local webView = native.newWebView( 0, 0, display.contentWidth, display.contentHeight)
    webView:request(“http://www.selab.isti.cnr.it/ws-mate/example.pdf”)
 

Anybody have any suggestions to get around this problem?