编辑 XPS 内容 [英] Edit XPS content

查看:50
本文介绍了编辑 XPS 内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,它应该将带有一些条形码的格式化文档发送到打印机.

I have got an application that is supposed to send a formatted document to a printer with some barcodes.

我制作了其他可与打印机配合使用并通过发送 xps 文件直接通过打印服务器打印的应用程序,所以我想我会尝试看看是否可以制作 .xps 文件,更改文本并完成它,但是我可以在网上找到的每篇文章都与创建 xps 文件有关,而不是更改它们.我觉得这应该是可能的,而且不必求助于在服务器上安装 Office 并通过那里打印会很好.那么我不妨使用 Open XML 和一个 .docx 文件.

I've made other applications that work with printers and print directly through the printserver by sending a xps file, so I thought I would try to see if I could make a .xps file, change the text and be done with it, however every article I can find on the net has to do with creating xps files and not changing them. I feel like it should be possible, and it would be nice not to have to resort to installing Office on the server and print through there. Then I might as well use Open XML and a .docx file.

这很简单.假设我想将 .xps 文件中的文本 INCNUMMER 更改为testing123".我该怎么做?

It is very simple. Let's say I want to change the text INCNUMMER in a .xps file to "testing123". How would I go about that?

我已经尝试了整个解压缩,打开 xml,找到文本,编辑,重新压缩,但恐怕 .xps 格式太多了,我不明白,无法使其工作.

I have tried the whole unzip, open the xml, find the text, edit, rezip but I'm afraid there's too much about the .xps format I don't understand to make that work.

最好的问候,卡斯帕.

推荐答案

如您所知,XPS 文件只是一个 ZIP 存档,其中包含许多具有特定名称和定义结构的文件和文件夹.

As you already know, an XPS file is just a ZIP archive containing a number of files and folders that have particular names and a defined structure.

在根级别有一个 Documents 文件夹,它通常只包含一个名为 1 的文档文件夹.其中包含一个 Pages 文件夹,其中包含一个或多个 .fpage 文件:这些文件定义了文档中每个页面的内容.

At the root level there is a Documents folder which will typically contain just a single document folder named 1. Inside that is a Pages folder containing one or more .fpage files: these define the content of each page in the document.

Documents
    1
        Pages
            1.fpage
            2.fpage
            etc

如果您在文本编辑器中打开这些 .fpage 文件,您将看到它们只是 XML 文件.每个页面通常由一个 元素表示,该元素包含多个 元素(文本表示由后者).但是,即使 元素确实具有 UnicodeString 属性,该属性的值也不能单独更改.

If you open up these .fpage files in a text editor you will see that they are just XML files. Each page is typically represented by a <Canvas> element that contains multiple <Path> and <Glyphs> elements (text is represented by the latter). However, even though <Glyphs> elements do have a UnicodeString attribute the value of that attribute cannot be changed in isolation.

每个 元素也有一个 Indices 属性.如果您完全删除此属性并同时更改 UnicodeString 属性,则此几乎有效.但是,您可能会发现在 XPS 查看器应用程序中查看文件时,文本中的某些字符被问号符号替换.

Each <Glyphs> element also has an Indices attribute. If you remove this attribute altogether and change the UnicodeString attribute at the same time, this almost works. However, you will probably find that when viewing the file in the XPS Viewer application certain characters in the text are replaced by question mark symbols.

字体字形嵌入在 XPS 文件中(Resources 文件夹中的 odttf 文件),生成 XPS 文件的软件只会嵌入在 XPS 文件中使用的字形源文件.例如,这意味着(对于给定的字体)如果您没有在源文档中使用字母A",那么该字母的字形将不会写入 XPS 文件的资源中.因此,如果您将 UnicodeString 属性更改为包含字母A",那么该字符将在查看器中显示为问号,因为它没有告诉它必须如何绘制该字符的字形资源.

Font glyphs are embedded in the XPS file (odttf files in the Resources folder), and the software that generated the XPS file will only embed glyphs that are used in the source document. For example, this means that (for a given font) if you did not use the letter "A" in the source document, then the glyph for that letter will not be written to the resources of the XPS file. Hence if you change the UnicodeString attribute to include a letter "A" then that character will display as a question mark in the viewer because it has no glyph resource that tells it how that character must be drawn.

如果您可以控制源文档(后来转换为 XPS 的文档),那么我想您可以包含一段包含您可能使用的所有字符的文本,并将其颜色设置为白色它不打印,但我不确定 XPS 打印机驱动程序是否会删除该文本.如果它没有那么你可能会做这样的事情:

If you have control over the source document (the one that later gets converted to XPS) then I suppose you could include a piece of text containing all of the characters that you are likely to use, and set its colour to white so that it doesn't print, but I'm not sure whether the XPS printer driver would strip that text out anyway. If it didn't then you could probably do something like this:

  • 打开相关的.fpage XML 文件
  • 搜索 元素的所有 UnicodeString 属性以找到您想要的文本
  • 用其他内容替换该文本
  • 从更改后的 元素中移除 Indices 属性
  • 将更新的 XML 保存回文件
  • 重新压缩,然后将扩展名从 ZIP 更改为 XPS
  • Open the relevant .fpage XML file
  • Search all UnicodeString attributes of <Glyphs> elements to find the text you want
  • Replace that text with something else
  • Remove the Indices attribute from the changed <Glyphs> elements
  • Save the updated XML back to the file
  • Re-zip then change the extension from ZIP to XPS

这篇关于编辑 XPS 内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