def save_fig(self, base, pictures, docx):
     base = os.path.join(base, "pic")
     util.checkout_directory(base)
     pic_dir = os.path.join(base, pictures.directory)
     util.checkout_directory(pic_dir)
     processed_pics = set()
     i = 0
     j = 0
     for p in pictures.picture_ids:
         p_id = p.id
         if not processed_pics.__contains__(p_id):
             processed_pics.add(p_id)
         else:
             continue
         img = docx.part.related_parts[p_id]
         file_type = img.filename.split(".")[-1]
         if p.type == "TSSI":
             pic_name = p.inte + "_" + p.type + "_" + str(i + 1)
             with open(
                     os.path.join(pic_dir,
                                  "{}.{}".format(pic_name, file_type)),
                     "wb") as f:
                 f.write(img.blob)
             i = +1
         elif p.type == "TSIM":
             pic_name = p.inte + "_" + p.type + "_" + str(j + 1)
             with open(
                     os.path.join(pic_dir,
                                  "{}.{}".format(pic_name, file_type)),
                     "wb") as f:
                 f.write(img.blob)
             j = +1
Exemple #2
0
 def save_fig(self, base, pictures, docx):
     base = os.path.join(base, "图片数据")
     util.checkout_directory(base)
     pic_dir = os.path.join(base, pictures.directory)
     util.checkout_directory(pic_dir)
     processed_pics = set()
     for i, p_id in enumerate(pictures.picture_ids):
         if not processed_pics.__contains__(p_id):
             processed_pics.add(p_id)
         else:
             continue
         img = docx.part.related_parts[p_id]
         file_type = img.filename.split(".")[-1]
         with open(os.path.join(pic_dir, "{}.{}".format(str(i + 1), file_type)), "wb") as f:
             f.write(img.blob)
Exemple #3
0
 def save_fig_PDF(self, base, pictures):
     base = os.path.join(base, "图片数据")
     util.checkout_directory(base)
     pic_dir = os.path.join(base, pictures.directory)
     util.checkout_directory(pic_dir)
     for i, pix in enumerate(pictures.pixes):
         new_name = "{}.png".format(i + 1)
         # 如果pix.n<5,可以直接存为PNG
         if pix.n < 5:
             path = os.path.join(pic_dir, new_name)
             pix.writePNG(path)
         # 否则先转换CMYK
         else:
             pix0 = fitz.Pixmap(fitz.csRGB, pix)
             pix0.writePNG(os.path.join(pic_dir, new_name))
             pix0 = None
         # 释放资源
         pix = None