C# 在将PDF输出到浏览器之前,从PDF中删除Adobe Reader和版本要求

C# 在将PDF输出到浏览器之前,从PDF中删除Adobe Reader和版本要求,c#,asp.net-mvc,pdf,pdf.js,C#,Asp.net Mvc,Pdf,Pdf.js,我计划使用Javascript通过浏览器创建PDF上下文。问题是,我正在使用的一些PDF需要Adobe的Reader提供特定版本。pdf.js还不(曾经?)支持对这些文件的欺骗。我需要知道的是,是否有办法在C#中打开PDF并删除这些阅读器和版本要求,以及如何做到这一点。我正计划用它在服务器端执行其他PDF操作,因此使用这个示例将非常有用。我计划通过MVC4将它们作为ajax请求的ActionResult提供,因此MemoryStream在操作结束时最有帮助。您的PDF文件n-400.PDF使用。

我计划使用Javascript通过浏览器创建PDF上下文。问题是,我正在使用的一些PDF需要Adobe的Reader提供特定版本。pdf.js还不(曾经?)支持对这些文件的欺骗。我需要知道的是,是否有办法在C#中打开PDF并删除这些阅读器和版本要求,以及如何做到这一点。我正计划用它在服务器端执行其他PDF操作,因此使用这个示例将非常有用。我计划通过MVC4将它们作为ajax请求的
ActionResult
提供,因此
MemoryStream
在操作结束时最有帮助。

您的PDF文件
n-400.PDF
使用。这意味着您需要一个同样支持pdf.js似乎不支持的查看器

这种PDF通常包含一些标准的PDF内容,这表明PDF需要一些支持XFA的查看器。在您的案例中,内容包含

如果此消息最终未被文档的正确内容替换,则PDF查看器可能无法显示此类型的文档

这实际上表明了启用XFA的查看器的功能,它根据XFA XML数据中的信息呈现一些页面,并显示这些页面,而不是PDF样式的页面描述

虽然由Adobe自行定义,但描述了如何将XFA数据嵌入到PDF文档中,请参见第12.7.8节XFA表单


如果您只需要那些处于展开状态的表单,您可能需要查看一下。

您的PDF文件
n-400.PDF
使用。这意味着您需要一个同样支持pdf.js似乎不支持的查看器

这种PDF通常包含一些标准的PDF内容,这表明PDF需要一些支持XFA的查看器。在您的案例中,内容包含

如果此消息最终未被文档的正确内容替换,则PDF查看器可能无法显示此类型的文档

这实际上表明了启用XFA的查看器的功能,它根据XFA XML数据中的信息呈现一些页面,并显示这些页面,而不是PDF样式的页面描述

虽然由Adobe自行定义,但描述了如何将XFA数据嵌入到PDF文档中,请参见第12.7.8节XFA表单


如果您只需要那些处于展开状态的表单,您可能需要看一看。

因此,最终
pdf.js
也无法完成我需要的任务,我所能做的就是将
Xfa/Pdf
转换成
C#
对象,然后根据需要通过Json将页面发送到我的Javascript,以便在
HTML5画布中呈现。下面的代码获取一个xfa-in-a-pdf文件,并在
itextsharp
的帮助下将其转换为C对象:

    PdfReader.unethicalreading = true;
    PdfReader reader = new PdfReader(new FileStream(Statics.PdfUploadLocation + PdfFileName, FileMode.Open, FileAccess.Read));

    XfaForm xfaForm = new XfaForm(reader);
    XDocument xDoc = XDocument.Parse(xfaForm.DomDocument.InnerXml);

    string xfaNamespace = @"{http://www.xfa.org/schema/xfa-template/2.6/}";


    List<XElement> formPages = xDoc.Descendants(xfaNamespace + "subform").Descendants(xfaNamespace + "subform").ToList();
    TotalPages = formPages.Count();


    var fieldIndex = 0;
    RawPdfFields = new List<XfaField>();

    for (int page = 0; page < formPages.Count(); page++)
    {
        RawPdfFields.AddRange(formPages[page].Descendants(xfaNamespace + "field")
                    .Select(x => new XfaField
                    {
                        Page = page,
                        Index = fieldIndex++,
                        Name = (string)x.Attribute("name"),
                        Height = GetUnitFromPossibleString((string)x.Attribute("h")),
                        Width = GetUnitFromPossibleString((string)x.Attribute("w")),
                        XPosition = GetUnitFromPossibleString((string)x.Attribute("x")),
                        YPosition = GetUnitFromPossibleString((string)x.Attribute("y")),
                        Reference = GetReference(x.Descendants(xfaNamespace + "traverse")),
                        AssistSpeak = GetAssistSpeak(x.Descendants(xfaNamespace + "speak"))
                    }).ToList());
    }
