iTextSharp Image dans un pdf
Bonjour,
Encore un problème :(, je souhaites générer un pdf à partir de VB.NET, j'ai décider d'utiliser iTextSharp qui m'a l'air très bien cependant il m'est impossible d'ajouter une image dans mon pdf.
erreur impossible de trouver C:\MAP.jpg
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
Imports iTextSharp.text
Imports iTextSharp.text.pdf
Imports System.IO
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
CreatePDFFile()
End Sub
Private Sub CreatePDFFile()
Dim doc As New Document(iTextSharp.text.PageSize.LETTER, 10, 10, 42, 35)
Dim pdfFilePath As String = "C:\Documents and Settings\*****\Fichier.pdf"
'Create Document class object and set its size to letter and give space left, right, Top, Bottom Margin
Dim wri As PdfWriter = PdfWriter.GetInstance(doc, New FileStream(pdfFilePath, FileMode.Create))
doc.Open()
'Open Document to write
'Write some content into pdf file
: Dim paragraph As New Paragraph("This is my first line using Paragraph.")
' Now image in the pdf file
Dim imageFilePath As String = "C:\map.jpg"
Dim jpg As iTextSharp.text.Image = iTextSharp.text.Image.GetInstance(imageFilePath)
'Resize image depend upon your need
jpg.ScaleToFit(280.0F, 260.0F)
'Give space before image
jpg.SpacingBefore = 30.0F
'Give some space after the image
jpg.SpacingAfter = 1.0F
jpg.Alignment = Element.ALIGN_CENTER
doc.Add(paragraph)
' add paragraph to the document
'add an image to the created pdf document
doc.Add(jpg)
doc.Close()
Process.Start("C:\Documents and Settings\*****\Fichier.pdf")
End Sub
End Class |