Inserimento di un’immagine e di un testo in un file PDF

 

' Il seguente frammento di codice mostra come si può inserire un'immagine e un testo in un file PDF
' Può essere usato in un form associato ad una categoria documentale di tipo file per apporre una firma e il nome
' di chi ha firmato su un file PDF

dim imgpath as string=Parameter1 ' Percorso dell'immagine, passato come parametro al metodo Execute di un oggetto Procedura

' Appone la firma anche sul PDF!
' vedere https://help.syncfusion.com/file-formats/pdf/working-with-images

' Recupera il percorso del documento PDF
dim f as string=form.GetDocumentPath()

'Load a PDF document.
Dim doc As New Syncfusion.Pdf.Parsing.PdfLoadedDocument(f)

'Get first page from document
Dim page As Syncfusion.Pdf.PdfLoadedPage = TryCast(doc.Pages(0), Syncfusion.Pdf.PdfLoadedPage)

'Create PDF graphics for the page
Dim graphics As Syncfusion.Pdf.Graphics.PdfGraphics = page.Graphics

'Load the image from the disk
Dim image As New Syncfusion.Pdf.Graphics.PdfBitmap(imgpath)

'Draw the image
graphics.DrawImage(image, 300,700,130,100) ' I parametri sono rispettivamente X,Y, width, height

'Set the standard font.
Dim font As Syncfusion.Pdf.Graphics.PdfFont = New Syncfusion.Pdf.Graphics.PdfStandardFont(Syncfusion.Pdf.Graphics.PdfFontFamily.Helvetica, 15)

'Draw the text.
graphics.DrawString(form.findcontrol("NOME").Value, font, Syncfusion.Pdf.Graphics.PdfBrushes.Black, 300, 750)

'Save the document.
doc.Save(f)

'Close the document.
doc.Close(True)

form.save()

E’ possibile scaricare una categoria documentale d’esempio da qui.