PDF Reader/editor in Ajax/ASP.Net - javascript

I am working on project that allows to read document within the browser without the need to install software , It's a part of a management application for companies.
I tried out to work with iTextSharp ,PDFSharp , but these labrories don't allows you to do what I want to do.It's just for generating pdf from HTML.
I checked out for another solution , I found an interesting project developed by Mozilla Lab . Mozilla is working on technology that will allow PDF documents to be rendered within the browser, rather than utilizing a browser plug-in or an external app to open them.
https://github.com/Marak/pdf.js/
I wonder to know Can I integer this script and use it with ASP.Net ? , If yes , I will be pleased to be guided by you with code source or external links that you recommend in order to implement this solution.

I believe that link you have sighted is about creating PDF file in browser (and not about showing existing PDF in browser).
Said that, there is another interesting project pdf.js that is trying to render PDF using java-script and HTML 5. Its essentially a java-script library that takes PDF bytes and attempt to render them. As such, you should able to integrate it in any web site regardless of server side technology - include the script and make relevant calls. See this simple example to get started.

Related

Convert HTML + CSS to PDF with nodeJS or Javascript?

I have a problem. I've tried some libraries that convert html to PDF but they don't import CSS, so my PDF is invalid.
I's tried with "html2pdf" , "pdfmake", "jspdf"..
PDFMake does not help me because it need to generate a JSON with HTML data...
The structure of file that I would like to convert to PDF is:
html: www/templates/phase_one_report.html
css: www/css/phase_one_report.css
Some ideas? I am using nodeJS with sailsJS in backend and javascript with ionic in frontend.
Sorry about my english.
This is a difficult problem. I have also found that existing HTML to PDF libraries usually don't handle the HTML & CSS that I throw at them.
The best solution I have found is not Javascript at all: wkhtmltopdf. This is essentially a program that wraps up the webkit rendering engine so that you can give it any HTML + CSS that webkit can render and it will return a PDF document. It does an outstanding job, since it's actually rendering the document just like a browser would.
You mention that you're using node.js, but it's not clear exactly what your environment is, so I'm going assume that your report is available at a URL like http://my.domain/phase_one_report.html. The simplest way to get this working would be to install the wkhtmltopdf application on your server, then use child_process.exec to execute it.
For example:
import { exec } from 'child_process';
// generate the report
// execute the wkhtmltopdf command
exec(
'wkhtmltopdf http://my.domain/phase_one_report.html output_file.pdf',
(error) => {
// send the PDF file to the client
}
);
There are a lot of different command-line options for wkhtmltopdf - you'll need to look into all the different ways to configure it.
If your report is not accessible at a URL, then this becomes a little more complicated - you'll need to inline the CSS and send everything to wkhtmltopdf at once.
There are a number of options available right now:
Edit 09/2018: Use puppeteer, the JS Headless Chrome driver. Firefox now also has headless mode but I'm not sure which library corresponds to puppeteer.
wkhtmltopdf as mentioned before does the job but is slightly outdated.
You will have to watch the latest chrome releases which will have a --headless option to enable html+css+js to pdf conversion.
Then there is PhantomJS and Slimer.js. Both are possible to use with node and Javascript. Nightmare.js is also an option but sits on top of it.
However, Phantom.js is currently the only solution that is truly headless and javascript based. Slimer.JS works with Firefox but requires you to have a window manager, at least xvfb, a virtual frame buffer.
If you want the latest browser features you will have to go with slimer.js or, another option, go with one of the Electron based solutions that keep popping up. Electron is based on Chrome and is scriptable too. A fine solution that also ships with Docker containers is currently https://github.com/msokk/electron-render-service
This list is possibly incomplete and will change a lot in the near future.

Deleting a file in JavaScript

