gpt4 book ai didi

c# - 在 PHP/Bash/C# 中从 PDF 中删除图层/背景#

转载 作者:可可西里 更新时间:2023-11-01 13:48:21 27 4
gpt4 key购买 nike

我有一些 PDF 文件需要使用 PHP 脚本进行修改。我也可以执行 exec(),所以我可以使用几乎所有在 CentOS 上运行的东西。

通过 Adob​​e Acrobat Pro X 打开 PDF 文件时,在“图层”面板中显示 2 个图层:

  1. 背景
  2. 颜色

当我禁用这两个层时,我最终得到黑白文本和图像(文本不是矢量,它是扫描文档)。

我想使用 PHP 和/或 C# 或任何命令行工具禁用这些层以及在 PDF 中找到的任何其他类似层。

其他有用信息:

当我在我的 PDF 上运行 pdfimages(随 XPDF 一起提供)时,它准确地提取了我实际需要从每个页面中删除的内容...

附加信息更新:我在这里修改了 PDFSharp 示例:http://www.pdfsharp.net/wiki/ExportImages-sample.ashx :

修改:
第 28 行:ExportImage(xObject, ref imageCount);

收件人:
PdfObject obj = xObject.Elements.GetObject("/OC");
Console.WriteLine(obj);

我在每个图像的控制台中得到以下输出:
<< /Name Background /Type /OCG >>
<< /OCGs [ 2234 0 R ] /P /AllOff /Type /OCMD >>
<< /Name Text Color /Type /OCG >>

这实际上是图层信息,以及/OC 键的 PDFSharp 文档:

Before the image is processed, its visibility is determined based on this entry. If it is determined to be invisible, the entire image is skipped, as if there were no Do operator to invoke it.

那么现在,如何将/OC 值修改为使这些层不可见的值?

最佳答案

经过长时间的试验,我找到了方法!我正在发布代码,以便将来有人会发现它有帮助:

using System;
using System.IO;
using System.Collections.Generic;
using iTextSharp.text;
using iTextSharp.text.pdf;

namespace LayerHide {

class MainClass
{
public static void Main (string[] args)
{

PdfReader reader = new PdfReader("test.pdf");
PdfStamper stamp = new PdfStamper(reader, new FileStream("test2.pdf", FileMode.Create));
Dictionary<string, PdfLayer> layers = stamp.GetPdfLayers();

foreach(KeyValuePair<string, PdfLayer> entry in layers )
{
PdfLayer layer = (PdfLayer)entry.Value;
layer.On = false;
}

stamp.Close();
}
}
}

关于c# - 在 PHP/Bash/C# 中从 PDF 中删除图层/背景#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6089461/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com