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.