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

Free Support Forum - aspose.com

Changing metadata in pdf document

Hi,

I am using Aspose.Total to convert various documents to PDF/A. In the last step of the process, in which a pdf is converted to pdf/a, I want to change the metadata of the document. Everything seems to go well, but when I open the document and check properties, the metadata I just added isn’t there.

This is the code I am using:

public
static MemoryStream
PdfToPdfa(Stream fileToConvert, Aspose.Pdf.PdfFormat format = Aspose.Pdf.PdfFormat.PDF_A_1A)<o:p></o:p>

{

MemoryStream resultStream = new MemoryStream();

try

{

using (Aspose.Pdf.Document pdfDoc = new Aspose.Pdf.Document(fileToConvert))

{

using (MemoryStream logStream = new MemoryStream())

{

if (pdfDoc.Convert(logStream, format, Aspose.Pdf.ConvertErrorAction.Delete))

{

pdfDoc.Metadata.Remove("pdf:Producer");

pdfDoc.Metadata.Add("pdf:Producer", "The producer");

pdfDoc.Metadata.Remove("xmp:CreatorTool");

pdfDoc.Metadata.Add("xmp:CreatorTool", "The tool");

pdfDoc.Metadata["xmp:CreateDate"] = "2012-11-10 09:08:07";

pdfDoc.Save(resultStream);

resultStream.Position = 0;

return resultStream;

}

else

{

logStream.Position = 0;

using (StreamReader sr = new StreamReader(logStream))

{

throw new Exception(sr.ReadToEnd());

}

}

}

}

}

catch (Exception ex)

{

resultStream.Dispose();

throw ex;

}

}

public void Convert()

{

try

{

string src = @"c:\test.pdf";

using (FileStream fs = new FileStream(src, FileMode.Open, FileAccess.Read))

{

using (MemoryStream ms = Converter.PdfToPdfa(fs))

{

ms.Position = 0;

System.IO.File.WriteAllBytes(string.Format("{0}.pdf", src), ms.ToArray());

}

}

}

catch (Exception ex)

{

// Handle exception

}

}


Am I doing something wrong, or is it not possible to update the metadata of the document?


Best regards,

Håkan

Hi Hakan,


Thanks for your inquiry. Please note as per design you can not change produce and creator tool value.

Furthermore while testing your code, I am getting following error after removing the metadata value using Aspose.Pdf for .NET 11.0.0.

"Unknown
prefix. Need to call method RegisterNamespaceURI
"

Please feel free to contact us for any further assistance.

Best Regards,