I am developing a native android app using HTML/CSS/JavaScript. During the App flow, I need to permanently delete certain HTML files (stored locally). Can this be done?
I am a high school teacher trying to develop an educational app. I have basic knowledge of HTML/CSS and near zero knowledge of JavaScript!
modern broswer support javascript file operation but this file system is only in broswer and isolated from local files, refer https://developer.mozilla.org/en/docs/Web/API/File
if u do need delete file on android system, then u need your app provide a bridge to and call from js, run in app, in java code, delete the file
the code might look like
JsBradge.delete(file)
Javascript disigned as a web document script language, so it has many security essentials, such as absolute isolation in browser, which means no write acces to file system.
So, you have two options - first is create your own bridge to java, for example call prompt('your_file_name'), catch it in java and delete your_file_name.
Second - use any of mobile app framework, for example - Cordova.
Sorry, but no easy ways =(

Detecting Office addin host without including office.js

In our webapp, we would like to be able to show different content at the same URL based on the host from which the site is opened. E.g https://localhost:44300 will behave differently depending on if it is opened from within a browser or an office js taskpane.
While that is the case, we would like not to include the office.js javascript until we know that the website is accessed from within an office js taskpane. Therefore it is also not possible to use Office.context.requirements.isSetSupported.
The way we do it at the moment is by looking at the URL since it includes the _host_Info. As an example we make the following check right now
if(window.location.search.indexOf('_host_Info=Word') > -1) { /* initiate app for word js addin */ }
Even though this works, it doesn't seem to be a good solution - especially if we want to navigate to other pages on the website. We therefore hope that there could be another way that the Office js host could be detected without having to include Office.js script beforehand
The scenario you describe is not supported -- and truthfully, I wonder how often it is that you want to use the exact same site both as an Office add-in and a standalone website. What we've most often seen is that people will re-use some of the same common libraries and CSS, but have different html pages for each scenario.
Note, too, that when run as an Office add-in, the page must include a reference to Office.initialize. This again makes it hard to re-use the same website contents for both an add-in and a standalone site. So my recommendation would be to refactor and share what you can, but have 2 separate html presences.
Hope this helps,
~ Michael Zlatkovsky, developer on Office Extensibility team, MSFT

Attach PDF to PDF as attachment (not as a page) via Javascript in HTML (not in Acrobat)

I would like to generate a PDF portfolio using JS from an HTML/CSS page on a local machine. I would use a PDF template file which includes a PDF portfolio Navigator in SWF form. I have successfully accomplished this using C# and a command line program, but can not identify the proper Javascipt components to do this browser-side or pseuo-server with Node.js. Basically, I am looking for something which will allow me to append a PDF to a new or existing PDF via configuration choices and an 'assemble' action using a JS or HTML button. iTextSharp provides the required PDF interaction functionality, but I can not figure out to run this inside an HTML to allow configuration via the HTML/CSS DOM (i.e. checkboxes, text field desciptors, etc...). Does a library with this type of functionality exist?
So you want to create a PDF using JavaScript?
On a quick google search, I found what appears to be a javascript library for creating and manipulating PDFs call jsPDF
If you want information on how to upload files with JavaScript alone, here is an article on how to do that. It also shows you how to use the file element.
For style, I recommend using a CSS Framework is you don't know much about CSS. I personally use Twitter Bootstrap for quickly prototyping things. It's quick and easy, and has good documentation. You can also use this to see how to make a form in HTML. I haven't got any good starter tutorials for HTML off the top of my list, sorry.
If you don't know much about JavaScript, when it comes to getting the options from the form, so that you can use them as configuration options, I'd suggest using the jQuery framework. It'll help you get up and running quickly enough
Note, all of this shouldn't replace basic training in JavaScript and HTML/CSS. Frameworks make things simpler, but if you don't know how to do something without a framework, you're going to have a hard time with a lot of the more complicated things. This goes for every language

How can I crawl an HTML5 website and convert its HTML content to PDF (using a Python or Ruby library)?

I'm looking for an engine/solution/framework/gem/egg/lib/whatever for either Ruby or Python to log into a website, crawl HTML5 content (mainly charts on a canvas), and be able to convert it into a PDF file (or image).
I'm able to write crawling scripts in mechanize so I can log onto the website and crawl the data, but mechanize does not understand complex JavaScript + HTML5.
So basically I'm looking for an HTML5/JavaScript interpreter.
This question is a bit confusing... sorry re-read my answer after reading the question again.
Your question has two parts:
1. How can I crawl a website
Crawling can be done using Mechinize, but as you said, it doesn't do Javascript very well. So one alternative is to use Capybara-webkit or Selenium (firefox / chrome).
Usually this is used for testing, but you may be able to drive it using Ruby code to navigate the various pages.
2. How can I convert the output to PDF
If you need to convert the crawled content to PDF, I don't think there is a way to do that. You may be able to take a screenshot (useful for testing) using Capybara-webkit or Selenium, but converting that to PDF may be just a matter of pumping it through some command line utility.
If you're looking for a true HTML to PDF converter (usually used to generate reports from views in a rails app), then use PDFKit
Basically it's a WebKit browser that can output to PDF. Really simple to run with.

Categories

Resources