Opening PDF in a browser with Github Pages [closed] - web

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 months ago.
Improve this question
I am using GitHub Pages to host my website. I have a PDF file that I want visitors to be able to open directly in a browser. But when I upload the PDF file to GitHub Pages and link to it it opens in GitHub's viewer. Is there any way to open the PDF in a browser? I do not want to upload the document to dropbox or Google Drive as these services are not available in certain countries.
Using a raw URL would lead to download. But I would like to have the file open in the browser.

Suppose your personal website is hosted in a Github page as follows:
https://username.github.io
The repository should be name as username.github.io. If you have a pdf file named document.pdf and you place it in the directory folder then you should be able to open it directly in the browser through the following link:
https://username.github.io/folder/document.pdf
To allow the user to open the pdf in a new window in the browser, you may use the following HTML, where "PDF" points to the link:
PDF.

Instead of loading your PDF directly from GitHub, include it in your GitHub Pages branch as a static file. This can be done by simply putting the file somewhere in your source tree:
Every other directory and file except for those listed above—such as css and images folders, favicon.ico files, and so forth—will be copied verbatim to the generated site. There are plenty of sites already using Jekyll if you’re curious to see how they’re laid out.
So put the PDF somewhere that makes sense, for example in pdfs/foo.pdf.
To make a link to this PDF work both locally and on GitHub Pages, Jekyll recommends the following (note especially point #2):
Sometimes it’s nice to preview your Jekyll site before you push your gh-pages branch to GitHub. However, the subdirectory-like URL structure GitHub uses for Project Pages complicates the proper resolution of URLs. Here is an approach to utilizing the GitHub Project Page URL structure (username.github.io/project-name/) whilst maintaining the ability to preview your Jekyll site locally.
In _config.yml, set the baseurl option to /project-name – note the leading slash and the absence of a trailing slash.
When referencing JS or CSS files, do it like this: {{ site.baseurl }}/path/to/css.css – note the slash immediately following the variable (just before “path”).
When doing permalinks or internal links, do it like this: {{ site.baseurl }}{{ post.url }} – note that there is no slash between the two variables.
Finally, if you’d like to preview your site before committing/deploying using jekyll serve, be sure to pass an empty string to the --baseurl option, so that you can view everything at localhost:4000 normally (without /project-name at the beginning): jekyll serve --baseurl ''
So now you can link to your PDF with {{ site.baseurl }}/pdfs/foo.pdf.

It's very easy to display Pdf in browser from Github static page, for that you need approach following process,
Make the static website/repository using your Github username, for example, if the username is sumanbogati then repository would be sumanbogati.github.io
Put the desired pdf in that repository
Now locate the Url of Pdf wherever you want
For example, to display pdf in Html web page
<embed src="https://sumanbogati.github.io/sample.pdf" type="application/pdf" />
This is an instant demo.

I have gone through most of the answers in this section however most of them are hard to figure out or too vague to understand what is happening. There is a simpler way to do this, so in order to display a Pdf file in a browser from Github here is the process:
Step 1: Make the static website/repository using your Github username for example, if the username is winterishere then repository would be winterishere.github.io
Step 2: Put the desired pdf in that repository and add an index.html file in the same location as the pdf file eg: resume.pdf.
Step 3: Open the index.html and add the embed tag to it below:
<embed src="https://yourusername.github.io/filename.pdf" width="100%" height="850px"/>
in my example the file the code would be:
<embed src="https://winterishere.github.io/resume.pdf" width="100%" height="850px"/>

Use Google Docs viewer with a URL like:
https://docs.google.com/viewer?url={link_to_pdf}
e.g.
https://docs.google.com/viewer?url=https://username.github.io/folder/document.pdf

Inside the index.html use this
<embed src="/Repo_Name/Resume_Name.pdf" width="100%" height="745px" />
This worked for me, check
** Only good for Laptop view

Make an file called index.html in your repository with only the following code in it:
<iframe src="./yourfile.pdf" width="100% height=100%">
</iframe>
Your pdf file needs to be in the same directory as your "index.html" file. This means that both your pdf file and index.html file need to be uploaded to your git hub repository. Then you can use github pages pointed to your "index.html" file to display the pdf in a browser.
Using the <iframe> tag is better now because the <embed> tag is no longer supported in some browsers/devices.

My solution:
put the file in https://my.github.io/files/paper.pdf
add link mypdf
push the changes.
Now if you click the mypdf link, it should open in browser directly.

Please feel free to try the below method as it worked for me on my Github pages.
We need two files:
a)Resume.html
b)Resume.pdf
Put these two files in the primary working directory. These files must be in the same directory as your "index.html" file.
Add the following to the HTML file you are working in (let's say its index.html):
<li><a href="./Resume.html" target="_blank">
<p>resume</p>
</a></li>
Then, add the following to the resume.html you just created:
<embed src="./Resume.pdf" type="application/pdf" width=100% height=850px />
What it'll do:
After the primary HTML (i.e. index.html) is loaded and you click the resume text present in it, a new window should open and load resume.html, and this resume.html will load Resume.pdf.

Place the PDF file in a folder like; www.website/pdf/example.pdf this will stop the file downloading outside of the root directory.
The steps are:
1. Create a new file in main directory.
2. Name file /pdf/ and save it.
3. Upload example.pdf file to this folder
Result:: PDF is viewable at; www.website/pdf/example.pdf
4. Optional step to avoid the .pdf URL. Create a index.html file in this folder and create a blank html file with PDF embed tag:

You can link it this way
<a target='_blank' href={require('path/to/pdf/file')}>PDF Doc</a>
Then, when you push to GitHub page, you will see your pdf file path as so
https://userName.github.io/repoName/static/media/pdfFileName.hashNumber.pdf
I believe it works if you import the file instead of using require as well but I haven't tested with that.

Related

How can I make a main URL with sub URL for different Django app?

I want to make a main URL and that URL will be the main route for all my Django apps.
Suppose I have 3 apps: blog, linux and business. I want to make URLs like this:
127.0.0.1:8000/blog/ (when i will click blog menu)
127.0.0.1:8000/blog/linux ( when i will click linux menu)
127.0.0.1:8000/blog/business (when i will click business menu)
The blog app will be my index home page and all the apps' links will be like this. I don't want to import all of the views and models in the blog app. The project's structure will be the same and I don't want to change it.
All I want is to make blog common for all the apps. If I click a post on a linux page, the URL will be like this:
127.0.0.1:8000/blog/linux/post name
How can I do this?
This is my project's structure:
[]
You can write all the URLs into the urls.py in your project folder or you can make a urls.py in your apps folder. Maybe read this
After Creating the App in django project by following procedure in https://docs.djangoproject.com/en/3.0/intro/tutorial01/
App Folder (blog app folder, found inside project folder)
Add these urls
127.0.0.1:8000/blog/linux
127.0.0.1:8000/blog/business
to the app/urls.py file above the admin.site url path
Project Folder:
Configure the urls.py file in the project folder by adding the 127.0.0.1:8000/blog/ url above the admin.site url path. This configuration is done to load this url when the server starts running.
The django checks for the requested url pattern and will route the first discovered url.
The django cannot identify duplicate url.

Non-english url path

In next.js that uses php-like approach - files in pages folder became url paths. Like /pages/reader.js will be loaded by url http://localhost/reader.
Problem is that i can't undersand how to use non-english url path in next.js?
Codesandbox example. (Update page to load from server)
Url example:
http://localhost/читатель
That changes internally by chrome to:
http://localhost/%D1%87%D0%B8%D1%82%D0%B0%D1%82%D0%B5%D0%BB%D1%8C
In next.js pages folder file named:
pages/читатель.tsx // not working
pages/%D1%87%D0%B8%D1%82%D0%B0%D1%82%D0%B5%D0%BB%D1%8C.tsx //working but i can't name files like that, i will not find what i need later.
Maybe php users resolved this somehow ;)
try to use encodeURI() of core javascript which can convert the specific characters to the required url form
const url=encodeURI('читатель.tsx');
console.log(url);//%D1%87%D0%B8%D1%82%D0%B0%D1%82%D0%B5%D0%BB%D1%8C.tsx
Then we can use this path to navigate

