Skip to content

Commit 1ecf3ef

Browse files
committed
fix: update code snippet
1 parent 7eada2e commit 1ecf3ef

File tree

1 file changed

+17
-13
lines changed
  • net/advanced-operations/working-with-zugferd/attach-zugferd

1 file changed

+17
-13
lines changed

net/advanced-operations/working-with-zugferd/attach-zugferd/_index.md

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -91,21 +91,25 @@ We recommend following steps to attach ZUGFeRD to PDF:
9191
* Save the converted document as a new PDF file (e.g. "ZUGFeRD-res.pdf").
9292

9393
```cs
94-
var path = @"C:\Samples\ZUGFeRD\";
94+
var dataDir = @"C:\Samples\ZUGFeRD\";
9595

96-
var document = new Document(Path.Combine(path,"ZUGFeRD-test.pdf"));
97-
// Setup new file to be added as attachment
98-
var description = "Invoice metadata conforming to ZUGFeRD standard";
99-
var fileSpecification = new Aspose.Pdf.FileSpecification(Path.Combine(path, "factur-x.xml"), description)
96+
// Load PDF document
97+
using (var document = new Aspose.Pdf.Document(dataDir + "ZUGFeRD-test.pdf"))
10098
{
101-
Description = "Zugferd",
102-
MIMEType = "text/xml",
103-
AFRelationship = Aspose.Pdf.AFRelationship.Alternative
104-
};
105-
// Add attachment to document's attachment collection
106-
document.EmbeddedFiles.Add(fileSpecification);
107-
document.Convert(new MemoryStream(), Aspose.Pdf.PdfFormat.PDF_A_3U, Aspose.Pdf.ConvertErrorAction.Delete);
108-
document.Save(Path.Combine(path, "ZUGFeRD-res.pdf"));
99+
// Setup new file to be added as attachment
100+
var description = "Invoice metadata conforming to ZUGFeRD standard";
101+
var fileSpecification = new Aspose.Pdf.FileSpecification(dataDir + "factur-x.xml", description)
102+
{
103+
Description = "Zugferd",
104+
MIMEType = "text/xml",
105+
Name = "factur-x.xml"
106+
};
107+
// Add attachment to document's attachment collection
108+
document.EmbeddedFiles.Add(fileSpecification);
109+
document.Convert(new MemoryStream(), Aspose.Pdf.PdfFormat.ZUGFeRD, Aspose.Pdf.ConvertErrorAction.Delete);
110+
// Save result PDF
111+
document.Save(dataDir + "ZUGFeRD-res.pdf");
112+
}
109113
```
110114

111115
The convert method takes a stream, a PDF format, and a convert error action as parameters. The stream parameter can be used to save the conversion log. The convert error action parameter specifies what to do if any errors occur during the conversion. In this case, it is set to "Delete", which means that any elements that are not compliant with the PDF/A-3U format will be deleted from the document.

0 commit comments

Comments
 (0)