Itext7 – Как добавить встроенный файл с ключами f и uf в pdfaC#

Место общения программистов C#
Ответить Пред. темаСлед. тема
Anonymous
 Itext7 – Как добавить встроенный файл с ключами f и uf в pdfa

Сообщение Anonymous »

Мне сложно добавить XML-файл zugferd в качестве вложения в PDF-файл.

Код: Выделить всё

static void EmbedFile(PdfADocument pdfDoc, string filePath)
{
byte[] fileContent = File.ReadAllBytes(filePath);

PdfDictionary dict = new PdfDictionary();
dict.Put(PdfName.F, new PdfString(filePath));
dict.Put(PdfName.UF, new PdfString(filePath, PdfEncodings.UNICODE_BIG));

PdfFileSpec fileSpec = PdfFileSpec.CreateEmbeddedFileSpec(pdfDoc, fileContent, "ZUGFeRD XML File",  PdfName.Alternative);

pdfDoc.AddFileAttachment("zugferd.xml", fileSpec);

}

Код: Выделить всё

static void ConvertToPdfA3b(string sourcePdfPath, string outputPdfPath, string iccProfilePath, string zugferdXmlFilePath)
{
if (!File.Exists(iccProfilePath))
{
throw new FileNotFoundException("ICC profile not found at " + iccProfilePath);
}

using (iText.Kernel.Pdf.PdfWriter writer = new iText.Kernel.Pdf.PdfWriter(outputPdfPath))
{
using (PdfADocument pdfADoc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_3B, new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB_ICC_v4_Appearance",
new FileStream(iccProfilePath, FileMode.Open, FileAccess.Read))))
{
pdfADoc.GetDocumentInfo().SetTitle("PDF/A-3b Document");
pdfADoc.GetDocumentInfo().SetAuthor("Author Name");
pdfADoc.GetDocumentInfo().SetSubject("Subject of the Document");

XMPMeta xmpMeta = XMPMetaFactory.Create();
xmpMeta.SetProperty(XMPConst.NS_DC, DublinCoreProperties.FORMAT, "application/pdf");
xmpMeta.SetProperty(XMPConst.NS_DC, DublinCoreProperties.DESCRIPTION, "Converted to PDF/A-3b");

PdfCatalog catalog = pdfADoc.GetCatalog();

PdfDictionary markInfo = catalog.GetPdfObject().GetAsDictionary(PdfName.MarkInfo);
if (markInfo == null)
{
markInfo = new PdfDictionary();
catalog.GetPdfObject().Put(PdfName.MarkInfo, markInfo);
}
markInfo.Put(PdfName.Marked, iText.Kernel.Pdf.PdfBoolean.TRUE);

// Read the source PDF file and copy pages to the PdfADocument
using (iText.Kernel.Pdf.PdfDocument pdfDoc = new iText.Kernel.Pdf.PdfDocument(new iText.Kernel.Pdf.PdfReader(sourcePdfPath)))
{
pdfDoc.CopyPagesTo(1, pdfDoc.GetNumberOfPages(), pdfADoc);
}

pdfADoc.SetXmpMetadata(xmpMeta);
EmbedFile(pdfADoc, zugferdXmlFilePath);

// Close the document to save changes
pdfADoc.Close();
}
}
}
Я загружаю файл и добавляю ключи в словарь.
Но я получаю исключение: iText.Pdfa.Exceptions.PdfAConformanceException: «Словарь спецификации файла должен содержать ключ f». и ключ uf"

Подробнее здесь: https://stackoverflow.com/questions/786 ... ey-to-pdfa
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «C#»