We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

MIMEtype is not set when adding an XML attachment to PDF

Hello dear Aspose Support,

we are currently implementing ZUGFeRD and have an issue adding an xml to the pdf.
In the FileSpecifications for the XML we set the MIMEType to “text/xml”. But in the finished pdf in the Stream folder of the embedded File SubType always remains “application/pdf”

I have debugged to the line where we add the filespecs to the document:
and could validate that MIMEType is set to “text/xml”.​
Could you please fix this issue as fast as possible?

Greetings from Frankfurt


Would you kindly share your sample code snippet along with source PDF/XML files. We will test the scenario in our environment and address it accordingly.

thanks for the fast reply.

For the first part we got the pdf and xml I uploaded with the path of xml in xInvoiceFile and a filehandler pdf filehandler and the related pdf

    If System.IO.File.Exists(xInvoiceFile) Then
                         Dim fSpecDict As System.Collections.Generic.Dictionary<String, String> = New System.Collections.Generic.Dictionary<String, String>()
                         fSpecDict.Add("AFRelationship", "Alternative")
                         Dim fh As FileHandler = FileHandler.GetFileHandler(xInvoiceFile)
                         pdfFileHandler.AddAttachment(fh, fSpecDict)

For the second part we have the AddAttachment(…) method:

using (Document document = HasDataStream ? new Document(DataStream) : new Document(Filename))
                FileSpecification fspec = new FileSpecification(addFileHandler.Filename);
                fspec.Encoding = FileEncoding.None;
                if (!string.IsNullOrEmpty(addFileHandler.Filename))
                    fspec.Description = Res.GetString(new CultureInfo("de-DE"), "ZUGFeRD Filedescription");
                    fspec.MIMEType = SBW.IO.MimeType.GetMimeType(addFileHandler.Filename).Value;
                    if (addFileHandler.MimeType != null)
                        fspec.MIMEType = addFileHandler.MimeType.Value;
                document.EmbeddedFiles.Add(Path.GetFileName(addFileHandler.Filename), fspec);
                FileParams fparams = new FileParams(fspec);
                fparams.CreationDate = DateTime.Now;
                fparams.ModDate = DateTime.Now;
                fspec.Params = fparams;
                document.Convert(new MemoryStream(), document.PdfFormat, ConvertErrorAction.Delete);
                if (fileSpecificationDict != null)
                    foreach (KeyValuePair<string, string> kvp in fileSpecificationDict)
                        fspec.SetValue(kvp.Key, kvp.Value);

I also tried setting all fspec properties except params before adding it to the document with no success.
sourcefiles.zip (68.4 KB)


We were able to notice the issue in our environment and have logged it as PDFNET-48921 in our issue tracking system. Please note that we are already working over adding ZUGFerd support to the API and will surely investigate your ticket as well. We will inform you as soon as we have some definite updates regarding its resolution. Please be patient and give us some time.

We are sorry for the inconvenience.