Aspose.Slides & Aspose.Cells - Metadata Could Not Set in PDF after Converting from XLSX/PPTX to PDF with PdfFormat v1.4, v1.5, v1.6, v1.7, v2.0

We have a problem with setting metadata in Pdf when we use PdfCompliance v_1_7.

First we do something in a Word, Excel or Powerpoint document and after our change we try to convert this document to Pdf with a certain Pdf.Compliance.

One problem is that we cannot use the correct PdfCompliance when we save the pptx/excel as not all compliance modes are available.

It looks like the namespace for “dc” is not set in the document:
image.png (41,4 KB)

Here is the code from my test with LinqPad:

using Aspose.Pdf;

void Main()
{	
	"Word".Dump();
	SetMetaDataWord(PdfFormat.v_1_4).Dump();
	SetMetaDataWord(PdfFormat.v_1_5).Dump();
	SetMetaDataWord(PdfFormat.v_1_6).Dump();
	SetMetaDataWord(PdfFormat.v_1_7).Dump();
	SetMetaDataWord(PdfFormat.v_2_0).Dump();
	SetMetaDataWord(PdfFormat.PDF_A_1A).Dump();
	SetMetaDataWord(PdfFormat.PDF_A_1B).Dump();
	SetMetaDataWord(PdfFormat.PDF_A_2A).Dump();
	SetMetaDataWord(PdfFormat.PDF_A_2B).Dump();
	SetMetaDataWord(PdfFormat.PDF_A_2U).Dump();

	"Excel".Dump();
	SetMetaDataExcel(PdfFormat.v_1_4).Dump();
	SetMetaDataExcel(PdfFormat.v_1_5).Dump();
	SetMetaDataExcel(PdfFormat.v_1_6).Dump();
	SetMetaDataExcel(PdfFormat.v_1_7).Dump();
	SetMetaDataExcel(PdfFormat.v_2_0).Dump();
	SetMetaDataExcel(PdfFormat.PDF_A_1A).Dump();
	SetMetaDataExcel(PdfFormat.PDF_A_1B).Dump();
	SetMetaDataExcel(PdfFormat.PDF_A_2A).Dump();
	SetMetaDataExcel(PdfFormat.PDF_A_2B).Dump();
	SetMetaDataExcel(PdfFormat.PDF_A_2U).Dump();

	"PowerPoint".Dump();
	SetMetaDataPowerPoint(PdfFormat.v_1_4).Dump();
	SetMetaDataPowerPoint(PdfFormat.v_1_5).Dump();
	SetMetaDataPowerPoint(PdfFormat.v_1_6).Dump();
	SetMetaDataPowerPoint(PdfFormat.v_1_7).Dump();
	SetMetaDataPowerPoint(PdfFormat.v_2_0).Dump();
	SetMetaDataPowerPoint(PdfFormat.PDF_A_1A).Dump();
	SetMetaDataPowerPoint(PdfFormat.PDF_A_1B).Dump();
	SetMetaDataPowerPoint(PdfFormat.PDF_A_2A).Dump();
	SetMetaDataPowerPoint(PdfFormat.PDF_A_2B).Dump();
	SetMetaDataPowerPoint(PdfFormat.PDF_A_2U).Dump();
}

public string SetMetaDataWord(PdfFormat pdfFormat)
{
	try {
		using (var pdfStream = new MemoryStream())
		{
			var document = new Aspose.Words.Document();
			document.Save(pdfStream, new Aspose.Words.Saving.PdfSaveOptions() { Compliance = Aspose.Words.Saving.PdfCompliance.Pdf17 });

			using (var pdfDocument = new Document(pdfStream))
			{
				using (var pdfConversionLogOutputStream = new MemoryStream())
				{
					pdfDocument.Convert(pdfConversionLogOutputStream, pdfFormat, ConvertErrorAction.Delete);
				}

				pdfDocument.Metadata["dc:subject"] = "test";
				
				return "ok";
			}
		}
	} catch (Exception e) {
		return e.Message;
	}
}

public string SetMetaDataExcel(PdfFormat pdfFormat)
{
	try
	{
		using (var pdfStream = new MemoryStream())
		{
			var document = new Aspose.Cells.Workbook();
			document.Save(pdfStream, new Aspose.Cells.PdfSaveOptions() { Compliance = Aspose.Cells.Rendering.PdfCompliance.Pdf17 });

			using (var pdfDocument = new Document(pdfStream))
			{
				using (var pdfConversionLogOutputStream = new MemoryStream())
				{
					pdfDocument.Convert(pdfConversionLogOutputStream, pdfFormat, ConvertErrorAction.Delete);
				}

				pdfDocument.Metadata["dc:subject"] = "test";

				return "ok";
			}
		}
	}
	catch (Exception e)
	{
		return e.Message;
	}
}

public string SetMetaDataPowerPoint(PdfFormat pdfFormat)
{
	try
	{
		using (var pdfStream = new MemoryStream())
		{
			var document = new Aspose.Slides.Presentation();
			document.Save(pdfStream, Aspose.Slides.Export.SaveFormat.Pdf, new Aspose.Slides.Export.PdfOptions() { Compliance = Aspose.Slides.Export.PdfCompliance.Pdf17 });

			using (var pdfDocument = new Document(pdfStream))
			{
				using (var pdfConversionLogOutputStream = new MemoryStream())
				{
					pdfDocument.Convert(pdfConversionLogOutputStream, pdfFormat, ConvertErrorAction.Delete);
				}

				pdfDocument.Metadata["dc:subject"] = "test";

				return "ok";
			}
		}
	}
	catch (Exception e)
	{
		return e.Message;
	}
}

Output:
image.png (4,8 KB)

Thanks for your help.

@jschur,
Thank you for contacting free support.

I need some time to check the problem. I will get back to you soon.

@jschur,
Thank you for your patience. We need to conduct a more in-depth study of the problem. I’ve moved this thread to Aspose.Total forum. My colleagues from Aspose.PDF team will investigate the case and find out what is wrong with PDF documents created from Excel and PowerPoint files.
@asad.ali FYI

Hi @andrey.potapov,
Hi @asad.ali,
Is there possibly a workauround for this? We have implemented and tested various ideas with ChatGPT, but without success.

Thanks for your help.

@jschur

If possible, could you please share sample PDF document that you have obtained from PPTX/Word/Excel file(s) along with respective source file? We will test the scenario in our environment and address it accordingly.