Embed pdf in .ejs file - node.js

I have a web app using express.js and I've tried to embed a pdf into a .ejs file as follows:
embed src="mypdf.pdf" width="500" height="375" />
This gives me the following error when I load that page: Cannot GET /mypdf.pdf
What is the correct way to display a pdf embedded in an .ejs file using express.js (I only want the pdf to take up a portion of the page)?

You need to give the correct path for your pdf.
Check the similar line in your app.js
app.use(express.static(path.join(__dirname, 'public')));
Here public is the directory which you are telling express to consider for static resources and can be accessed directly with root path.
Now create a new folder in this public folder called docs or you can put pdf directly in the public folder
change embed tag as following
<embed src="/doc/mypdf.pdf" width="500" height="375" type="application/pdf">
if you put pdf directly in a public folder then change the path to /mypdf.pdf.

Related

how to send a html requirements files with node.js?

I have an HTML project that I want to send to the user's browser via nodejs. Since each HTML file has a set of linked files like style.css, how do we do that?
Do I have to use "app.use" in express.js? Because in this case I have to send the whole project files (even unvisited pages file) to the user !!!
We do what is called a "public" folder. Inside this public folder, anyone can access these files. If your domain was example.com, and inside the public folder we have style.css, we can access sit by example.com/style.css. Any other files that are not in the public directory the user will not be able to access (unless you manually serve them in Express).
You do it in Express like this:
app.use(express.static(__dirname + '/public'));
So put all the files you want to access in the HTML file in the public directory.
You can link a CSS file in your HTML file (in the head tags) like:
<link rel="stylesheet" type="text/css" href="/style.css" />
Here's what you directory can look like:
- index.js (your main server)
- / public
- style.css
- someOtherFile.js
- etc...
- Your other files...

Unable to load GLTF file in ASP.NET View implementing A-FRAME

One of the views (.cshtml file) of my ASP.NET MVC application is using A-Frame. I am trying to load a 3-D model using GLTF file inside the <a-scene> tag.
<body>
<a-scene>
<a-assets timeout="5000">
<a-asset-item id="tree" src="~/Assets/scene.gltf">
</a-assets>
<a-gltf-model src="#tree"></a-gltf-model>
</a-scene>
</body>
I have already tested the src path in the same page by putting a .png file and loading it in <img/>, it works. The problem is just with the .gltf file.
What is possibly wrong with the .gltf file in particular?
The URL doesn't seem like a valid URL. It seems like a Unix path. Host the GLTF somewhere the website can reach it (like the same directory) and fix the path. src="scene.gltf".

nodejs express hide source code of static html

is it possible in nodejs, with express to hide the source-code in my static html directory, without rewriting new end-points for each html page?
server code looks like this and my website is in the directory html
app.use(express.static('html'));
Im looking for something similar to a PHP echo, that hides client-side source code
Does not look like nodejs is capable of performing a 'server side script' inside an html page, similar to
<?php
//hidden script, source-code, leading up to an $echo
?>
such that the source-code of the script is hidden from the end-user if they were to 'view source'

URL of a file in WebContent folder of an XPages project

I want to import font awesome in xpages. I have found that importing files in Webcontent folder makes them accessible from xpages but i cannot find the url to refer to them.
Now i have the whole folder of font awesome under WebContent folder and i want to import as a resource to the xpage the stylesheet file: WebContent/font-awesome-4.3.0/css/font-awesome.css
i am using this code
<xp:this.resources>
<xp:styleSheet href="WebContent/font-awesome-4.0.3/css/font-awesome.css"></xp:styleSheet>
</xp:this.resources>
and i have tried many different url in href attribute.
What is the correct url?
It is the correct location. The url should be without WebContent/.

import js file to header all jsp in liferay

I'm going to import a js file to the header of all pages exist in liferay portal.
I know I have to do in Hook.I put import this js into init.jsp in ..\html\common , but was import to all elements of the liferay pages.
I don't know where put this file?
You don't have to do this in a hook. Do it in your theme as the theme is responsible for generating the whole document, including the <html> and <head> sections.
In the theme, override templates/portal_normal.vm. It should be obvious where to put the script reference.
You'll override this file by creating a docroot/_diffs/templates folder and copy docroot/templates/portal_normal.vm to that location. Then edit the file in docroot/_diffs/templates, build and deploy your theme.

Resources