Editer fichier PDF

Résolu
AlphaDev Messages postés 3 Date d'inscription samedi 26 septembre 2020 Statut Membre Dernière intervention 28 septembre 2020 - 26 sept. 2020 à 20:37
Whismeril Messages postés 19022 Date d'inscription mardi 11 mars 2003 Statut Contributeur Dernière intervention 17 avril 2024 - 28 sept. 2020 à 21:12
Bonsoir à tous
J'aimerais savoir s'il est possible d’éditer un fichier PDF existant avec VB.net
Merci à tous pour votre aide
A voir également:

5 réponses

Whismeril Messages postés 19022 Date d'inscription mardi 11 mars 2003 Statut Contributeur Dernière intervention 17 avril 2024 656
26 sept. 2020 à 20:59
1
Whismeril Messages postés 19022 Date d'inscription mardi 11 mars 2003 Statut Contributeur Dernière intervention 17 avril 2024 656
27 sept. 2020 à 14:36
VB.Net c'est du C# déguisé en VB.

Rapidement on trouve plein d'exemple en C#,
https://lite.qwant.com/?q=itextsharp+edit+pdf&client=opensearch
il suffit alors de les convertir
https://lite.qwant.com/?q=vb+to+c%23&t=web
1
AlphaDev Messages postés 3 Date d'inscription samedi 26 septembre 2020 Statut Membre Dernière intervention 28 septembre 2020
Modifié le 27 sept. 2020 à 19:49
Merci Whismeril,

Maintenant avec Itextsharp et vb.net j'arrive a créer des pdf voici le code.:

Imports iTextSharp.text.pdf
Imports iTextSharp.text
Imports System.IO
Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim pdfDoc As New Document()
        Dim pdfWrite As PdfWriter = PdfWriter.GetInstance(pdfDoc, New FileStream("Test.pdf", FileMode.Create))
        pdfDoc.Open()
        pdfDoc.Add(New Paragraph("Hello World"))
        pdfDoc.Close()
    End Sub
End Class


Par contre j'ai cherché mais je n'arrive pas a trouver comment modifier un pdf existant
avec iTextsharp

Merci pour votre aide
0
AlphaDev Messages postés 3 Date d'inscription samedi 26 septembre 2020 Statut Membre Dernière intervention 28 septembre 2020
Modifié le 28 sept. 2020 à 19:21
Merci encore pour votre aide,je partage le code après la conversion à partir du c# vers le vb.net pour ajouter du texte a n'importe quel pdf.

Dim oldFile As String = "oldfile.pdf"
        Dim newFile As String = "newfile.pdf"

        ' open the reader
        Dim reader As PdfReader = New PdfReader(oldFile)
        Dim size As Rectangle = reader.GetPageSizeWithRotation(1)
        Dim document As Document = New Document(size)

        ' open the writer
        Dim fs As FileStream = New FileStream(newFile, FileMode.Create, FileAccess.Write)
        Dim writer As PdfWriter = PdfWriter.GetInstance(document, fs)
        document.Open()

        ' the pdf content
        Dim cb As PdfContentByte = writer.DirectContent

        ' select the font properties
        Dim bf As BaseFont = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED)
        cb.SetColorFill(BaseColor.DARK_GRAY)
        cb.SetFontAndSize(bf, 10)

        ' write the text in the pdf content
        cb.BeginText()
        Dim text As String = "Some blablablabla...."
        ' put the alignment and coordinates here
        cb.ShowTextAligned(1, text, 520, 640, 0)
        cb.EndText()

        ' create the new page and add it to the pdf
        Dim page As PdfImportedPage = writer.GetImportedPage(reader, 1)
        cb.AddTemplate(page, 0, 0)

        ' close the streams and voilá the file should be changed :)
        document.Close()
        fs.Close()
        writer.Close()
        reader.Close()
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
Whismeril Messages postés 19022 Date d'inscription mardi 11 mars 2003 Statut Contributeur Dernière intervention 17 avril 2024 656
28 sept. 2020 à 21:12
De rien
0
Rejoignez-nous