1

午後の皆さん、

iTextSharp を使用して Web ページを .PDF ファイルに変換できるとのアドバイスを受けました。次のリンクをサンプル チュートリアルとして使用していますが、.pdf を生成できませんか?

http://www.dotnetspark.com/kb/654-simple-way-to-create-pdf-document-using.aspx にアクセスしてください

VBサンプルを使用しています。プロジェクトに iTextSharp.dll を追加し、要求に応じて名前空間を追加しました。空白のページを作成し、ページにボタンを追加しただけで、次のコードを使用してファイルを生成できないようです。

これが私のコードです...

Imports iTextSharp.text
Imports iTextSharp.text.pdf

Partial Class pdf
Inherits System.Web.UI.Page

Protected Sub btnGeneratePDF_Click(ByVal sender As Object, ByVal e As EventArgs)
    'Create Document class obejct and set its size to letter and give space left, right, Top, Bottom Margin
    Dim doc As New Document(iTextSharp.text.PageSize.LETTER, 10, 10, 42, 35)
    Try
        Dim wri As PdfWriter = PdfWriter.GetInstance(doc, New FileStream("d:\myfolder\test.pdf", FileMode.Create))
        'Open Document to write
        doc.Open()

        'Write some content
        Dim paragraph As New Paragraph("This is my first line using Paragraph.")
        Dim pharse As New Phrase("This is my second line using Pharse.")
        Dim chunk As New Chunk(" This is my third line using Chunk.")
        ' Now add the above created text using different class object to our pdf document
        doc.Add(paragraph)
        doc.Add(pharse)
        doc.Add(chunk)
    Catch dex As DocumentException


        'Handle document exception
    Catch ioex As IOException
        'Handle IO exception
    Catch ex As Exception
        'Handle Other Exception
    Finally
        'Close document
        doc.Close()
    End Try
End Sub

クラス終了

これがボタンのコードです...

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="pdf.aspx.vb" Inherits="pdf" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

    <asp:Button ID="btnGeneratePDF" runat="server" Text="Generate .PDF" />

</div>
</form>
</body>
</html>

誰かが私のためにこれを見て、どこが間違っているのか教えてもらえますか?

よろしくベティ

4

1 に答える 1

1

これですべてが修正されるかどうかはわかりませんが、少なくともボタンからClick_Eventが欠落しています。

<asp:Button ID="btnGeneratePDF" runat="server" Text="Generate .PDF" OnClick="btnGeneratePDF_Click" />

(そして、あなたが昨日この質問をしたことがわかります:ボタンClickEventは同じ問題でトリガーされません、次回覚えてみてください;-))

于 2012-09-20T11:50:49.173 に答える