cancel
Showing results for 
Search instead for 
Did you mean: 

Display a PDF file from local drive

Former Member
0 Kudos

Hi,

I would like to display a pdf file that is actually stored on the portal server hard drive.

What I have tried to do is link an iFrame element to the url of the file: "D:
MyFolder
myFile.pdf"

But it doesn't work. I have the following error when trying to do that:

com.sap.tc.webdynpro.services.exceptions.InvalidUrlRuntimeException: Invalid URL=D:/MyFolder/myFile.pdf

Does this means that iFrame can only display http URLs ? What are the other ways to easily display pdf files ?? I'am stuck with that problem and can't find any other solution.

I also tried with "servletResponse.getOutputStream().write(fileByteContent);" but the problem is that I am not in a PAR application, and I don't have the servletResponse element and don't know how to get it.

Thanks for your help.

Thibault Schalck

Accepted Solutions (0)

Answers (2)

Answers (2)

prasannakrishna_mynam
Contributor
0 Kudos

Hi,

You can not access the .pdf file using the nornal path (c:
), use the following code to open the pdf in ur iframe, this will work i used it in my application.

String sFileName =

strCampCodeVal"_"nReqIdVal+".pdf";

String sFile =

"C:
SBLI
BCP
barcode_files
"+sFileName;

File fFile = new File(sFile);

if ( fFile == null )

{

System.out.println("System can not download the

file at this time. Please try again later.");

return;

}

//Checking the file for existence

if ( !fFile.exists() || !fFile.canRead() )

{

System.out.println("You have specified an

invalid file to download. Please check and try

again.");

return;

}

//set the content type its important , try with applicatio/pdf also

res.setContentType("application/force-download");

//seting the header

res.setHeader("Content-disposition",

"attachment;filename=" + sFileName);

res.setHeader("Cache-control", "must-revalidate");

ServletOutputStream sosCur = res.getOutputStream();;

//reading the in and writing the stream

BufferedInputStream bisFile = null;

try

{

byte [] bBuffer = new byte[4096];

bisFile = new BufferedInputStream(new

FileInputStream(fFile));

int nBytes = -1;

while( (nBytes = bisFile.read(bBuffer, 0, 4096))!=-1 )

{

sosCur.write(bBuffer, 0, nBytes);

}

}

catch(Exception ex){

}

This will resove your issue.All the best..

Regards..

krishna..

steffen_spahr2
Participant
0 Kudos

Hi Thibault,

the correct form of a file-url looks like:

file:///d:/MyFolder/myFile.pdf

or

file://d:/MyFolder/myFile.pdf.

Regards

Steffen