1

こんにちは、私は Extjs アプリケーションを実行しています。ユーザーがボタンをクリックしたときに、ReportLab で PDF を開きたいと考えています。

私のスクリプトは次のとおりです。

xtype: 'button',
text: 'Print',
listeners: {
    click: function(evt, comp) {
        Ext.Ajax.request({
            url : 'get_pdf',
            method: 'GET',
            success: function ( result, request ) {
                var pdf = Ext.util.JSON.decode(result.responseText);
                if (pdf.success) {
                    console.log('It's ok'); 
                }
            });
        }
    }

サーバー側にはdjangoビューがあります:

def get_pdf(request):

    # Create the HttpResponse object with the appropriate PDF headers.
    response = HttpResponse(mimetype='application/pdf')
    response['Content-Disposition'] = 'attachment; filename=somefilename.pdf'

    # Create the PDF object, using the response object as its "file."
    p = canvas.Canvas(response)

    # Draw things on the PDF. Here's where the PDF generation happens.
    # See the ReportLab documentation for the full list of functionality.
    p.drawString(100, 100, "Hello world.")

    # Close the PDF object cleanly, and we're done.
    p.showPage()
    p.save()
    return response

印刷ボタンをクリックすると、Extjs から次のエラーが表示されます: 構文エラー (%PDF-1.3 What I'm doing wrong?

4

1 に答える 1

0

完全な回答を提供する Extjs についてはわかりませんが、応答テキストは JSON ではなく、PDF であるため、エラーの理由がわかりました。本当にやりたいことはresult、ブラウザに表示することです。つまり、開始した HTTP リクエストの内容を表示します。成功を確認したい場合は、代わりに結果の HTTP ヘッドを確認してください。

于 2011-07-14T22:38:55.587 に答える