为什么数据会添加到PDF内容流中? [英] Why is data added to the PDF content stream?

查看:253
本文介绍了为什么数据会添加到PDF内容流中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用此代码时(从PDF iTextSharp中删除水印)为了简单地读取和重写相同PDF的内容流,我为此内容流添加了额外的操作文件

When using this code (Removing Watermark from PDF iTextSharp) to simply read and re-write the content stream for an identical PDF, I get additional operations added to the content stream for this file.

在内容流之前

q
 q
/I0 Do
Q

Q
 q
10 0 0 10 0 0 cm
0.1 0 0 0.1 0 0 cm
/QuickPDFXO6d1c5c37 Do
Q

内容流后

q
0 -1 1 0 0 1224 cm
q
q
/I0 Do
Q
Q
q
10 0 0 10 0 0 cm
0.1 0 0 0.1 0 0 cm
/QuickPDFXO6d1c5c37 Do
Q
Q

知道为什么这会附加到我的内容流中吗?

Any idea why this was appended to my content stream?

q
0 -1 1 0 0 1224 cm
....
Q

我的代码类似于链接的文章,除了我我试图从内容流中删除某些项目。

My Code is similar to the article linked except that I'm trying to remove certain items from the content stream.

XObjectRemover editor = new XObjectRemover();
List<List<PdfContentData>> output = editor.EditPageContent(stamper, pgNumber);
PdfContentByte content = stamper.GetUnderContent(pgNumber);

foreach (List<PdfContentData> bracketList in output)
{
    foreach (PdfContentData operandList in bracketList)
    {
        if (operandList.operandToDelete == false)
        {
            int index = 0;
            foreach (PdfObject op in operandList.pdfOperands)
            {
                op.ToPdf(content.PdfWriter, content.InternalBuffer);
                content.InternalBuffer.Append(operandList.pdfOperands.Count > ++index ? (byte)' ' : (byte)'\n');
            }
        }
    }
}

PdfContentData类只是所有内容操作的集合,其中一些标记为删除。

The PdfContentData class is just a collection of all the content operations with some flagged for delete.

public class PdfContentData
{
    public int opNumber { get; set; }
    public PdfLiteral pdfOperator { get; set; }
    public List<PdfObject> pdfOperands { get; set; }
    public bool operandToDelete { get; set; }

    public PdfContentData(int opNum, PdfLiteral op, List<PdfObject> ops)
    {
        this.opNumber = opNum;
        this.pdfOperator = op;
        this.pdfOperands = ops;
    }

    public override string ToString()
    {
        return $"Ops: [{string.Join(",", pdfOperands.Select(p => p.ToString()).ToArray())}]   Del: [{operandToDelete}]";
    }
}

和XObjectRemover只是一个派生自PdfContentStreamEditor的类就像在@ mkl的例子中的TransparentGraphicsRemover一样。

and XObjectRemover is just a class that is derived from PdfContentStreamEditor, just like TransparentGraphicsRemover in @mkl's example.

推荐答案

此添加

q
0 -1 1 0 0 1224 cm
....
Q

旋转两者之间的所有内容。添加这是iText(夏普)的服务,旨在让您忽略旋转并使用更自然的坐标绘制东西。

rotates everything in between. Adding this is a 'service' by iText(Sharp) intended to allow you to ignore the rotation and draw stuff using more natural coordinates.

不幸的是这项服务没有意义为了手头的任务。因此,您应该切换它。

Unfortunately this service does not makes sense for the task at hand. Thus, you should switch it of.

PdfStamper 有一个标志,允许您这样做:

The PdfStamper has a flag allowing you to do just that:

/** Checks if the content is automatically adjusted to compensate
 * the original page rotation.
 * @return the auto-rotation status
 */    
/** Flags the content to be automatically adjusted to compensate
 * the original page rotation. The default is <CODE>true</CODE>.
 * @param rotateContents <CODE>true</CODE> to set auto-rotation, <CODE>false</CODE>
 * otherwise
 */    
virtual public bool RotateContents {
    set {
        stamper.RotateContents = value;
    }
    get {
        return stamper.RotateContents;
    }
} 

(评论是最初与单独关联的Javadoc评论这个属性的getter和setter。因此,这个双重评论。)

(The comments are Javadoc comments originally associated with a separate getter and setter for this attribute. Thus, this double comment.)

因此,我建议将 RotateContent 设置为 false

Thus, I would propose setting RotateContent to false.

这篇关于为什么数据会添加到PDF内容流中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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