我想用
PdfCleanUpTool
用ITXEX7。
然而,我的最终pdf文件已经损坏(它的大小只有15b)。
当我开始我的
慰问
VS的应用程序我在输出中得到这个:
未找到配置节-正在抑制日志记录输出
我试图设置日志以获取错误消息,但没有成功。
我已安装此软件包:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Common.Logging" version="3.4.1" targetFramework="net47" />
<package id="Common.Logging.Core" version="3.4.1" targetFramework="net47" />
<package id="Common.Logging.NLog4412" version="3.4.1" targetFramework="net47" />
<package id="itext7" version="7.1.2" targetFramework="net47" />
<package id="itext7.pdfsweep" version="2.0.1" targetFramework="net47" />
<package id="Microsoft.CSharp" version="4.0.1" targetFramework="net47" />
<package id="NLog" version="4.4.12" targetFramework="net47" />
<package id="Portable.BouncyCastle" version="1.8.1.3" targetFramework="net47" />
</packages>
这是我的
app.config
文件:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="common">
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
</sectionGroup>
<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
</configSections>
<common>
<logging>
<factoryAdapter type="Common.Logging.NLog.NLogLoggerFactoryAdapter, Common.Logging.NLog4412">
<arg key="configType" value="INLINE" />
</factoryAdapter>
</logging>
</common>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="console" xsi:type="Console" layout="${date:format=HH\:MM\:ss} ${logger} ${message}" />
</targets>
<rules>
<logger name="*" minlevel="Info" writeTo="console" />
</rules>
</nlog>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7" />
</startup>
</configuration>
可能我需要设置一个许可证密钥,但我想得到一个错误消息,说我必须这样做。
我的问题是:
如何正确设置
nlog
具有
普通日志记录
从中获取错误
ITXEX7
.
以下是可用于验证当前行为的完整示例:
using Common.Logging;
using Common.Logging.Configuration;
using Common.Logging.Simple;
using iText.Kernel.Colors;
using iText.Kernel.Geom;
using iText.Kernel.Pdf;
using iText.PdfCleanup;
using System;
using System.Collections.Generic;
using System.IO;
namespace RedactTest
{
class Program
{
static void Main(string[] args)
{
NameValueCollection properties = new NameValueCollection
{
["showDateTime"] = "true",
["level"] = "All"
};
LogManager.Adapter = new ConsoleOutLoggerFactoryAdapter(properties);
using (Stream inputStream = new FileStream("D:\\test.pdf", FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
PdfReader reader = new PdfReader(inputStream);
using (Stream outputStream = new FileStream("D:\\test_redact.pdf", FileMode.Create))
{
PdfWriter writer = new PdfWriter(outputStream);
PdfDocument pdfDocument = new PdfDocument(reader, writer);
List<PdfCleanUpLocation> cleanUpLocations = new List<PdfCleanUpLocation>
{
new PdfCleanUpLocation(1, new Rectangle(40f, 650f, 200f, 700f),ColorConstants.GRAY),
new PdfCleanUpLocation(1, new Rectangle(40f, 550f, 200f, 590f),ColorConstants.GRAY),
new PdfCleanUpLocation(1, new Rectangle(344f, 650f, 550f, 724f),ColorConstants.GRAY)
};
PdfCleanUpTool cleaner = new PdfCleanUpTool(pdfDocument, cleanUpLocations);
cleaner.CleanUp();
}
}
Console.Write("OK");
Console.ReadLine();
}
}
}