#NEWLINE# def createPDF( self , name = None , size = '10kb' ) : #NEWLINE# #INDENT# from PyPDF2 import PdfFileReader , PdfFileWriter #NEWLINE# from fpdf import FPDF #NEWLINE# import os #NEWLINE# import random #NEWLINE# name = os . path . basename ( name ) #NEWLINE# tmp_name = ( '/tmp/' + name ) #NEWLINE# output_name = ( ( self . sharepath + '/' ) + name ) #NEWLINE# if ( size == '10kb' ) : #NEWLINE# #INDENT# randlength = random . randint ( 10000 , 90000 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( size == '100kb' ) : #NEWLINE# #INDENT# randlength = random . randint ( 100000 , 900000 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( size == '1mb' ) : #NEWLINE# #INDENT# randlength = random . randint ( 1000000 , 9000000 ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# pdf = FPDF ( ) #NEWLINE# pdf . add_page ( ) #NEWLINE# pdf . set_font ( 'Arial' , 'B' , 8 ) #NEWLINE# pdf . cell ( 0 , 0 , os . urandom ( randlength ) ) #NEWLINE# pdf . output ( tmp_name , 'F' ) #NEWLINE# output = PdfFileWriter ( ) #NEWLINE# input1 = PdfFileReader ( open ( tmp_name , 'rb' ) ) #NEWLINE# output . encrypt ( user_pwd = 'ihasapass' ) #NEWLINE# output . addPage ( input1 . getPage ( 0 ) ) #NEWLINE# outputStream = file ( output_name , 'wb' ) #NEWLINE# output . write ( outputStream ) #NEWLINE# outputStream . close ( )