網站首頁 編程語言 正文
‘’’
Author: zzx
Date: 2022-07-30 15:52:15
LastEditors: zdl
LastEditTime: 2022-07-30 16:03:20
FilePath: \matlabcodef:\BaiduNetdiskWorkspace\markdown寫雜談\python導出drawio文件
Description:
Copyright ? 2022 by zdl, All Rights Reserved.
‘’’
vscode一體化導出drawio
需要的工具:vscode, draw.io擴展,draw.io桌面版 、python
提示:這個方法并沒有簡化流程,只是能夠減少打開窗口,在vscode中直接查看原始文件,導出文件,效率并沒有顯著提升。
啰嗦的部分:
drawio流程圖繪制軟件比visio好用。而且vscode有插件。vs插件的優點在于支持mermaid流程圖,缺點非常明顯不支持指定分辨率圖像導出。
網上檢索發現drawio的桌面版可以在命令行操作。在drawio安裝目錄下運行cmd,然后通過draw.io -help 命令可以查看全部命令。
查看命令發現沒有針對性的dpi設置。我就想到給圖片輸入寬度和高度的方式。根據我猜測這個寬度和高度應該對應的就是像素點數量,所以我就按照實際尺寸,以及dpi的定義
寫了一個命令, 發現可用。但是每次都要計算寬度、高度、調用cmd命令窗口,太麻煩。功能強大的python加上插件齊全的vscode能不能全部實現呢?
折騰了幾個小時,終于搞定了。
進入正題:
1、安裝draw.io插件,和桌面版,記住桌面版的路徑
2、繪制好的圖片有一個實際的尺寸,記住實際尺寸的寬和高
3、python轉換 寬度
dpivalue=600#dpi
realwidth=89.4#mm
realheight=81.2#mm
width=round(dpivalue*realwidth/25.4)
height=round(dpivalue*realheight/25.4)
4、 構造命令行,不嫌麻煩可以自己寫完整目錄
inputfilepath=r'F:\BaiduNetdiskWorkspace\00typora\大論文\drawio\算法流程圖.drawio'
outputfilepath=r'F:\BaiduNetdiskWorkspace\00typora\大論文\drawio\test.png'
starttext=r'draw.io -x '
midletext=r" -f png -t --width "+str(width)+r" --height " +str(height)+r" -o "
commandtext1=starttext+inputfilepath+midletext+outputfilepath
5、 改變python文件工作目錄并執行命令
path="D:/draw.io/"#安裝文件夾
os.chdir( path )# 修改當前工作目錄
v2=os.system(commandtext1)
完整的代碼
代碼量并不大,非常簡單
'''
Author: zzx
Date: 2022-07-27 10:12:38
LastEditors: zdl
LastEditTime: 2022-07-30 16:10:22
FilePath: \matlabcodef:\BaiduNetdiskWorkspace\00typora\大論文\drawio\output.py
Description:
Copyright (c) 2022 by zdl, All Rights Reserved.
'''
import os
dpivalue=600#dpi
realwidth=89.4#mm
realheight=81.2#mm
width=round(dpivalue*realwidth/25.4)
height=round(dpivalue*realheight/25.4)
inputfilepath=r'F:\BaiduNetdiskWorkspace\00typora\大論文\drawio\算法流程圖.drawio'
outputfilepath=r'F:\BaiduNetdiskWorkspace\00typora\大論文\drawio\test.png'
starttext=r'draw.io -x '
midletext=r" -f png -t --width "+str(width)+r" --height " +str(height)+r" -o "
commandtext1=starttext+inputfilepath+midletext+outputfilepath
path="D:/draw.io/"#安裝文件夾
os.chdir( path )# 修改當前工作目錄
v2=os.system(commandtext1)
# 快速運行F5
# print(v2)
#關于python權限的問題
# https://blog.csdn.net/qq_33731081/article/details/103812749
# 如何在python中運行命令行命令
# https://blog.csdn.net/qq_34769162/article/details/119037908
#報錯為空值的問題
# https://blog.csdn.net/xiaoxiaogh/article/details/88320102
#關于drawio導出命令,靈感來源https://j2r2b.github.io/2019/08/06/drawio-cli.html
'''
Options:
-V, --version output the version number
-c, --create creates a new empty file if no file is
passed
-k, --check does not overwrite existing files
-x, --export export the input file/folder based on the
given options
-r, --recursive for a folder input, recursively convert
all files in sub-folders also
-o, --output <output file/folder> specify the output file/folder. If
omitted, the input file name is used for
output with the specified format as
extension
-f, --format <format> if output file name extension is
specified, this option is ignored (file
type is determined from output extension,
possible export formats are pdf, png, jpg,
svg, vsdx, and xml) (default: "pdf")
-q, --quality <quality> output image quality for JPEG (default:
90)
-t, --transparent set transparent background for PNG
-e, --embed-diagram includes a copy of the diagram (for PNG,
SVG and PDF formats only)
--embed-svg-images Embed Images in SVG file (for SVG format
only)
-b, --border <border> sets the border width around the diagram
(default: 0)
-s, --scale <scale> scales the diagram size
--width <width> fits the generated image/pdf into the
specified width, preserves aspect ratio.
--height <height> fits the generated image/pdf into the
specified height, preserves aspect ratio.
--crop crops PDF to diagram size
-a, --all-pages export all pages (for PDF format only)
-p, --page-index <pageIndex> selects a specific page, if not specified
and the format is an image, the first page
is selected
-g, --page-range <from>..<to> selects a page range (for PDF format only)
-u, --uncompressed Uncompressed XML output (for XML format
only)
--enable-plugins Enable Plugins
-h, --help display help for command
'''
原文鏈接:https://blog.csdn.net/weixin_39361931/article/details/126073760
相關推薦
- 2022-11-06 MobLink?Android端業務場景簡單說明_Android
- 2022-11-20 .Net中Task?Parallel?Library的基本用法_基礎應用
- 2022-07-30 Redis實現訂單過期刪除的方法步驟_Redis
- 2021-11-06 C/C++?Qt?StringListModel?字符串列表映射組件詳解_C 語言
- 2022-10-14 Sklearn中predict_proba函數用法及原理詳解
- 2022-12-07 Android?Flutter實現興趣標簽選擇功能_Android
- 2022-07-13 redis搭建哨兵集群的實現步驟_Redis
- 2022-12-28 React組件的生命周期深入理解分析_React
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支