Image(s) not showing when using nodejs with handlebars (.hbs)

I have tried to search for an answer here but nothing so far worked, not many threads about handlebars. Im at my 2nd year of coding and struggling to get images to show up on my node app.
I have this on app.js and below that the code im trying to get image to show up on the .hbs file:
app.use(express.static('img/'));
<img src="bckground.jpg" alt="teeest" />
Thank you in advance if someone knows what to do.
Supposing that you are serving your application at "http://localhost:3000", and your web page is "http://localhost:3000/index.html", you are requesting the image "bckground.jpg", so the browser will try to load "http://localhost:3000/bckground.jpg". This is wrong, because you are serving the static images folder under the "img" path, so the image is available at "http://localhost:3000/img/bckground.jpg".
If your application is being served at the "root" path of the domain, then this should work for you:
<img src="/img/bckground.jpg" />
Note the initial "/" at the image path. This means that the path will be calculated from the root folder of the domain. You should take this into account if you are serving your application in a subfolder.

Refreshing URL glitch - cloud updating/rewriting

Hello I've created an VBA script which saves me jpg from excel and then gsync uploads it on gDrive, but here comes the thing. The URL for downloading is volatile and I need full resolution image.
There is link so you can open in awful google UI
and I would like to open THIS => volatile link :(
Or can I use this VBA to upload image on some other Cloud directly from excel?
You can either use the Drive SDK to get the file details including the latest temporary download link:
https://developers.google.com/drive/v2/reference/files/get
...or you can make a parent or grandparent folder public and work out a URL direct to the image using its filename, like this:
http://gappstips.com/gmail/use-google-drive-to-host-your-gmail-signature/
http://drive.google.com/uc?export=view&id= "ID"
If you change URL in view mode you can view that image dirrect.
There are other files types.

TYPO3: extension with both backend module and frontend plugin

I am trying to create an extension ('XML Uploader') with a backend module and a frontend plugin also.
The backend module will be used for managing xml files (upload, validate against a DTD), and the frontend plugin should be used for displaying the uploaded xmls.
The problem is with the frontend part:
I followed
the basic extension tutorial - added a new page, created a content element of type 'Insert plugin' - but when trying to add a new record, the type 'XML Uploader' does not appear in the list of new record types. Moreover, the changes made to class.tx_xmluploader_pi1.php have no effect.
So how should I work with the frontend plugin? Or would it be better to create a separate extension instead?
Any help would be very much appreciated.. Thank you.
When creating your table with the extension kickstarter you must check the "Allowed on pages:" checkbox to allow records from this table to be created on regular pages.
If your changes have no effect, it could be that the page is cached by typo3. In that case you can clear or disable the cache with the admin panel or in the page configuration menu.
You have to include the static template of your extension (I presume you used the kickstarter or extension_builder):
go to the your template, in the object browser you should see something like:
plugin.tx_xmluploader_pi1 = USER
if you can't find it, edit your template (edit/modify => edit whole template record) and add your extension template in the tab 'Includes'
Additionally, check your ext_localconf.php for the line
t3lib_extMgm::addPItoST43($_EXTKEY, 'pi1/class.tx_xmluploader_pi1.php', '_pi1', 'list_type', 0);
This is where your FE plugin is being registered.

Resources