我想在图像上创建一个文本图层,而不是作为单元格添加到pdf doc中。
这是我目前的代码:
Dim pdfDoc As New Document(PageSize.A4, 50, 50, 25, 25)
Dim output = New MemoryStream()
'Dim path As String = "\\pcpke735\PKESimulation\pdf\"
Dim path As String = "C:\PKE Simulation AG\WebApplication1\pdf\"
Dim filename As String = "Leistungen_" & DateTime.Now.Date.ToString("ddMMyyyy") & "_" & Date.Now.ToString("hhmmss") & ".pdf"
Dim pdfWrite As PdfWriter = PdfWriter.GetInstance(pdfDoc, New FileStream(path & filename, FileMode.Create))
Dim sparplan_bez As String
Try
pdfDoc.AddTitle("Leistungen")
pdfDoc.Open()
'Headerbild einfügen
Dim logo = iTextSharp.text.Image.GetInstance(Server.MapPath("/images/head.png"))
logo.ScaleAbsolute(600, 150)
logo.SetAbsolutePosition(0, 700)
logo.Alignment = iTextSharp.text.Image.UNDERLYING
pdfDoc.Add(logo)
'Vier Leerzeilen
pdfDoc.Add(New Paragraph(vbCrLf))
pdfDoc.Add(New Paragraph(vbCrLf))
pdfDoc.Add(New Paragraph(vbCrLf))
pdfDoc.Add(New Paragraph(vbCrLf))
'Dim logo = iTextSharp.text.Image.GetInstance(Server.MapPath("/Logo/PKE.jpg"))
'logo.SetAbsolutePosition(450, 750)
'Schriftart und Grösse setzen
Dim titleFont = FontFactory.GetFont("Arial", 18, Font.BOLD)
Dim subTitelFont = FontFactory.GetFont("Arial", 14, Font.BOLD)
Dim boldTableFont = FontFactory.GetFont("Arial", 12, Font.BOLD)
Dim standardFont = FontFactory.GetFont("Arial", 11)
'Vier Leerzeilen
pdfDoc.Add(New Paragraph(vbCrLf))
pdfDoc.Add(New Paragraph(vbCrLf))
'Titelzeile
Dim cb = pdfWrite.DirectContent
cb.BeginText()
cb.SetTextMatrix(210, 230)
Dim Tfont = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, False)
cb.SetFontAndSize(Tfont, 24)
cb.ShowText("Simulation per " & eintrittper.Text)
cb.EndText()
pdfDoc.Add(New Paragraph(vbCrLf))
pdfDoc.Add(New Paragraph("Erstellt am: " & Now(), standardFont))
pdfDoc.Add(New Paragraph(vbCrLf))
pdfDoc.Close()
Dim quelle As String = "/pdf/" & filename
Response.Write("<script>window.open('" & quelle & "')</script>")
Catch ex As Exception
'WriteLog("Fehler PDF Leistungen erstellen : " & Err.Description)
'errorState = True
End Try
End Sub
直接内容对象应放在图像上。