gpt4 book ai didi

itext - BizTalk 自定义管道解析 POP3 PDF 附件错误

转载 作者:行者123 更新时间:2023-12-01 14:56:57 24 4
gpt4 key购买 nike

我有一个 BizTalk 自定义管道组件,我在其中使用 itexsharp 将 PDF 附件解析为自定义模型。管道绑定(bind)到 POP3 接收端口。

在新创建的消息中,如果我返回附件流 (outputMessage.GetPart("Body").Data = ms),那么这在 BizTalk 管理控制台中看起来不错。我已经能够从这里手动保存消息,并且使用与管道中相同的解析方法对其进行了正确解析。

直接在管道中解析 PDF 时,出现以下错误:重建失败:未找到预告片。;原始消息:在文件指针 1620729 处未找到外部参照小节

如果我从管道中删除默认的 XMLDisassembler 组件,那么解析错误就会消失,但在控制台中,消息主体为空,尽管 AttachmentSizeInBytes=1788

public IBaseMessage Execute(IPipelineContext pContext, IBaseMessage pInMsg)
{
return ExtractMessagePartToMessage(pContext, pInMsg);
}

private IBaseMessage ExtractMessagePartToMessage(IPipelineContext pContext, IBaseMessage pInMsg)
{
if (pInMsg.PartCount <= 1)
{
throw new InvalidOperationException("The email had no attachment, apparently.");
}

string partName;
IBaseMessagePart attachmentPart = pInMsg.GetPartByIndex(1, out partName);
Stream attachmentPartStream = attachmentPart.GetOriginalDataStream();

IBaseMessage outputMessage;
outputMessage = pContext.GetMessageFactory().CreateMessage();
outputMessage.AddPart("Body", pContext.GetMessageFactory().CreateMessagePart(), true);
outputMessage.Context = pInMsg.Context;

var ms = new MemoryStream();
attachmentPartStream.CopyTo(ms);
ms.Seek(0L, SeekOrigin.Begin);

Stream orderStream = PdfFormParser.Parse(ms);

outputMessage.GetPart("Body").Data = orderStream;
outputMessage.Context.Write("AttachmentName", "http://schemas.microsoft.com/BizTalk/2003/file-properties", partName);
outputMessage.Context.Write("AttachmentSizeInBytes", "http://schemas.microsoft.com/BizTalk/2003/file-properties", orderStream.Length.ToString());


pContext.ResourceTracker.AddResource(ms);
pContext.ResourceTracker.AddResource(orderStream);

return outputMessage;
}

public static Stream Parse(Stream pdfDocument)
{
using (var reader = new PdfReader(pdfDocument))
{
var outputStream = new MemoryStream();
var pdfForm = ParseInternal(reader);
var xmlDocument = new XmlDocument();
xmlDocument.LoadXml(pdfForm.Serialize());

xmlDocument.Save(outputStream);

return outputStream;
}

最佳答案

在管道中读取或写入 Stream 时,如果其他东西要使用它(尤其是您希望 BizTalk 处理的最终消息),则必须将流倒回到开头。

关于itext - BizTalk 自定义管道解析 POP3 PDF 附件错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45170460/

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