是否可以重新初始化pdf文件中的图形状态? [英] Is it possible to reinitialize the graphics state in a pdf file?

查看:389
本文介绍了是否可以重新初始化pdf文件中的图形状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在c ++中创建一个程序,以在pdf文件的第一页中添加一个简单的图像。我选择libqpdf,因为它相当简单的使用。然而,我发现有一些pdf文件,当我添加图像作为页面内容的第一个对象,图像正确显示,但当我添加的图像作为内容的最后一个对象,图像显示上下颠倒并处于错误的位置。

I want to create a program in c++ to add a simple image in the first page of a pdf file. I chose libqpdf as it rather simple to use. However I found out that there are some pdf files that when I add the image as the first object of the page content, the image appears correctly, but when I add the image as the last object of the content, the image appears upside-down and in the wrong position. I suspect that the CTM is modified and not restored as is expected.

是否可以使用cm操作重置图形状态CTM矩阵?

Is it possible to reset the graphics state CTM matrix using a cm operation?

代码(仍处于很早的状态)可以在这里找到: https:/ /github.com/parapente/qpdfImageEmbed

The code (still in a very early state) can be found here: https://github.com/parapente/qpdfImageEmbed

推荐答案

否。

cm总是将矩阵连接到当前矩阵,没有操作符可以设置它。

"cm" always concatenates the matrix to the current matrix and there is no operator to set it.

这是为什么大多数PDF创建涉及大量



Which is why most PDF creation involves lots of

q
...
Q

对保存和恢复图形状态(包括矩阵)。

pairs to save and restore the graphics state (including the matrix).

如果你需要添加一些东西页面流的结尾,你可以在页面流的开头写一个q命令,在最后添加一个Q,然后添加你的操作。

If you need to add something to the end of the page stream, you could write a "q" command at the very beginning of the page stream, add a "Q" at the very end, end then add your operations.

这篇关于是否可以重新初始化pdf文件中的图形状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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