TT

Friday, 9 September 2016

How to generate the pdf in python using PDFKIT



  •  First of we need to install the PDFKIT using the below command on terminal.
    • pip install pdfkit
    • you can visit this link for more information : https://pypi.python.org/pypi/pdfkit
  • We perform the two usecase of this.
    • Generate the PDF from URL. In This u just need to pass the URL and name of the file as below.
      • pdfkit.from_url('https://pypi.python.org/pypi/pdfkit', 'pdfkit.pdf')
    • Same thing u can perfom to convert the file as like 
      • pdfkit.from_file('yourfile.html', 'anyname.pdf')
    • Now Generate the pdf from String. Suppose you are integrating some third party software, so they provide the document in base64 formart. So First you can convert them from base64 to binary , store them into varible and then pass to pdfkit to convert in pdf.
      • pdfkit.from_string('binarystrinf', 'anyname.pdf')
  • If You want to store the pdf in variable then pass the False instead of the filename.
  • You can pass the option as third parameter to format the pdf , which include the margintop, paper size etc.
  • So like wise this u can generate the pdf from different source and apply the options.

Code


# Import the library
import pdfkit

# Generate PDF from URL
pdfkit.from_url('https://pypi.python.org/pypi/pdfkit', 'demo1.pdf')


# Convert base64 to binary and then generate the pdf.
import binascii

base64string = 'TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlzIHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2YgdGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGludWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRoZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4='

binarystring = binascii.a2b_base64(base64string)

pdfkit.from_string(binarystring, 'demo2.pdf')

# Store pdf in variable pass the second argument as 'False'
stored_pdf = pdfkit.from_string(binarystring, False)

# Pass the options to format the pdf
options = {
    'page-size': 'Letter',
    'margin-top': '0.75in',
    'margin-right': '0.75in',
    'margin-bottom': '0.75in',
    'margin-left': '0.75in',
    'encoding': "UTF-8",
    'no-outline': None
}
pdfkit.from_string(binarystring, 'demo3.pdf', options=options)


    



Wednesday, 10 June 2015

How to apply Compiz Effect in ubuntu 12.04



Steps

  • First of all install the "Compiz configuration settings manager" from "synaptic Package manager"
  • Open "synaptic Package manager" and in search write "compiz"
  • Now you have to install two thing as given below from synaptic manager 
    • Compiz configuration settings manager (compizconfig-setting-manager)
    • Collection of extra plugins (compiz-plugins-extra)
  • If both option is untick then tick them and click on apply one by one.
  • Now opeen the "Compiz configuration settings manager" by typing "ccsm" from dash
  • Now click on "Effects" and then tick the following option
    •  Animations
    •  Animations Add-ons
  • When You minimize the window there is no effect.
  • Now click on "Animations" the go to "minimize animation"
  • Double click on "Zoom" under the "Minimize effect"
  • Select effect to "Random" and duration to "500" and close that one.
  • Now tick mark the "Burn" from Random Effects and enjoy.
  • You can also apply different effect as you like.   

Video





Tuesday, 12 May 2015

How to Copy/backup thunderbird data or move mail to another PC in ubuntu 12.04 ??

Steps

  • First of all open the home folder
  • Then Press the ctrl+h to open hidden folder
  • You will found  the .thunderbird folder
  • Open that folder , inside that you will found 
    • Crash reports folder
    • Another folder with with .default extension
  • Open that .default extension folder and copy all data
  • Save that data at safe place and whenever in other pc it required 
  • For move open the same .default folder in other PC where it required again and paste that data.
  • Restart the thunderbird , it will show all your mails which are in old PC

Video