Docx save as PDF metadata missing

Hi,
I would like to generate an accessible PDF. To do this, metadata must be present. I set the metadata via BuildInDocumentProperties, but in the output pdf they are empty. I’m using Aspose Word 26.4.0. Heres my code:

internal static byte[] BuildReport(object dataSource, byte[] vorlage, string titel, string author)
{
    using var documentStream = new MemoryStream(vorlage);

    var doc = new Aspose.Words.Document(documentStream);
    doc.Styles.DefaultFont.LocaleId = new CultureInfo("de-DE").LCID;

    var engine = new ReportingEngine
    {
        Options = ReportBuildOptions.RemoveEmptyParagraphs
    };

    engine.BuildReport(doc, dataSource, "r");

    var properties = doc.BuiltInDocumentProperties;
    properties.Title = titel;
    properties.Author = author;
    properties.NameOfApplication = "MyApplication";

    using var pdfStream = new MemoryStream();

    doc.Save(pdfStream, new PdfSaveOptions
    {
        Compliance = PdfCompliance.PdfUa1,
        DisplayDocTitle = true,
        ExportDocumentStructure = true,
        CustomPropertiesExport = PdfCustomPropertiesExport.Metadata,
        OptimizeOutput = true,

        OutlineOptions =
        {
            HeadingsOutlineLevels = 3,
            ExpandedOutlineLevels = 1
        }
    });

    return pdfStream.ToArray();
}

@jan.net Unfortunately, I cannot reproduce the problem on my side. As I can see the specified document properties are properly exported to PDF. I used the following code for testing:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Write("This is a simple test document.");

doc.BuiltInDocumentProperties.Title = "Top Secret!";
doc.BuiltInDocumentProperties.Author = "James Bond";
doc.BuiltInDocumentProperties.NameOfApplication = "MI-6-app";

PdfSaveOptions opt = new PdfSaveOptions();
opt.Compliance = PdfCompliance.PdfUa1;
            
doc.Save(@"C:\Temp\out.pdf", opt);

@alexey.noskov I tested your code and it works for me, too. But after creating, I combine several files into a single pdf file. That seems to be the problem. I use the PdfFileEditor Concatenate function with the following snippet.

public byte[] MergePdfs(params byte[][] pdfBytes)
{
    var editor = new PdfFileEditor();
    var pdfStreams = new List<Stream>();

    using (var outputStream = new MemoryStream())
    {
        foreach (var pdfByte in pdfBytes)
        {
            var stream = new MemoryStream(pdfByte);
            pdfStreams.Add(stream);
        }
        editor.Concatenate(pdfStreams.ToArray(), outputStream);

        return outputStream.ToArray();
    }
}

@jan.net PdfFileEditor is Aspose.PDF class. I will move your request to the appropriate forum category. My colleagues from Aspose.PDF team will help you shortly.

@jan.net
Could you provide files before and after concatenation in order to check and replicate the issue on our side, please?

@ilyazhuykov I attached the documents. I concatenate TestDocument1.pdf and TestDocument2.pdf and receive the out.pdf.

TestDocument1.pdf (22.4 KB)
TestDocument2.pdf (22.4 KB)
out.pdf (42.0 KB)