我使用下面的代码生成pdf并将其保存到服务器位置。如果存在,我将如何替换文件?因此,如果目录包含pdf,如果相同的“myUniqueFileName”用相同的文件名替换它?谢谢
Dim Doc1 As New Document
Dim path As String = "\\server\pdfs\"
If (Not System.IO.Directory.Exists(path)) Then
System.IO.Directory.CreateDirectory(path)
End If
Dim myUniqueFileName = String.Format("{0}.pdf", random)
Dim pdfWrite As PdfWriter = PdfWriter.GetInstance(Doc1, New FileStream(path & myUniqueFileName, FileMode.Create))
Doc1.Open()
Dim test As String
test = Session("PDF")
Dim PDFHeader As String
PDFHeader = Session("Header")
Dim imagepath As String = Server.MapPath(".") & "/images/Header.png"
Dim image As iTextSharp.text.Image = iTextSharp.text.Image.GetInstance(imagepath)
image.ScalePercent(70.0F)
Dim line1 As New iTextSharp.text.pdf.draw.LineSeparator(0.0F, 100.0F, BaseColor.BLACK, Element.ALIGN_LEFT, 1)
Doc1.Add(image)
Doc1.Add(New Paragraph(PDFHeader))
Doc1.Add(New Chunk(line1))
Doc1.Add(New Paragraph(test))
Doc1.Close()
答案 0 :(得分:0)
Nm,我能够使用相同的逻辑,它将使用FileMode.Create重新创建文件