Open schorges opened 7 months ago
+1
This works for me :
`PdfSharpCore.Pdf.PdfDocument document = new PdfSharpCore.Pdf.PdfDocument(); var p = new PdfSharpCore.Pdf.PdfPage(); document.Pages.Add(p);
var embeddedFile = new PdfSharpCore.Pdf.Advanced.PdfEmbeddedFile(document); embeddedFile.CreateStream(Encoding.Default.GetBytes("Hello World!")); embeddedFile.MimeType = "text/plain";
var fs = new PdfSharpCore.Pdf.Advanced.PdfFileSpecification(document, "Hello World.txt", embeddedFile); document.Internals.AddObject(embeddedFile); document.Internals.AddObject(fs);
var arrayName = new PdfArray(document);
var dicNames = new PdfDictionary(document); dicNames.Elements.Add("/Names", new PdfArray(document, new PdfItem[] { new PdfString(fs.FileName), fs.Reference })); document.Internals.AddObject(dicNames);
var dicEmbeddedFiles = new PdfDictionary(document); dicEmbeddedFiles.Elements.Add("/EmbeddedFiles", dicNames.Reference); document.Internals.AddObject(dicEmbeddedFiles);
document.Internals.Catalog.Elements.Add("/Names", dicEmbeddedFiles.Reference);
document.Save(filename); `
Is there a way to attach a xml file to the pdf ?
Like this: https://stackoverflow.com/questions/70597318/af-reference-to-file-embedded-into-a-pdf-with-itextsharp