2019年6月

# -*- coding:utf-8*-
import sys
reload(sys)
sys.setdefaultencoding('utf-8')


import os
import os.path
from pyPdf import PdfFileReader,PdfFileWriter
import time
time1 = time.time()


# 使用os模块walk函数,搜索出某目录下的全部pdf文件
######################获取同一个文件夹下的所有PDF文件名#######################

def getFileName(filepath):
    file_list = []
    for root,dirs,files in os.walk(filepath):
        for filespath in files:
            #print(filespath)
            if filespath[-3:] == 'pdf':
                file_list.append(os.path.join(root, filespath))

    return file_list



##########################合并同一个文件夹下所有PDF文件########################

def MergePDF(filepath,outfile):
    output=PdfFileWriter()
    outputPages=0
    pdf_fileName=getFileName(filepath)
    for each in pdf_fileName:
        print each
        # 读取源pdf文件
        input = PdfFileReader(file(each, "rb"))

        # 如果pdf文件已经加密,必须首先解密才能使用pyPdf
        if input.isEncrypted == True:
            input.decrypt("map")

        # 获得源pdf文件中页面总数
        pageCount = input.getNumPages()
        outputPages += pageCount
        print pageCount

        # 分别将page添加到输出output中
        for iPage in range(0, pageCount):
            output.addPage(input.getPage(iPage))


    print "All Pages Number:"+str(outputPages)
    # 最后写pdf文件
    outputStream=file('e:\\pdf\\' + outfile, "wb")
    output.write(outputStream)
    outputStream.close()
    print "finished"


def rename(path):
    #path = "E:\\Website\\test\\".decode('utf-8').encode('GB2312')
    filelist = os.listdir(path)
    for files in filelist:
        olddir = os.path.join(path,files)
        if os.path.isdir(olddir):
            print olddir.decode('GB2312').encode('utf-8')
            MergePDF(olddir, 'xlzs' + files + '.pdf')


if __name__ == '__main__':
    file_dir = 'E:\Website\中心医院\杏林之声pdf201501-201904'.decode('utf-8').encode('GB2312')
    out = u"第一周.pdf"
    rename(file_dir)
    #MergePDF(file_dir,out)
    time2 = time.time()
    print u'总共耗时:' + str(time2 - time1) + 's'

注意事项:路径的正确写法、证书文件的指定

#
# This is the Apache server configuration file providing SSL support.
# It contains the configuration directives to instruct the server how to
# serve pages over an https connection. For detailed information about these 
# directives see <URL:http://httpd.apache.org/docs/trunk/mod/mod_ssl.html>
# 
# Do NOT simply read the instructions in here without understanding
# what they do.  They're here only as hints or reminders.  If you are unsure
# consult the online docs. You have been warned.  
#

#
# Pseudo Random Number Generator (PRNG):
# Configure one or more sources to seed the PRNG of the SSL library.
# The seed data should be of good random quality.
# WARNING! On some platforms /dev/random blocks if not enough entropy
# is available. This means you then cannot use the /dev/random device
# because it would lead to very long connection times (as long as
# it requires to make more entropy available). But usually those
# platforms additionally provide a /dev/urandom device which doesn't
# block. So, if available, use this one instead. Read the mod_ssl User
# Manual for more details.
#
#SSLRandomSeed startup file:/dev/random  512
#SSLRandomSeed startup file:/dev/urandom 512
#SSLRandomSeed connect file:/dev/random  512
#SSLRandomSeed connect file:/dev/urandom 512


#
# When we also provide SSL we have to listen to the 
# standard HTTP port (see above) and to the HTTPS port
#
# Note: Configurations that use IPv6 but not IPv4-mapped addresses need two
#       Listen directives: "Listen [::]:443" and "Listen 0.0.0.0:443"
#
Listen 443

##
##  SSL Global Context
##
##  All SSL configuration in this context applies both to
##  the main server and all SSL-enabled virtual hosts.
##

#   Pass Phrase Dialog:
#   Configure the pass phrase gathering process.
#   The filtering dialog program (`builtin' is a internal
#   terminal dialog) has to provide the pass phrase on stdout.
SSLPassPhraseDialog  builtin

#   Inter-Process Session Cache:
#   Configure the SSL Session Cache: First the mechanism 
#   to use and second the expiring timeout (in seconds).
#SSLSessionCache         "dbm:E:/phpStudy2018/PHPTutorial/Apache/logs/ssl_scache"
SSLSessionCache        "shmcb:E:/phpStudy2018/PHPTutorial/Apache/logs/ssl_scache(512000)"
SSLSessionCacheTimeout  300

##
## SSL Virtual Host Context
##
<VirtualHost weixin.linsen18.com:443>

    DocumentRoot "E:/phpStudy/WWW/newshop"

    ServerName  weixin.linsen18.com:443

    ServerAdmin 75303307@qq.com

    DirectoryIndex index.html index.htm index.php

    ErrorLog E:/phpStudy2018/PHPTutorial/Apache/logs/example_error.log

   

    SSLEngine On

    SSLCertificateFile "E:/phpStudy2018/PHPTutorial/Apache/conf/ssl/2307291_weixin.linsen18.com_public.crt"

    SSLCertificateKeyFile "E:/phpStudy2018/PHPTutorial/Apache/conf/ssl/2307291_weixin.linsen18.com.key"

    SSLCertificateChainFile "E:/phpStudy2018/PHPTutorial/Apache/conf/ssl/2307291_weixin.linsen18.com_chain.crt"

<FilesMatch "\.(shtml|phtml|php)$">

    SSLOptions +StdEnvVars

</FilesMatch>

    #BrowserMatch "MSIE [2-5]" \

    #nokeepalive ssl-unclean-shutdown \

    #downgrade-1.0 force-response-1.0



</VirtualHost>