1

MVC Web アプリケーションであり、ファイルがサーバー上に存在するため、文字列 base64 要素として返す pdf 要素があります。現在、PDFObject と pdf.js を使用して、この PDF をブラウザーで表示しようとしています。ただし、このアプリケーションをサーバー上の IIS に配置すると機能しない URL を渡さない限り、PDF を表示できないようです。

src="{my base 64 string} を埋め込んだ PDF を作成し、その周りに PDFObject をラップする方法はありますか?そうでない場合は、PDFObject を介して、url の代わりに base64 文字列を使用する方法はありますか? ?

また、これはIE 11にあります

更新 これが私のコントローラーです

public ActionResult GetPDFString(string instrumentType, string booktype, string book, string startpage, string EndPage)
    {
        LRS_Settings settings = ctxLRS.LRS_Settings.FirstOrDefault();
        string root = settings.ImagePathRoot;
        string state = settings.State;
        string county = settings.County;
        g_filePath = @"\\10.20.170.200\Imaging\GA\075\Daily\" + instrumentType + "\\" + book + "\\";
        //g_filePath = @"\\10.15.100.225\sup_court\Imaging\GA\075\Daily\" + instrumentType + "\\" + book + "\\";
        byte[] file = imgConv.ConvertTifToPDF(g_filePath, booktype, book, startpage, EndPage);

        var ms = new MemoryStream(file);
        var fsResult = new FileStreamResult(ms, "application/pdfContent");

        return fsResult;


    //return imgConv.ConvertTifToPDF(g_filePath, booktype, book, startpage, EndPage);
}

ここに私のjqueryがあります

var options = {
                pdfOpenParams: {
                    navpanes: 1,
                    toolbar: 0,
                    statusbar: 0,
                    pagemode: 'none',
                    pagemode: "none",
                    page: 1,
                    zoom: "page-width",
                    enableHandToolOnLoad: true
                },
                forcePDFJS: true,
                PDFJS_URL: "/PDF.js/web/viewer.html"
            }

            PDFObject.embed("@Url.Action("GetPDFString", "DocumentView", new { instrumentType = ViewBag.instrumentType, BookType = Model.BookType, Book = ViewBag.Book, StartPage = ViewBag.StartPage, EndPage = ViewBag.endPage, style = "height:100%; width100%;" })", "#PDFViewer", options);

問題は、#PDFViewer 内に PDF を表示する代わりに、ファイルをダウンロードしようとしていることです。誰かパズルの最後のピースを手伝ってくれませんか。これは私を夢中にさせています。

4

2 に答える 2

1

代わりに、標準の html だけを使用しようとしましたか? コントローラ アクション

public ActionResult GetAttachment(string instrumentType, string booktype, string book, string startpage, string EndPage)
{
    var fileStream = new FileStream(Server.MapPath("~/Content/files/sample.pdf"), 
                                     FileMode.Open,
                                     FileAccess.Read
                                   );
    var fsResult = new FileStreamResult(fileStream, "application/pdf");
    return fsResult;
}

あなたの見解では

<div id="PDFViewer">
    <embed src="@Url.Action("GetAttachment", "DocumentView", new { instrumentType = ViewBag.instrumentType, BookType = Model.BookType, Book = ViewBag.Book, StartPage = ViewBag.StartPage, EndPage = ViewBag.endPage })" width="100%" height="100%" type="application/pdf"></embed>
</div>

これは、PDFObject を使用するよりも要件に適していますか?

于 2016-08-31T22:02:10.660 に答える
0

content disposition ヘッダーを必ず に設定してください。そうしないとinline、ブラウザはファイルをビューポートにレンダリングするのではなく、ダウンロードしようとします。

Content-Disposition:「インライン」と「添付ファイル」の違いを参照してください。

PDFObject とプレーンな HTML に関する限り、トラブルシューティングのために、静的マークアップ (JS なし) を試して同じ PDF を表示することを常にお勧めします。そこで動作する場合、問題は PDFObject にある可能性があります (この場合、PDFObject の Base64 文字列の処理)。プレーン マークアップで PDF が適切にレンダリングされない場合、問題はファイル/Base64 にある可能性があります。

PDFObject 静的マークアップ ジェネレーターから静的マークアップのコピーを取得できます: http://pdfobject.com/generator

(PDF.js の Base64 文字列の処理については話せないことを付け加えておきます...)

于 2016-08-31T23:36:09.273 に答える