我試圖生成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它工作得很好,但我需要生成一個級別的文件!
非常感謝布魯諾!是爲了一個大學項目! –