Siang Semua,
Saya telah diberitahu bahwa saya dapat menggunakan iTextSharp untuk membantu saya mengubah halaman web saya menjadi file .PDF. Saya menggunakan tautan berikut sebagai contoh tutorial tetapi tidak dapat menghasilkan .pdf?
Kunjungi http://www.dotnetspark.com/kb/654-simple-way-to-create-pdf-document-using.aspx
Saya menggunakan sampel VB. Saya telah menambahkan iTextSharp.dll ke proyek saya dan menambahkan namespace seperti yang diminta. Saya baru saja membuat halaman kosong dan menambahkan tombol ke halaman tersebut dan menggunakan kode berikut sepertinya saya tidak dapat membuat ini untuk menghasilkan file?
Ini kode saya...
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
Kelas Akhir
Ini kode tombolnya...
<%@ 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>
Bisakah seseorang melihat ini untuk saya dan memberi tahu saya di mana kesalahan saya?
Salam Betty