0

我正在使用下面的代码生成 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()
4

1 回答 1

0

Nm,我能够使用相同的逻辑,它将使用 FileMode.Create 重新创建文件

于 2013-08-20T13:19:48.530 回答