在Visual Studio 2015上启用object.pdf



如何在Visual Studio中启用adobe对象来读取和处理。PDF数据?

如果我正确理解这个问题,你需要添加一个MediaTypeFormatter来处理"application/pdf"格式。下面的示例。。。

public class PdfFormatter : MediaTypeFormatter
{
    #region Constants and Fields
    private const int ChunkSizeMax = 1024 * 10;
    #endregion
    #region Constructors and Destructors
    public PdfFormatter()
    {
        SupportedMediaTypes.Add(MediaTypeHeaderValue.Parse("application/pdf"));
    }
    #endregion
    #region Public Methods
    public override bool CanReadType(Type type)
    {
        return false; // can't read any types
    }
    public override bool CanWriteType(Type type)
    {
        return type == typeof(byte[]);
    }
    public override Task WriteToStreamAsync(Type type, object value, Stream writeStream, HttpContent content, TransportContext transportContext)
    {
        Task t = new Task(() => WritePdfBytes(value, writeStream));
        t.Start();
        return t;
    }
    #endregion
    #region Methods
    private static void WritePdfBytes(object value, Stream writeStream)
    {
        byte[] buffer = value as byte[];
        int offset = 0;
        while (offset < buffer.Length)
        {
            int chunkSize = Math.Min(buffer.Length - offset, ChunkSizeMax);
            writeStream.Write(buffer, offset, chunkSize);
            offset += chunkSize;
        }
    }
    #endregion
}

在Global.asax.cs文件中添加

GlobalConfiguration。配置格式化程序。添加(new PdfFormatter());

相关内容

最新更新