PdfReader.unethicalreading=true;
PdfReader reader=newpdfreader(新文件流(Statics.pdfuploaddlocation+PdfFileName,FileMode.Open,FileAccess.Read));
XfaForm XfaForm=新的XfaForm(读卡器);
XDocument xDoc=XDocument.Parse(xfaForm.DomDocument.InnerXml);
字符串xfaNamespace=@”{http://www.xfa.org/schema/xfa-template/2.6/}";
List formPages=xDoc.subderstands(xfaNamespace+“subform”).subderstands(xfaNamespace+“subform”).ToList();
TotalPages=formPages.Count();
var-fieldIndex=0;
rawPdfields=新列表();
对于(int page=0;pagenew XfaField
{
第页,
Index=fieldIndex++,
名称=(字符串)x.Attribute(“名称”),
高度=GetUnitFromPossibleString((字符串)x.Attribute(“h”),
宽度=GetUnitFromPossibleString((字符串)x.Attribute(“w”),
XPosition=GetUnitFromPossibleString((字符串)x.Attribute(“x”)),
YPosition=GetUnitFromPossibleString((字符串)x.Attribute(“y”)),
Reference=GetReference(x.subjects(xfaNamespace+“遍历”),
AssistSpeak=GetAssistSpeak(x.x.子代(xfaNamespace+“speak”))
}).ToList());
}

因此,最终
pdf.js
也无法完成我需要的工作,但是,我能做的是将
Xfa/pdf
转换为
C#
对象,然后根据需要通过Json将页面发送到我的Javascript,以便在
HTML5画布中呈现。下面的代码获取一个xfa-in-a-pdf文件,并在
itextsharp
的帮助下将其转换为C对象:

    PdfReader.unethicalreading = true;
    PdfReader reader = new PdfReader(new FileStream(Statics.PdfUploadLocation + PdfFileName, FileMode.Open, FileAccess.Read));

    XfaForm xfaForm = new XfaForm(reader);
    XDocument xDoc = XDocument.Parse(xfaForm.DomDocument.InnerXml);

    string xfaNamespace = @"{http://www.xfa.org/schema/xfa-template/2.6/}";


    List<XElement> formPages = xDoc.Descendants(xfaNamespace + "subform").Descendants(xfaNamespace + "subform").ToList();
    TotalPages = formPages.Count();


    var fieldIndex = 0;
    RawPdfFields = new List<XfaField>();

    for (int page = 0; page < formPages.Count(); page++)
    {
        RawPdfFields.AddRange(formPages[page].Descendants(xfaNamespace + "field")
                    .Select(x => new XfaField
                    {
                        Page = page,
                        Index = fieldIndex++,
                        Name = (string)x.Attribute("name"),
                        Height = GetUnitFromPossibleString((string)x.Attribute("h")),
                        Width = GetUnitFromPossibleString((string)x.Attribute("w")),
                        XPosition = GetUnitFromPossibleString((string)x.Attribute("x")),
                        YPosition = GetUnitFromPossibleString((string)x.Attribute("y")),
                        Reference = GetReference(x.Descendants(xfaNamespace + "traverse")),
                        AssistSpeak = GetAssistSpeak(x.Descendants(xfaNamespace + "speak"))
                    }).ToList());
    }
PdfReader.unethicalreading=true;
PdfReader reader=newpdfreader(新文件流(Statics.pdfuploaddlocation+PdfFileName,FileMode.Open,FileAccess.Read));
XfaForm XfaForm=新的XfaForm(读卡器);
XDocument xDoc=XDocument.Parse(xfaForm.DomDocument.InnerXml);
字符串xfaNamespace=@”{http://www.xfa.org/schema/xfa-template/2.6/}";
List formPages=xDoc.subderstands(xfaNamespace+“subform”).subderstands(xfaNamespace+“subform”).ToList();
TotalPages=formPages.Count();
var-fieldIndex=0;
rawPdfields=新列表();
对于(int page=0;pagenew XfaField
{
第页,
Index=fieldIndex++,
名称=(字符串)x.Attribute(“名称”),
高度=GetUnitFromPossibleString((字符串)x.Attribute(“h”),
宽度=GetUnitFromPossibleString((字符串)x.Attribute(“w”),
XPosition=GetUnitFromPossibleString((字符串)x.Attribute(“x”)),