itext 7
This commit is contained in:
@@ -6,10 +6,20 @@ Imports System.Net
|
||||
Imports System.Text
|
||||
Imports System.Text.RegularExpressions
|
||||
Imports System.Windows.Forms
|
||||
Imports DocumentFormat.OpenXml
|
||||
Imports iText.Kernel.Pdf
|
||||
Imports iText.Kernel.Pdf.Filespec
|
||||
Imports iText.Kernel.XMP
|
||||
Imports iText.Kernel.XMP.Options
|
||||
Imports iText.Pdfa
|
||||
Imports iText.Pdfa.Exceptions
|
||||
Imports iTextSharp.text.pdf
|
||||
Imports Spire.Pdf
|
||||
Imports Spire.Pdf.Attachments
|
||||
Imports Spire.Pdf.Graphics
|
||||
Imports Spire.Pdf.Print
|
||||
Imports PdfName = iTextSharp.text.pdf.PdfName
|
||||
|
||||
|
||||
|
||||
Public Class cDATENSERVER
|
||||
@@ -2438,109 +2448,109 @@ Public Class DATENVERVER_OPTIONS
|
||||
End Function
|
||||
|
||||
|
||||
Public Shared Function addZugferdXML(File As String, attPath As String) As String
|
||||
Dim tempFile As String = File & ".tmp"
|
||||
|
||||
Using reader As New PdfReader(File)
|
||||
Using fs As New FileStream(tempFile, FileMode.Create)
|
||||
Using stamper As New PdfStamper(reader, fs)
|
||||
|
||||
Dim xmlBytes = System.IO.File.ReadAllBytes(attPath)
|
||||
|
||||
Dim fileName As String = "factur-x.xml"
|
||||
|
||||
Dim fspec = PdfFileSpecification.FileEmbedded(
|
||||
stamper.Writer,
|
||||
fileName,
|
||||
fileName,
|
||||
xmlBytes,
|
||||
"application/xml",
|
||||
Nothing,
|
||||
0
|
||||
)
|
||||
|
||||
fspec.Put(PdfName.AFRELATIONSHIP, New PdfName("Alternative"))
|
||||
|
||||
stamper.Writer.AddFileAttachment("ZUGFeRD", fspec)
|
||||
|
||||
Dim af As New PdfArray()
|
||||
af.Add(fspec.Reference)
|
||||
stamper.Writer.ExtraCatalog.Put(PdfName.AFRELATIONSHIP, af)
|
||||
Public Shared Function addZugferdXML(pdfPath As String, xmlPath As String) As String
|
||||
|
||||
|
||||
SetZugferdXmp(stamper, fileName)
|
||||
Dim tempFile As String = pdfPath & ".tmp"
|
||||
|
||||
Using pdf As New iText.Kernel.Pdf.PdfDocument(New iText.Kernel.Pdf.PdfReader(pdfPath), New iText.Kernel.Pdf.PdfWriter(tempFile))
|
||||
|
||||
Dim xmlBytes = File.ReadAllBytes(xmlPath)
|
||||
Dim fileName As String = "factur-x.xml"
|
||||
|
||||
Dim fs = PdfFileSpec.CreateEmbeddedFileSpec(
|
||||
pdf,
|
||||
xmlBytes,
|
||||
"ZUGFeRD XML",
|
||||
fileName,
|
||||
New iText.Kernel.Pdf.PdfName("text/xml"),
|
||||
Nothing,
|
||||
New iText.Kernel.Pdf.PdfName("Alternative")
|
||||
)
|
||||
|
||||
pdf.AddFileAttachment("ZUGFeRD", fs)
|
||||
|
||||
' ✔ AF-Eintrag (PFLICHT!)
|
||||
Dim afArray As New iText.Kernel.Pdf.PdfArray()
|
||||
afArray.Add(fs.GetPdfObject())
|
||||
pdf.GetCatalog().Put(New iText.Kernel.Pdf.PdfName("AF"), afArray)
|
||||
|
||||
' ✔ XMP setzen
|
||||
SetZugferdXmp_NEW(pdf, fileName)
|
||||
|
||||
End Using
|
||||
End Using
|
||||
End Using
|
||||
|
||||
System.IO.File.Delete(File)
|
||||
System.IO.File.Move(tempFile, File)
|
||||
System.IO.File.Delete(pdfPath)
|
||||
System.IO.File.Move(tempFile, pdfPath)
|
||||
|
||||
Return pdfPath
|
||||
|
||||
Return File
|
||||
End Function
|
||||
|
||||
|
||||
Public Shared Function ConvertToPdfA3(inputPdf As String) As String
|
||||
|
||||
Dim tempFile As String = inputPdf & ".tmp"
|
||||
Dim outputPdf As String = inputPdf & ".pdfa.pdf"
|
||||
|
||||
Dim reader As New PdfReader(inputPdf)
|
||||
Dim iccBytes As Byte() = My.Resources.sRGB2014
|
||||
Dim iccStream As New MemoryStream(iccBytes)
|
||||
|
||||
Using fs As New FileStream(tempFile, FileMode.Create, FileAccess.Write)
|
||||
Using stamper As New PdfStamper(reader, fs)
|
||||
|
||||
' ✔ DAS ist in iTextSharp 5 der einzig relevante PDF/A-Baustein
|
||||
Dim iccPath As String =
|
||||
"C:\Windows\System32\spool\drivers\color\sRGB Color Space Profile.icm"
|
||||
|
||||
Dim icc = ICC_Profile.GetInstance(File.ReadAllBytes(iccPath))
|
||||
|
||||
stamper.Writer.SetOutputIntents(
|
||||
Using writer As New iText.Kernel.Pdf.PdfWriter(outputPdf)
|
||||
Using pdf As New PdfADocument(
|
||||
writer,
|
||||
PdfAConformance.PDF_A_3B,
|
||||
New PdfOutputIntent(
|
||||
"Custom",
|
||||
"",
|
||||
"http://www.color.org",
|
||||
"sRGB IEC61966-2.1",
|
||||
icc
|
||||
iccStream
|
||||
)
|
||||
)
|
||||
|
||||
stamper.Writer.PDFXConformance = PdfWriter.PDFX32002
|
||||
Dim reader As New iText.Kernel.Pdf.PdfReader(inputPdf)
|
||||
Dim srcDoc As New iText.Kernel.Pdf.PdfDocument(reader)
|
||||
|
||||
srcDoc.CopyPagesTo(1, srcDoc.GetNumberOfPages(), pdf)
|
||||
|
||||
srcDoc.Close()
|
||||
|
||||
End Using
|
||||
End Using
|
||||
|
||||
reader.Close()
|
||||
|
||||
If File.Exists(inputPdf) Then File.Delete(inputPdf)
|
||||
File.Move(tempFile, inputPdf)
|
||||
|
||||
Return inputPdf
|
||||
Return outputPdf
|
||||
|
||||
End Function
|
||||
|
||||
|
||||
Private Shared Sub SetZugferdXmp(stamper As PdfStamper, xmlFileName As String)
|
||||
|
||||
Dim xmp As String =
|
||||
"<?xpacket begin="""" id=""W5M0MpCehiHzreSzNTczkc9d""?>" &
|
||||
"<x:xmpmeta xmlns:x=""adobe:ns:meta/"">" &
|
||||
"<rdf:RDF xmlns:rdf=""http://www.w3.org/1999/02/22-rdf-syntax-ns#"" " &
|
||||
"xmlns:pdfaid=""http://www.aiim.org/pdfa/ns/id/"" " &
|
||||
"xmlns:zf=""urn:factur-x:pdfa:CrossIndustryDocument:invoice:2#"" >" &
|
||||
"<rdf:Description rdf:about="""">" &
|
||||
"<pdfaid:part>3</pdfaid:part>" &
|
||||
"<pdfaid:conformance>B</pdfaid:conformance>" &
|
||||
"<zf:DocumentType>INVOICE</zf:DocumentType>" &
|
||||
"<zf:DocumentFileName>" & xmlFileName & "</zf:DocumentFileName>" &
|
||||
"<zf:Version>2.1</zf:Version>" &
|
||||
"<zf:ConformanceLevel>EN 16931</zf:ConformanceLevel>" &
|
||||
"</rdf:Description>" &
|
||||
"</rdf:RDF>" &
|
||||
"</x:xmpmeta>" &
|
||||
"<?xpacket end=""w""?>"
|
||||
Private Shared Sub SetZugferdXmp_NEW(pdf As iText.Kernel.Pdf.PdfDocument, xmlFileName As String)
|
||||
|
||||
stamper.XmpMetadata = Encoding.UTF8.GetBytes(xmp)
|
||||
Dim xmp As XMPMeta = XMPMetaFactory.Create()
|
||||
|
||||
' =========================
|
||||
' PDF/A
|
||||
' =========================
|
||||
Dim pdfaNs As String = "http://www.aiim.org/pdfa/ns/id/"
|
||||
xmp.SetProperty(pdfaNs, "part", "3")
|
||||
xmp.SetProperty(pdfaNs, "conformance", "B")
|
||||
|
||||
' =========================
|
||||
' Factur-X Namespace
|
||||
' =========================
|
||||
Dim fxNs As String = "urn:factur-x:pdfa:CrossIndustryDocument:invoice:1p0#"
|
||||
|
||||
XMPMetaFactory.GetSchemaRegistry().RegisterNamespace(fxNs, "fx")
|
||||
|
||||
xmp.SetProperty(fxNs, "DocumentType", "INVOICE")
|
||||
xmp.SetProperty(fxNs, "DocumentFileName", xmlFileName)
|
||||
xmp.SetProperty(fxNs, "Version", "1.0")
|
||||
xmp.SetProperty(fxNs, "ConformanceLevel", "EN 16931")
|
||||
|
||||
' =========================
|
||||
' WICHTIG: KEIN XML-MANIPULATION
|
||||
' =========================
|
||||
pdf.SetXmpMetadata(xmp)
|
||||
|
||||
End Sub
|
||||
|
||||
|
||||
@@ -530,6 +530,16 @@ Namespace My.Resources
|
||||
End Get
|
||||
End Property
|
||||
|
||||
'''<summary>
|
||||
''' Sucht eine lokalisierte Ressource vom Typ System.Byte[].
|
||||
'''</summary>
|
||||
Friend ReadOnly Property sRGB2014() As Byte()
|
||||
Get
|
||||
Dim obj As Object = ResourceManager.GetObject("sRGB2014", resourceCulture)
|
||||
Return CType(obj,Byte())
|
||||
End Get
|
||||
End Property
|
||||
|
||||
'''<summary>
|
||||
''' Sucht eine lokalisierte Ressource vom Typ System.Drawing.Bitmap.
|
||||
'''</summary>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -953,7 +953,6 @@
|
||||
<EmbeddedResource Include="Benutzerdefinierte Steuerelemente\usrcntlKdSearch.resx">
|
||||
<DependentUpon>usrcntlKdSearch.vb</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="obj\x64\Debug\VERAG_PROG_ALLGEMEIN.frminterneEmailBenachrichtigungen.resources" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Classes\USTV\Swagger">
|
||||
@@ -963,6 +962,7 @@
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="ProgAllg.pfx" />
|
||||
<None Include="Resources\sRGB2014.icc" />
|
||||
<None Include="Schnittstellen\ATEZ\NCTS_API\JSON_schema\query_declarationSchema.json" />
|
||||
<None Include="Schnittstellen\ATEZ\NCTS_API\NCTS-P5\CC015C.xsd">
|
||||
<SubType>Designer</SubType>
|
||||
@@ -1492,6 +1492,9 @@
|
||||
<PackageReference Include="esendex-dotnet-sdk">
|
||||
<Version>3.8.0</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="itext7">
|
||||
<Version>9.6.0</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="JsonSubTypes">
|
||||
<Version>2.0.1</Version>
|
||||
</PackageReference>
|
||||
|
||||
Reference in New Issue
Block a user