0

I have this path: C:\folder1\folder2\folder3

To make it in Java I use FileUtils.forceMkdir(new File("/folder1/folder2/folder3"));

I can't figure out how to access this relative path using HTML to embed my pdf file into a page. I tried using: <embed src="/folder1/folder2/folder3/name.pdf" width="500" height="375"> but this is not working. Any suggestions?

Edit: I want to access C:/folder1/folder2/folder3/name.pdf using relative paths in case a user, for instance, has an E:/ drive instead of C:/

Jordan.J.D
  • 7,999
  • 11
  • 48
  • 78
  • Where is your HTML file located? `C:\ `? – TylerH May 08 '14 at 20:37
  • i am working in Eclipse, are you asking where my project is located? @TylerH – Jordan.J.D May 08 '14 at 20:38
  • Yes. Your HTML file needs to be located at `C:\ ` for your current relative file path to be correct. It also wouldn't hurt to remove the first `/` before `folder1`, either (in the past I've had relative paths not work when I started with `/` instead of the folder name). – TylerH May 08 '14 at 20:41
  • @TylerH I removed the first `/` with no change in progress. I am not accessing a file in my project, I will be accessing it off my `C:/` drive – Jordan.J.D May 08 '14 at 20:46

2 Answers2

1

If your HTML file is in C:\, try the following (notice the / is removed from the start of the path)

<embed src="folder1/folder2/folder3/name.pdf" width="500" height="375">

Or if, as an example, your HTML file were in C:\folder1\folder2 instead of C:\, the path would be like this:

<embed src="folder3/name.pdf" width="500" height="375">

The beginning slash may or may not be equivalent to their current drive, thus it may work better to use a relative path as suggested above.

0

There are multiple ways to do it.

See Recommended way to embed PDF in HTML?

And try <embed src="/folder1/folder2/folder3/name.pdf" width="500" height="375" type='application/pdf'> instead. Sometimes it doesn't work without the type specified. Using <embed> for a .pdf file also requires that you have the adobe PDF reader plugin on your browser (which most have by default).

Hope that works for you.

HTML's / renders the root of the server url, in my case, localhost/. Not the file path on your computer, e.g. C:/.

Community
  • 1
  • 1
khaverim
  • 3,386
  • 5
  • 36
  • 46
  • 1. I tried adding type to no avail. I have been through that post, which has brought me to using the tag instead of other ways. Also, I updated my question with some more info in case it helps. – Jordan.J.D May 08 '14 at 20:43
  • What *actually* happens? Just blank output where the pdf would otherwise be on the page? Or any error? Have you tried putting another generic file in the same directory and embedding that one? What's the result? – khaverim May 08 '14 at 20:48
  • Using the absolute path works perfectly, the PDF is embedded well. As of right now I get a gray box with the size parameters I specified. – Jordan.J.D May 08 '14 at 20:50
  • Using PHP by chance? `` could be what you need. – khaverim May 08 '14 at 20:57