itext 7
This commit is contained in:
@@ -112,6 +112,35 @@ Public Class frmKundenUebersichtZollRgDetails
|
||||
cFakturierung.doRechnungsDruck_SRorER(RK_ID,, False, 3,,,,, sammelrechnungskopie)
|
||||
End Sub
|
||||
|
||||
Public Shared Function ConvertToPdfA3_WithMustang(inputPdf As String) As String
|
||||
|
||||
Dim outputPdf As String = inputPdf & ".a3.pdf"
|
||||
|
||||
Dim mustangJar As String = "C:\Users\d.breimaier\Downloads\Mustang-CLI-2.21.0.jar" ' Pfad anpassen!
|
||||
|
||||
Dim psi As New ProcessStartInfo()
|
||||
psi.FileName = "C:\Program Files\Eclipse Adoptium\jre-11.0.28.6-hotspot\bin\java.exe"
|
||||
psi.Arguments = $"-Xmx1G -Dfile.encoding=UTF-8 -jar ""{mustangJar}"" --action a3only --source ""{inputPdf}"" --out ""{outputPdf}"""
|
||||
psi.UseShellExecute = False
|
||||
psi.RedirectStandardOutput = True
|
||||
psi.RedirectStandardError = True
|
||||
psi.CreateNoWindow = True
|
||||
|
||||
Using proc As Process = Process.Start(psi)
|
||||
Dim stdout As String = proc.StandardOutput.ReadToEnd()
|
||||
Dim stderr As String = proc.StandardError.ReadToEnd()
|
||||
|
||||
proc.WaitForExit()
|
||||
|
||||
If proc.ExitCode <> 0 Then
|
||||
Throw New Exception("Mustang Fehler: " & stderr)
|
||||
End If
|
||||
End Using
|
||||
|
||||
Return outputPdf
|
||||
|
||||
End Function
|
||||
|
||||
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
|
||||
|
||||
Dim Path_temp As String = ""
|
||||
@@ -121,6 +150,7 @@ Public Class frmKundenUebersichtZollRgDetails
|
||||
If Path_temp <> "" Then
|
||||
|
||||
Try
|
||||
'ConvertToPdfA3_WithMustang(Path_temp)
|
||||
|
||||
Dim psi As New ProcessStartInfo()
|
||||
|
||||
@@ -141,9 +171,9 @@ Public Class frmKundenUebersichtZollRgDetails
|
||||
Console.WriteLine(output)
|
||||
Console.WriteLine(err)
|
||||
|
||||
If err <> "" Then
|
||||
If output <> "" Then
|
||||
Dim tmpPath_Report = VERAG_PROG_ALLGEMEIN.DATENVERVER_OPTIONS.getTMPPath("MUSTANG-REPORT", ".pdf", , False)
|
||||
CreateValidationPdf(err, Path_temp, RK_ID, tmpPath_Report)
|
||||
CreateValidationPdf(output, Path_temp, RK_ID, tmpPath_Report)
|
||||
If tmpPath_Report <> "" Then Process.Start(tmpPath_Report)
|
||||
End If
|
||||
|
||||
@@ -157,28 +187,94 @@ Public Class frmKundenUebersichtZollRgDetails
|
||||
|
||||
End Sub
|
||||
|
||||
Private Function ExtractMustangResult(log As String, Invoice_file As String, RK_ID As Integer) As String
|
||||
Private Function ExtractMustangResult(xmlLog As String, invoiceFile As String, RK_ID As Integer) As String
|
||||
|
||||
Dim pdfStatus = If(log.Contains("Parsed PDF:invalid"), "INVALID", "VALID")
|
||||
Dim xmlStatus = If(log.Contains("XML:valid"), "VALID", "INVALID")
|
||||
Dim FileInfo As New FileInfo(Invoice_file)
|
||||
Dim Invoice As New cRechnungsausgang(RK_ID)
|
||||
Dim doc As New Xml.XmlDocument()
|
||||
doc.LoadXml(xmlLog)
|
||||
|
||||
Dim profile As String = "EN16931"
|
||||
If log.Contains("EN16931") Then profile = "EN16931"
|
||||
Dim fileInfo As New FileInfo(invoiceFile)
|
||||
Dim invoice As New cRechnungsausgang(RK_ID)
|
||||
|
||||
Dim took As String = ""
|
||||
Dim m = System.Text.RegularExpressions.Regex.Match(log, "Took:(\d+)ms")
|
||||
If m.Success Then took = m.Groups(1).Value & " ms"
|
||||
' --- PDF Status ---
|
||||
Dim pdfNode = doc.SelectSingleNode("//pdf/summary")
|
||||
Dim pdfStatus As String = If(pdfNode?.Attributes("status")?.Value = "valid", "VALID", "INVALID")
|
||||
|
||||
Return $"ZUGFeRD VALIDATION RESULT" & vbCrLf &
|
||||
$"--------------------------------" & vbCrLf &
|
||||
$"PDF File : {FileInfo.Name}" & vbCrLf &
|
||||
$"Invoice No : {Invoice.RechnungsNr}" & vbCrLf &
|
||||
$"PDF Status : {pdfStatus}" & vbCrLf &
|
||||
$"XML Status : {xmlStatus}" & vbCrLf &
|
||||
$"Profile : {profile}" & vbCrLf &
|
||||
$"Duration : {took}"
|
||||
' --- XML Status ---
|
||||
Dim xmlNode = doc.SelectSingleNode("//xml/summary")
|
||||
Dim xmlStatus As String = If(xmlNode?.Attributes("status")?.Value = "valid", "VALID", "INVALID")
|
||||
|
||||
' --- Profile ---
|
||||
Dim profileNode = doc.SelectSingleNode("//xml/info/profile")
|
||||
Dim profile As String = If(profileNode IsNot Nothing, profileNode.InnerText, "UNKNOWN")
|
||||
|
||||
' --- XML Version ---
|
||||
Dim xmlVersionNode = doc.SelectSingleNode("//xml/info/version")
|
||||
Dim xmlVersion As String = If(xmlVersionNode IsNot Nothing, xmlVersionNode.InnerText, "-")
|
||||
|
||||
' --- Validator Version ---
|
||||
Dim validatorNode = doc.SelectSingleNode("//xml/info/validator")
|
||||
Dim validatorVersion As String = validatorNode?.Attributes("version")?.Value
|
||||
|
||||
' --- Duration ---
|
||||
Dim pdfDuration = doc.SelectSingleNode("//pdf/info/duration")?.InnerText
|
||||
Dim xmlDuration = doc.SelectSingleNode("//xml/info/duration")?.InnerText
|
||||
|
||||
Dim duration As String = ""
|
||||
If pdfDuration IsNot Nothing AndAlso xmlDuration IsNot Nothing Then
|
||||
duration = $"{pdfDuration} ms (PDF) / {xmlDuration} ms (XML)"
|
||||
End If
|
||||
|
||||
' --- Tests ---
|
||||
Dim firedNode = doc.SelectSingleNode("//xml/info/rules/fired")
|
||||
Dim failedNode = doc.SelectSingleNode("//xml/info/rules/failed")
|
||||
|
||||
Dim fired As Integer = If(firedNode IsNot Nothing, Integer.Parse(firedNode.InnerText), 0)
|
||||
Dim failed As Integer = If(failedNode IsNot Nothing, Integer.Parse(failedNode.InnerText), 0)
|
||||
Dim passed As Integer = fired - failed
|
||||
|
||||
' --- PDF Errors ---
|
||||
Dim failedAssertions = doc.SelectNodes("//pdf//TestAssertion[@status='failed']")
|
||||
Dim errorCount As Integer = If(failedAssertions IsNot Nothing, failedAssertions.Count, 0)
|
||||
|
||||
' --- Top Errors ---
|
||||
Dim errorDetails As New List(Of String)
|
||||
If failedAssertions IsNot Nothing Then
|
||||
For i = 0 To Math.Min(2, failedAssertions.Count - 1)
|
||||
Dim msg = failedAssertions(i).Attributes("message")?.Value
|
||||
If msg IsNot Nothing Then errorDetails.Add("- " & msg)
|
||||
Next
|
||||
End If
|
||||
|
||||
' --- Output ---
|
||||
Dim result As New Text.StringBuilder()
|
||||
|
||||
result.AppendLine("ZUGFeRD VALIDATION RESULT")
|
||||
result.AppendLine("================================")
|
||||
result.AppendLine($"PDF File : {fileInfo.Name}")
|
||||
result.AppendLine($"Invoice No : {invoice.RechnungsNr}")
|
||||
result.AppendLine("--------------------------------")
|
||||
result.AppendLine($"PDF Status : {pdfStatus}")
|
||||
result.AppendLine($"XML Status : {xmlStatus}")
|
||||
result.AppendLine($"Profile : {profile}")
|
||||
result.AppendLine($"XML Version : {xmlVersion}")
|
||||
result.AppendLine($"Validator : {validatorVersion}")
|
||||
result.AppendLine("--------------------------------")
|
||||
result.AppendLine($"Tests Passed : {passed} / {fired}")
|
||||
result.AppendLine($"XML Failed : {failed}")
|
||||
result.AppendLine($"PDF Errors : {errorCount}")
|
||||
result.AppendLine($"Duration : {duration}")
|
||||
|
||||
If errorDetails.Count > 0 Then
|
||||
result.AppendLine("--------------------------------")
|
||||
result.AppendLine("Top Errors:")
|
||||
For Each err_ In errorDetails
|
||||
result.AppendLine(err_)
|
||||
Next
|
||||
End If
|
||||
|
||||
result.AppendLine("================================")
|
||||
|
||||
Return result.ToString()
|
||||
|
||||
End Function
|
||||
|
||||
|
||||
Reference in New Issue
Block a user