我需要做的是;
- 从 sharepoint 获取 pdf
- 使用 PDFSharp 获取单页
- 将其返回到视图并显示该页面
到目前为止,我所拥有的是;
context.Response.ClearHeaders();
context.Response.ContentType = "application/pdf";
context.Response.AddHeader("content-disposition", "inline; filename=Something.pdf");
// Get a fresh copy of the sample PDF file from Sharepoint later on
string filename = @"book.pdf";
// Open the file
PdfDocument inputDocument = CompatiblePdfReader.Open(filename, PdfDocumentOpenMode.Import);
PdfDocument outputDocument = new PdfDocument();
outputDocument.Version = inputDocument.Version;
outputDocument.Info.Title = "Pages 1 to 30";
outputDocument.Info.Author = "Slappy";
outputDocument.AddPage(inputDocument.Pages[1]);
MemoryStream ms = new MemoryStream();
outputDocument.Save(ms, false);
ms.WriteTo(context.Response.OutputStream);
我不知道如何在网页中显示它。
我有这个;
<script src="../../Scripts/jquery-1.6.4.min.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.media.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.metadata.js" type="text/javascript"></script>
<script>
$(function () {
$.ajax({ url: '/GetBookPage.ashx',
success: function (result) {
$("a.media").attr('href', result);
$('a.media').media({ width: 800, height: 600 });
},
async: false
});
});
</script>
<a class="media">PDF File</a>
如果我将 pdf 保存到文件系统然后将 href 指向该文件,则上述方法有效。