word 转pdf 再转图片--用在轻社群发文章
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import fitz
import glob
import os
from win32com.client import Dispatch, constants, gencache
import sys,shutil
import datetime
print sys.getdefaultencoding()
#################word
def doc2pdf(input, output):
w = Dispatch("Word.Application")
try:
doc = w.Documents.Open(input, ReadOnly = 1)
doc.ExportAsFixedFormat(output, constants.wdExportFormatPDF,
Item = constants.wdExportDocumentWithMarkup, CreateBookmarks = constants.wdExportCreateHeadingBookmarks)
return 0
except Exception ,e:
print str(e)
return 1
finally:
w.Quit(constants.wdDoNotSaveChanges)
# Generate all the support we can.
def GenerateSupport():
# enable python COM support for Word 2007
# this is generated by: makepy.py -i "Microsoft Word 12.0 Object Library"
gencache.EnsureModule('{00020905-0000-0000-C000-000000000046}', 0, 8, 4)
#####################
inputdoc = sys.argv[1]
store_tmp = unicode(os.path.splitext(inputdoc)[0],'GBK')
print inputdoc
outputpdf = os.path.splitext(inputdoc)[0]+'.pdf'
if (not os.path.isabs(inputdoc)):
inputdoc = os.path.abspath(inputdoc)
if (not os.path.isabs(outputpdf)):
outputpdf = os.path.abspath(outputpdf)
try:
GenerateSupport()
rc = doc2pdf(inputdoc, outputpdf)
except Exception,e:
print str(e)
def rightinput(desc):
flag=True
while(flag):
instr = raw_input(desc)
try:
intnum = eval(instr)
if type(intnum)==int:
flag = False
except:
print('ÇëÊäÈëÕýÕûÊý£¡')
pass
return intnum
#pdffile = glob.glob("*.pdf")[0]
pdffile = outputpdf
pdffile = unicode(pdffile , "GBK")
print pdffile
doc = fitz.open(pdffile)
#flag = rightinput("ÊäÈ룺1£ºÈ«²¿Ò³Ã棻2£ºÑ¡ÔñÒ³Ãæ\t")
flag = 1
if flag == 1:
strat = 0
totaling = doc.pageCount
# else:
# strat = rightinput('ÊäÈëÆðÊ¼Ò³Ãæ£º') - 1
# totaling = rightinput('ÊäÈë½áÊøÒ³Ãæ£º')
pdf2png = os.path.join(os.path.dirname(__file__),'pdf2png')
pdf2png_old = os.path.join(pdf2png,'old')
if not os.path.isdir(pdf2png):
os.mkdir(pdf2png)
if not os.path.isdir(pdf2png_old):
os.mkdir(pdf2png_old)
n_t = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
for f in os.listdir(pdf2png):
#print f.endswith('png')
if f.endswith('png'):
try:
src = os.path.join(pdf2png,f)
dst = os.path.join(pdf2png_old,f)
shutil.move(src,dst)
except Exception,e:
pass
for pg in range(strat, totaling):
page = doc[pg]
zoom = int(100)
rotate = int(0)
trans = fitz.Matrix(zoom / 100.0, zoom / 100.0).preRotate(rotate)
pm = page.getPixmap(matrix=trans, alpha=False)
pm.writePNG(pdf2png+'/%s_%s_%s.png' % (store_tmp,n_t,str(pg+1)))
word 转pdf 再转图片--用在轻社群发文章的更多相关文章
- openOffice word转pdf,pdf转图片优化版
之前写了一个版本的,不过代码繁琐而且不好用,效率有些问题.尤其pdf转图片速度太慢.下面是优化版本的代码. spriing_boot 版本信息:2.0.1.RELEASE 1.配置信息: packag ...
- Word转pdf,再转图片插入PDF
WORD转PDF所需jar包: https://yangtaotao.lanzous.com/ice1jlc PDF转图片所需jar包: https://yangtaotao.lanzous.com/ ...
- C#实现 word、pdf、ppt 转为图片
office word文档.pdf文档.powerpoint幻灯片是非常常用的文档类型,在现实中经常有需求需要将它们转换成图片 -- 即将word.pdf.ppt文档的每一页转换成一张对应的图片,就像 ...
- word、pdf、ppt 转为图片
office word文档.pdf文档.powerpoint幻灯片是非常常用的文档类型,在现实中经常有需求需要将它们转换成图片 -- 即将word.pdf.ppt文档的每一页转换成一张对应的图片,就像 ...
- 解决word转pdf后图片失真
碰到问题: 将word转pdf后图片出现失真 问题分析: 上述问题必定跟图片类型和所用软件有关,现将不同图片在不同软件下的失真情况汇总,见表1 问题解决:迫不得已,不要使用截图:若必需要用,则word ...
- word转pdf图片问题
经过整理总结出两类问题:1,pdf文件下载文档中某些图片显示红叉. 问题现象:pdf是通过word转换成,发现源文件doc和docx文档均出现上述问题:只是某些图片显示红叉.通过这两点确定和文 ...
- CAD转PDF再由pdf转jpg图片
免费的PDF转JPG图片 https://www.gaitubao.com/pdf-to-jpg/
- 采用jacob实现word转pdf
网络上已经有很多这方面的内容,在用之前也是参考了好多别人的文章,下面记录下我自己的整合过程.整个过程都比较简单: 开发环境:win8 64位系统,在2008下面部署也是一样的. 文档要求jdk的版本要 ...
- C#操作word模板插入文字、图片及表格详细步骤
c#操作word模板插入文字.图片及表格 1.建立word模板文件 person.dot用书签 标示相关字段的填充位置 2.建立web应用程序 加入Microsoft.Office.Interop.W ...
随机推荐
- centos7 中没有service iptables save指令来保存防火墙规则
解决方法: systemctl stop firewalld 关闭防火墙yum install iptables-services 安装 iptables 服务systemctl enable ip ...
- Linux笔记本合上屏幕不待机
Linux笔记本合上屏幕不待机[]# vim /etc/systemd/logind.conf# This file is part of systemd.## systemd is free sof ...
- Centos开发小计
1. 生成静态库,linux下库的规则是lib开头 g++ -c code.cpp ar cr libcode.a code.o
- 深入理解 JavaScript 中的 class
在 ES6 规范中,引入了 class 的概念.使得 JS 开发者终于告别了,直接使用原型对象模仿面向对象中的类和类继承时代. 但是JS 中并没有一个真正的 class 原始类型, class 仅仅只 ...
- 第2课 auto类型推导(1)
第2课 auto类型推导(1) 一.auto类型推导 (一)与模板类型推导映射关系 1.auto类型推导与模板类型推导可以建立一一映射关系,它们之间存在双向的算法变换.auto扮演模板中T的角色,而变 ...
- lhgDialog弹窗提示窗口组件
原文地址:http://www.lhgdialog.com/api/ 在页面head引入lhgdialog(如果项目采用jQuery作为框架,则引用jQuery的库). <script type ...
- 【layui】日期选择一闪而过问题
添加 trigger: 'click',
- Vim 入门教程
Vim 入门教程 转载请保留以上信息 Vim 的教程相对比较零散,系统的教程比较少,我也阅读过不少教程,走过很 多弯路.借着 Vim-china 组织组建这一契机,整理下自己学习过的内容, 分享给大家 ...
- [转帖]智能合约和 DApp
智能合约和 DApp https://www.jianshu.com/p/5e7df3902957 2018.10.08 19:50:41字数 3,403阅读 9,819 2017年11月份和2018 ...
- ZYNQ笔记(6):普通自定义IP封装实现PL精准定时中断
软件的定时中断很难控制精准触发沿的位置,可以通过 PL-PS 的中断完成精准的定时中断.PL 的中断通过 Verilog 代码产生,这样紧密结合 PS-PL 的处理,发挥各自的优势. 一.PL 侧定时 ...