- 3.0.8.0 2026-08-03 Correcciones clase FirmaCanvas

This commit is contained in:
2026-09-04 08:56:53 +02:00
parent 25b72a0223
commit c0298979cc
8 changed files with 1440 additions and 14 deletions

View File

@@ -1,7 +1,11 @@
Imports System.IO
Imports System
Imports System.IO
Imports System.Security.Cryptography
Imports System.Security.Cryptography.X509Certificates
Imports TSpdfUtils
Imports tsPDFUtilsCore
Imports TSpdf
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
@@ -48,8 +52,8 @@ Public Class Form1
Public Shared Sub FirmaPDFPFX(Razon As String, Contacto As String, Localizacion As String, FicheroPdfDef As String, EliminaFirmasAnteriores As Boolean, Optional EliminaFicheroDestino As Boolean = False)
Dim p As String = "prueba1234."
Try
Dim bpfx = IO.File.ReadAllBytes("C:\tmp\mmm.pfx")
Dim bpdf = IO.File.ReadAllBytes("c:\tmp\E_2026-00322_sellado.pdf")
Dim bpfx = System.IO.File.ReadAllBytes("C:\tmp\mmm.pfx")
Dim bpdf = System.IO.File.ReadAllBytes("c:\tmp\E_2026-00322_sellado.pdf")
Dim pk As New X509Certificate2(bpfx, p, X509KeyStorageFlags.Exportable)
CambiaKeyContainerName(pk)
If pk.NotAfter < Now Then Throw New Exception("El certificado está caducado")
@@ -57,8 +61,8 @@ Public Class Form1
Dim ms As New MemoryStream
'tsUtilsPDF.pdf.FirmaPDF(pk, "", PdfStream, ms, Razon, Contacto, Localizacion, RutaTmp, EliminaFirmasAnteriores)
TSpdfUtils.Firmas.FirmaPDF(bpfx, p, "", New MemoryStream(bpdf), ms, Razon, Contacto, Localizacion, EliminaFirmasAnteriores)
If EliminaFicheroDestino AndAlso IO.File.Exists(FicheroPdfDef) Then IO.File.Delete(FicheroPdfDef)
IO.File.WriteAllBytes("c:\tmp\pruebafirmada.pdf", ms.ToArray)
If EliminaFicheroDestino AndAlso System.IO.File.Exists(FicheroPdfDef) Then System.IO.File.Delete(FicheroPdfDef)
System.IO.File.WriteAllBytes("c:\tmp\pruebafirmada.pdf", ms.ToArray)
Catch ex As Exception
Throw New Exception(ex.Message, ex)
End Try
@@ -71,4 +75,88 @@ Public Class Form1
rsa2.ImportParameters(rsa.ExportParameters(True))
Certificado.PrivateKey = rsa2
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
End Sub
Private Shared Sub FirmaDocumentoCFO(PdfOrigen As String, PdfDestino As String)
Dim br As Brush
Dim Imagen As Byte() = IO.File.ReadAllBytes("c:\tmp\OPENCOAS_LOGO.png")
'Dim TextoArt As String = ""
'If Doc.tiposdocumentosCOAS.Descripcion = "C.F.O. VISADO UNICO" Then
' TextoArt = "Conforme al Art. 5.1 del R.D. 1000/2010"
'End If
'If ds.NumeroExpedienteDocumentoOriginal.ToString <> "" Then
' ' probablemente haya que reducir la fuente en este caso
' TextoArt = "Sustituye al visado el " & ds.FechaVisadoOriginal.ToString("dd-MM-yyyy") & ". " & ds.NumeroExpedienteDocumentoOriginal.Split(" ")(1)
'Else
' Dim releds As relacionesentredocumentos = Doc.RelacionesComoHijo.FirstOrDefault(Function(x) x.Tipo = TipoRelacionEntreDocumentosEnum.SUSTITUCION)
' If releds IsNot Nothing Then
' Dim sFecVis As String
' If releds.DocumentoPadre.NumeroExpedienteDocumento.StartsWith("24/003566") OrElse releds.DocumentoPadre.NumeroExpedienteDocumento.StartsWith("24/003565") Then
' sFecVis = "22-12-2023"
' Else
' If releds.DocumentoPadre.FechaVisado.HasValue = False Then Throw New Exception("El documento al que sustituye no tiene fecha de visado")
' sFecVis = releds.DocumentoPadre.FechaVisado.Value.ToString("dd-MM-yyyy")
' End If
' TextoArt = "Sustituye al visado " & releds.DocumentoPadre.Documento & " el " & sFecVis
' End If
'End If
'If ds.TipoSello.StartsWith("2") Or ds.TipoSello.StartsWith("3") Then
' br = Brushes.Green
' Imagen = My.Resources.CFO_Verde
'Else
' br = Brushes.DarkBlue
' Imagen = My.Resources.CFO_Azul
'End If
Dim listadoTextos As List(Of DatosTextos) = New List(Of DatosTextos)
Dim listadoImagenes As List(Of DatosImagenFirma) = New List(Of DatosImagenFirma)
Dim Texto1 As New DatosTextos
Texto1.texto = "Solicitud Certificado Digital del COAS"
Texto1.size = 7.25
Texto1.NombreFuente = "Montserrat-Regular"
Texto1.PosicionEsquina = EsquinaEnum.INFERIOR_IZQUIERDA
Texto1.anguloRotacion = 270
Texto1.distanciaX = 7
Texto1.distanciaY = 715
Texto1.colorTexto = br
Texto1.estiloTexto = FontStyle.Regular
Texto1.AlineacionTexto = AlineamientoEnum.IZQUIERDA
listadoTextos.Add(Texto1)
Dim imagenFondo As New DatosImagenFirma
imagenFondo.PosicionEsquina = EsquinaEnum.INFERIOR_IZQUIERDA
imagenFondo.Alto = 100
imagenFondo.Ancho = 100
imagenFondo.PosicionX = 0
imagenFondo.PosicionY = 0
imagenFondo.AnguloRotacion = 270
imagenFondo.Imagen = Imagen
listadoImagenes.Add(imagenFondo)
Dim listadoFuentes As New List(Of DatosFuente)
Dim dfr As New DatosFuente
With dfr
.NombreFuente = "Montserrat-Regular"
.memoryFont = IO.File.ReadAllBytes("C:\tecnosis.tfs\Clientes\COAS\GestionWebCOAS\Content\Fuentes\Montserrat_Regular.ttf")
End With
listadoFuentes.Add(dfr)
Dim dfb As New DatosFuente
With dfb
.NombreFuente = "Montserrat-Bold"
.memoryFont = IO.File.ReadAllBytes("C:\tecnosis.tfs\Clientes\COAS\GestionWebCOAS\Content\Fuentes\Montserrat_Bold.ttf")
End With
listadoFuentes.Add(dfb)
Dim medidas As Kernel.Geom.Rectangle
'medidas = New Kernel.Geom.Rectangle(0, 0, 48.1889648, 396.8502)
medidas = New Kernel.Geom.Rectangle(0, 0, 48.1889648, 312.735)
TSpdfUtils.FirmaCanvas.FirmaPDFVisible(bPfx, ClavePFX, ClavePDF, PdfOrigen, PdfDestino, Razon, Contacto, Localizacion, bimagen, False, False, NombreCampoFirma, dcf, BloquearDocumento)
End Sub
End Class