AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / computer / 问题 / 1534191
Accepted
Métoule
Métoule
Asked: 2020-03-21 02:15:00 +0800 CST2020-03-21 02:15:00 +0800 CST 2020-03-21 02:15:00 +0800 CST

Inkscape:保存没有漂亮打印的svg文件?

  • 772

我有一个从 Powerpoint 创建的 SVG 文件,现在我想在 Inkscape 中进行编辑。在 Inkscape 中打开并保存该文件时,不进行任何修改,文件大小从 120kB 变为 170kB(我将其保存为纯 SVG,而不是 Inkscape SVG)。

据我所知,这是因为 Inkscape 生成的 SVG 打印得很漂亮,因此有很多无用的空白。有没有办法在没有漂亮打印的情况下保存 SVG 文件?

例如,原始文件的这一部分:

<linearGradient x1="272" y1="618" x2="272" y2="643" gradientUnits="userSpaceOnUse" spreadMethod="reflect" id="fill25"><stop offset="0" stop-color="#D2D2D2"/><stop offset="0.5" stop-color="#C8C8C8"/><stop offset="1" stop-color="#C0C0C0"/></linearGradient>

保存为

<linearGradient
   id="fill1"
   spreadMethod="reflect"
   gradientUnits="userSpaceOnUse"
   y2="159"
   x2="272"
   y1="134"
   x1="272">
  <stop
     id="stop6277"
     stop-color="#D2D2D2"
     offset="0" />
  <stop
     id="stop6279"
     stop-color="#C8C8C8"
     offset="0.5" />
  <stop
     id="stop6281"
     stop-color="#C0C0C0"
     offset="1" />
</linearGradient>
inkscape svg
  • 1 1 个回答
  • 221 Views

1 个回答

  • Voted
  1. Best Answer
    Anaksunaman
    2020-03-23T15:05:36+08:002020-03-23T15:05:36+08:00

    有没有办法在没有漂亮打印的情况下保存 SVG 文件?

    需要注意的是,您可能需要查看SVG 输出首选项下的XML 格式化选项:

    前任。XML 格式

    Inkscape SVG 输出 XML 格式 - 屏幕截图

    这些选项应该可以通过Edit → Preferences → Input/Output → SVG output → XML Formatting获得。请注意,编辑 → 首选项也可通过Ctrl+ Shift+获得P(如所示)。

    标记Inline attributes(以上)的选项应保留前:

    <linearGradient
       id="fill1"
       spreadMethod="reflect"
       gradientUnits="userSpaceOnUse"
       y2="159"
       x2="272"
       y1="134"
       x1="272">
      <stop
         id="stop6277"
         stop-color="#D2D2D2"
         offset="0" />
      <stop
         id="stop6279"
         stop-color="#C8C8C8"
         offset="0.5" />
      <stop
         id="stop6281"
         stop-color="#C0C0C0"
         offset="1" />
    </linearGradient>
    

    例如:

    <linearGradient x1="272" y1="618" x2="272" y2="643" gradientUnits="userSpaceOnUse" spreadMethod="reflect" id="fill25"><stop offset="0" stop-color="#D2D2D2"/><stop offset="0.5" stop-color="#C8C8C8"/><stop offset="1" stop-color="#C0C0C0"/></linearGradient>
    

    注意事项

    • 使用 Inkscape 编辑的文件可能仍会应用一些小的开销,因为 Inkscape 可能以与原始格式略有不同的格式保存文件(即使使用 "plain" .svg)。

    • 关于前导空格等,“整个”.svg标签可能会缩进以进行漂亮的打印,例如:

      <g>
          <path fill="#FFFFFF" stroke="#F1F2F2" stroke-width="3" stroke-miterlimit="10" d="M314.267,104.257h-0.006H314.267z"/>
      

    如果我没记错的话,调整Indent, spaces目前似乎对.svg已经具有漂亮打印效果的文件没有任何影响。标签(即似乎此选项仅适用于新文件)。

    如果要确保删除前导空格等,您可能应该使用文本编辑器或脚本手动删除它们。

    • 您可以使用Notepad++等文本编辑器打开.svg文件,然后选择编辑 → 空白操作 → 修剪前导空格以删除前导空格。您还可以使用Edit → Line Operations → Remove Empty Lines删除任何空白行。

    • .svg您可以编写一个脚本来对给定目录中的一个或多个文件执行上述操作。例如,Python 3中的一个简短示例:

    前任。reduce_svg_files.py

        # Remove leading spaces and blank lines from a set of text files (e.g. ".svg"
        # files) in a directory with Python.
    
        # Preserves '\n' (linefeed) line endings (for file size considerations) by
        # reading/writing files as "binary".
    
        # This script would be run in the same directory as the original files.
    
    
        # --- Imports ---
    
        import os
        import os.path
        import sys
    
    
        # --- Variables ---
    
        # Where are the original files located?
        root_dir = '.\\'
    
        # What is the directory/path to write any reduced files to?
        mini_directory_name = 'mini'
        mini_output_directory = os.path.join(root_dir, mini_directory_name)
    
        # What file extension should the script work with?
        ext = '.svg'
    
        # What suffix should be added to the end of any reduced files?
        mini_suffix = ' - mini'
    
    
        # --- Main ---
    
        try:
    
            # Create the directory specified by "mini_output_directory", as needed.
            os.makedirs(mini_output_directory, exist_ok=True)
    
            # Read the directory contents (files and folder names) of "root_dir".
            directory_items = os.listdir(root_dir)
    
            # For every directory item returned...
            for directory_item in directory_items:
    
                # If that item is a file that also ends with "ext"...
                if os.path.isfile(directory_item) and directory_item.endswith(ext):
    
                    # Create a list to hold the reduced contents of the file.
                    svg_contents = []
    
                    # Read the contents of the original file.
                    with open(directory_item, 'rb') as svg_file:
    
                        # For each line in the file...
                        for svg_line in svg_file:
    
                            # Remove any leading spaces, etc. with ".lstrip()" and
                            # store each "cleaned" line in svg_contents[] (from above).
                            svg_contents.append(svg_line.lstrip())
    
                        # Then...
    
                        # Remove the "ext" from the original file name by replacing it
                        # with "nothing".
                        mini_title = directory_item.replace(ext, '')
    
                        # Add "mini_suffix" and then the "ext" back to the stripped
                        # file name to create the name for the reduced file.
                        mini_file = mini_title + mini_suffix + ext
    
                        # Create the full path to where the reduced file should be
                        # stored.
                        mini_path = os.path.join(mini_output_directory, mini_file)
    
                    # Write the reduced file to this path.
                    with open(mini_path, 'wb') as mini_output_path:
                        mini_output_path.writelines(svg_contents)
    
        # If there is a problem working with the OS while running the script, catch any
        # error then quit.
        except OSError as err:
    
            print('')
            print(err)
            sys.exit()
    

    请注意,上述两个选项都通过保留行尾来保留格式。正如您在评论中指出的那样,如果不担心行尾,您可以在 Notepad++ 中执行(大致)相同的两个步骤,其中一个操作为Edit → Blank Operations → Remove Unnecessary Blank and EOL(将任何.svg文件内容转换为带有空格的单个文本字符串)。

    如果您还想删除标签之间的空格,可以使用上面的 Python 脚本并更改:

    svg_contents.append(svg_line.lstrip())
    

    只是:

    svg_contents.append(svg_line.strip())
    

    但是请注意,.svg如果每行不包含“完整”<tag>元素(即确保原始.svg文件内容看起来像您想要的内容,而不是原始问题中不受欢迎的“元素列表”)。

    • 1

