Giter VIP home page Giter VIP logo

jp_pdf's Introduction

#How to install PhantomJS on a linux machine.

  1. connect to server via ssh
  2. change the user to root user with: su - or sudo su depending on what linux distro you have (centos or ubuntu)
  3. go to tmp folder cd /tmp
  4. Download latest phantom static build with: wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2
  5. Unzip the file with: tar -xjvf phantomjs-2.1.1-linux-x86_64.tar.bz2
  6. go to phantom folder cd phantomjs-2.1.1-linux-x86_64/bin
  7. move or copy the file phantomjs in your path: mv phantomjs /usr/bin/phantomjs or cp phantomjs /usr/bin/phantomjs
  8. check if the file is executable, if isn't please make it chmod a+x /usr/bin/phantomjs
  9. try to run the file from any folder phantomjs
  10. put in a folder, where you want the next js file:

convert.js

/********************************************/
var page = require('webpage').create();

// here you can set the viewport size
page.viewportSize = { width: 1200, height: 960 };

var syst = require('system');

var t = Date.now();

// set the default url if you want
var address = 'http://www.google.com';

if (syst.args.length < 2) {
  console.log('Usage: convert.js <some URL>');
  phantom.exit();
}

address = syst.args[1];

page.open(address, function(status){
    console.log('Status: ' + status);
    if (status === 'success') {
	    page.render('/your/path/for/pdf-files/' + t + '.pdf');
//    	page.render('/your/path/for/png-files/' + t + '.png');
    }
    phantom.exit();
});
/**********************************************/
  1. how to use the script from command line, in the folder where the convert.js is phantomjs convert.js http://test.adviceasdev.dk/maerskretool/print-example.html

after that, you will have a pdf file, something like 4545335353000.pdf in your folder

##Update

index.html is only a demo to show you how the things works

folders css, js and img are for demo only

convert.js is the file which make the conversion from html to pdf. this file will be run in command line by php

converttopdf.php - the file which generate html file and send it to convert.js

download.php - will return the pdf file and delete it from server

temporary files (html and pdf) will be saved in tmp folder and are automatically deleted when the pdf is downloaded.

don't forget to set the rights for tmp folder

chmod 755 tmp

jp_pdf's People

Contributors

morodan avatar morrocod avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.