我试图生成PDF/A 1A,2A或3A与iText的为C#,但我遇到这样的问题:备用说明需要的图文档
“替代项应该指定/图元素的替代描述。“
我的代码如下所示:
public byte[] GeneratePDFA(byte[] inputPdf)
{
//System.out.println("PDF to PDF/A");
// step 1: creation of a document-object
iTextSharp.text.Document document = new iTextSharp.text.Document();
PdfReader reader = null;
MemoryStream ms = new MemoryStream();
try
{
// step 2:
// we create a writer that listens to the document
// and directs a PDF-stream to a file
PdfAWriter writer = PdfAWriter.GetInstance(document, ms, PdfAConformanceLevel.PDF_A_1A);
writer.SetTagged(PdfWriter.markAll);
document.AddAuthor("DiY");
document.AddSubject("DiY");
document.AddLanguage("it-IT");
document.AddCreationDate();
writer.CreateXmpMetadata();
//writer.setCompressionLevel(9);
// step 3: we open the document
document.Open();
PdfContentByte cb = writer.DirectContent; // Holds the PDF data
// step 4:
reader = new PdfReader(inputPdf);
PdfTemplate page;
// Get number of pages:
int pageCount = reader.NumberOfPages;
for (int i = 0; i < pageCount; i++)
{
document.NewPage();
page = writer.GetImportedPage(reader, i + 1);
cb.AddTemplate(page, 0d, 0d);
}
}
catch (DocumentException de)
{
throw de;
}
catch (IOException ioe)
{
throw ioe;
}
// step 5: we close the document
document.Close();
reader.Close();
document.Dispose();
reader.Dispose();
ms.Flush();
return ms.GetBuffer();
}
PS:如果我尝试生成一个PDF/A B1,B2或B3它工作得很好,但我需要生成一个级别的文件!
非常感谢布鲁诺!是为了一个大学项目! –