From anonymous, 1 Week ago, written in Python.
Embed
  1. import pathlib
  2. import sys
  3. import win32com.client
  4.  
  5.  
  6. def set_ps(page, cell, value):
  7.     page.PageSheet.Cells(cell).Formula = value
  8.  
  9.  
  10. def convert(visio, path, out_path):
  11.     doc = visio.Documents.Open(str(path))
  12.  
  13.     for page in doc.Pages:
  14.         set_ps(page, "PageLeftMargin", "0mm")
  15.         set_ps(page, "PageRightMargin", "0mm")
  16.         set_ps(page, "PageTopMargin", "0mm")
  17.         set_ps(page, "PageBottomMargin", "0mm")
  18.         page.ResizeToFitContents()
  19.  
  20.     pdf_format = 1
  21.     intent_print = 1
  22.     print_all = 0
  23.     doc.ExportAsFixedFormat(pdf_format, out_path, intent_print, print_all)
  24.     doc.Close()
  25.  
  26.  
  27. def main():
  28.     visio = win32com.client.Dispatch("Visio.Application")
  29.     visio.AlertResponse = 7  # Answer "no" to all save dialogs
  30.  
  31.     basedir = pathlib.Path(sys.argv[1])
  32.     files = list(basedir.glob('*.vsdx'))
  33.     for i, path in enumerate(files, start=1):
  34.         print(f"[{i:3}/{len(files):3}] {path.stem}")
  35.         out_path = path.with_suffix(path.suffix + '.pdf')
  36.         if out_path.exists():
  37.             continue
  38.         convert(visio, path, out_path)
  39.  
  40.  
  41. if __name__ == '__main__':
  42.     main()