相关问题

  • Inkscape:带对象的完整路径

  • 如何在 Inkscape 中相对于中心对齐对象?

  • 如何更改 Inkscape 显示语言?

  • Inkscape 不显示新字体,新字体在所有其他程序中可用

  • Inkscape - 将文件导出为 pdf 会得到空的 pdf 文件(包括 SVG 文件)

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何减少“vmmem”进程的消耗?

    • 11 个回答
  • Marko Smith

    从 Microsoft Stream 下载视频

    • 4 个回答
  • Marko Smith

    Google Chrome DevTools 无法解析 SourceMap:chrome-extension

    • 6 个回答
  • Marko Smith

    Windows 照片查看器因为内存不足而无法运行?

    • 5 个回答
  • Marko Smith

    支持结束后如何激活 WindowsXP?

    • 6 个回答
  • Marko Smith

    远程桌面间歇性冻结

    • 7 个回答
  • Marko Smith

    子网掩码 /32 是什么意思?

    • 6 个回答
  • Marko Smith

    鼠标指针在 Windows 中按下的箭头键上移动?

    • 1 个回答
  • Marko Smith

    VirtualBox 无法以 VERR_NEM_VM_CREATE_FAILED 启动

    • 8 个回答
  • Marko Smith

    应用程序不会出现在 MacBook 的摄像头和麦克风隐私设置中

    • 5 个回答
  • Martin Hope
    CiaranWelsh 如何减少“vmmem”进程的消耗? 2020-06-10 02:06:58 +0800 CST
  • Martin Hope
    Jim Windows 10 搜索未加载,显示空白窗口 2020-02-06 03:28:26 +0800 CST
  • Martin Hope
    v15 为什么通过电缆(同轴电缆)的千兆位/秒 Internet 连接不能像光纤一样提供对称速度? 2020-01-25 08:53:31 +0800 CST
  • Martin Hope
    fixer1234 “HTTPS Everywhere”仍然相关吗? 2019-10-27 18:06:25 +0800 CST
  • Martin Hope
    andre_ss6 远程桌面间歇性冻结 2019-09-11 12:56:40 +0800 CST
  • Martin Hope
    Riley Carney 为什么在 URL 后面加一个点会删除登录信息? 2019-08-06 10:59:24 +0800 CST
  • Martin Hope
    zdimension 鼠标指针在 Windows 中按下的箭头键上移动? 2019-08-04 06:39:57 +0800 CST
  • Martin Hope
    jonsca 我所有的 Firefox 附加组件突然被禁用了,我该如何重新启用它们? 2019-05-04 17:58:52 +0800 CST
  • Martin Hope
    MCK 是否可以使用文本创建二维码? 2019-04-02 06:32:14 +0800 CST
  • Martin Hope
    SoniEx2 更改 git init 默认分支名称 2019-04-01 06:16:56 +0800 CST

热门标签

windows-10 linux windows microsoft-excel networking ubuntu worksheet-function bash command-line hard-drive

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve