def check40BitOptions(self):
        userPass = '******'
        for canPrint in (0, 1):
            for canModify in (0, 1):
                for canCopy in (0, 1):
                    for canAnnotate in (0, 1):
                        for strength in (40, 128):
                            # work out a 4-char string to be a mnemonic for the options
                            p = m = c = a = 'x'
                            if canPrint: p = 'P'
                            if canModify: m = 'M'
                            if canCopy: c = 'C'
                            if canAnnotate: a = 'A'

                            filename = 'test_crypto_%03dbit_%s_%s%s%s%s.pdf' % (
                                strength, userPass, p, m, c, a)
                            import os
                            filepath = outputfile(filename)
                            canv = Canvas(filepath)

                            canv.setFont('Helvetica', 24)
                            canv.drawString(100, 700,
                                            'PDF Encryption test case')
                            canv.setFont('Helvetica', 16)
                            canv.drawString(
                                100, 675,
                                'Verify by looking at File - Document Info - Security'
                            )

                            canv.drawString(100, 600,
                                            'open password = %s' % userPass)
                            canv.drawString(100, 575,
                                            'strength = %d buts' % strength)
                            canv.drawString(100, 500,
                                            'canPrint = %d' % canPrint)
                            canv.drawString(100, 475,
                                            'canModify = %d' % canModify)
                            canv.drawString(100, 450, 'canCopy = %d' % canCopy)
                            canv.drawString(100, 425,
                                            'canAnnotate = %d' % canAnnotate)

                            encryptCanvas(canv,
                                          userPass,
                                          canPrint=canPrint,
                                          canModify=canModify,
                                          canCopy=canCopy,
                                          canAnnotate=canAnnotate,
                                          strength=strength)

                            canv.save()
                            if VERBOSE: print('saved %s' % filepath)
Ejemplo n.º 2
0
    def check40BitOptions(self):
        userPass = '******'
        for canPrint in (0, 1):
            for canModify in (0, 1):
                for canCopy in (0, 1):
                    for canAnnotate in (0, 1):
                        for strength in (40, 128):
                            # work out a 4-char string to be a mnemonic for the options
                            p = m = c = a = 'x'
                            if canPrint: p = 'P'
                            if canModify: m = 'M'
                            if canCopy: c = 'C'
                            if canAnnotate: a = 'A'

                            filename = 'test_crypto_%03dbit_%s_%s%s%s%s.pdf' % (
                                strength, userPass, p, m, c, a)
                            import os
                            filepath = outputfile(filename)
                            canv = Canvas(filepath)
                            
                            canv.setFont('Helvetica', 24)
                            canv.drawString(100,700, 'PDF Encryption test case')
                            canv.setFont('Helvetica', 16)
                            canv.drawString(100, 675, 'Verify by looking at File - Document Info - Security')

                            canv.drawString(100, 600, 'open password = %s' % userPass)
                            canv.drawString(100, 575, 'strength = %d buts' % strength)
                            canv.drawString(100, 500, 'canPrint = %d' % canPrint)
                            canv.drawString(100, 475, 'canModify = %d' % canModify)
                            canv.drawString(100, 450, 'canCopy = %d' % canCopy)
                            canv.drawString(100, 425, 'canAnnotate = %d' % canAnnotate)

                            encryptCanvas(canv,
                                          userPass,
                                          canPrint=canPrint,
                                          canModify=canModify,
                                          canCopy=canCopy,
                                          canAnnotate=canAnnotate,
                                          strength=strength)
                            
                            canv.save()
                            if VERBOSE: print 'saved %s' % filepath
Ejemplo n.º 3
0
def drawPageFrame(canvas, doc):
    width, height = A4
    canvas.saveState()
    encryptCanvas(canvas, "test")
    canvas.drawImage(__jpgname, 0, 0, height, width, preserveAspectRatio=True, anchor='c')
    canvas.restoreState()