.pdf ファイルにテーブルを生成するこの小さなスクリプトがありますが、テキストが大きすぎます。別のフォントサイズ/タイプを追加するにはどうすればよいですか?
Dim form As New HtmlForm
form.Controls.Add(gvEvents)
Dim sw As New StringWriter
Dim htmlWriter As New HtmlTextWriter(sw)
Dim htmlContent As String = sw.ToString()
Response.ContentType = "application/pdf"
Response.AddHeader("content-disposition", "attachment;filename=Holdkalender.pdf")
Response.Cache.SetCacheability(HttpCacheability.NoCache)
form.Controls(0).RenderControl(htmlWriter)
Dim sr As New StringReader(sw.ToString())
Dim pdfDoc As New Document(PageSize.A4, 50, 50, 50, 50)
Dim htmlparser As New HTMLWorker(pdfDoc)
PdfWriter.GetInstance(pdfDoc, Response.OutputStream)
pdfDoc.Open()
htmlparser.Parse(sr)
pdfDoc.Close()
Response.Write(pdfDoc)
Response.End()
編集:
これを試しましたが、Ielement エラーが発生します。
Protected Sub btnGeneratePDF_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnGeneratePDF.Click
BindEvents(Convert.ToInt32(ddlEventSize.SelectedValue))
Dim form As New HtmlForm
form.Controls.Add(gvEvents)
Dim sw As New StringWriter
Dim htmlWriter As New HtmlTextWriter(sw)
Dim htmlContent As String = sw.ToString()
Response.ContentType = "application/pdf"
Response.AddHeader("content-disposition", "attachment;filename=Holdkalender.pdf")
Response.Cache.SetCacheability(HttpCacheability.NoCache)
form.Controls(0).RenderControl(htmlWriter)
Dim sr As New StringReader(sw.ToString())
Dim pdfDoc As New Document(PageSize.A4, 50, 50, 50, 50) 'Paper Size and margin
Dim htmlparser As New HTMLWorker(pdfDoc)
PdfWriter.GetInstance(pdfDoc, Response.OutputStream)
pdfDoc.Open()
Dim ftlbl As Font = Nothing
ftlbl = FontFactory.GetFont(FontFactory.HELVETICA, 5)
pdfDoc.Add(ftlbl)
Try
htmlparser.Parse(sr)
Catch ex As Exception
'Display parser errors in PDF.
Dim paragraph As New Paragraph("FEJL!" + ex.Message)
Dim text As Chunk = TryCast(paragraph.Chunks(0), Chunk)
If text IsNot Nothing Then
text.Font.Color = BaseColor.RED
End If
pdfDoc.Add(paragraph)
Finally
pdfDoc.Close()
Response.Write(pdfDoc)
Response.End()
End Try
End Sub
編集2: