Me gustaría asociar un archivo de catálogo de búsqueda PDX con un documento PDF. Aparentemente, actualmente no hay una biblioteca que admita esto de forma inmediata, por lo que lo que tengo que hacer es manipular la /Search
entrada en el documento directamente. No sé casi nada sobre el estándar PDF, por lo que una biblioteca a la que pueda acceder desde el código .NET que encapsularía la mayoría de los detalles para mí sería genial.
Con PDFNet puede insertar/editar fácilmente un PDF como está buscando.
https://www.pdftron.com/documentation/samples/cs/SDFTest?platforms=windows https://www.pdftron.com/pdf-sdk/windows-library
También hay versiones de Universal Windows Platform y Xamarin disponibles si está buscando hacer esto en dispositivos móviles.
https://www.pdftron.com/documentation/uwp/guides https://www.pdftron.com/documentation/xamarin/guides
La biblioteca XFINIUM.PDF incluye una API COS que le permite crear estructuras personalizadas en archivos PDF.
El siguiente código muestra cómo construir la estructura de búsqueda en su muestra:
// Create a new document.
PdfFixedDocument document = new PdfFixedDocument();
// Or load an existing document.
// PdfFixedDocument document = new PdfFixedDocument("sample.pdf");
// Fill the document information.
document.DocumentInformation = new PdfDocumentInformation();
document.DocumentInformation.Author = "XFINIUM Software";
document.DocumentInformation.CreationDate = DateTime.Now;
document.DocumentInformation.ModifyDate = DateTime.Now;
document.DocumentInformation.Creator = "XFINIUM.PDF COS objects sample";
document.DocumentInformation.Producer = "XFINIUM.PDF Toolkit";
document.DocumentInformation.Title = "XFINIUM.PDF COS objects sample";
document.DocumentInformation.Subject = "XFINIUM.PDF sample code";
document.DocumentInformation.Keywords = "xfinium.pdf, pdf, sample";
// Create the /Search structure
PdfCosDictionaryContainer cosSearchDictionary = new PdfCosDictionaryContainer();
document.CosDictionary["/Search"] = cosSearchDictionary;
PdfCosArray indexesArray = new PdfCosArray();
cosSearchDictionary["/Indexes"] = indexesArray;
PdfCosDictionaryContainer indexDefinitionDictionary = new PdfCosDictionaryContainer();
indexesArray.Add(indexDefinitionDictionary);
indexDefinitionDictionary["/Name"] = new PdfCosName("/PDX");
PdfCosDictionaryContainer indexFileDictionary = new PdfCosDictionaryContainer();
indexDefinitionDictionary["/Index"] = indexFileDictionary;
indexFileDictionary["/Type"] = new PdfCosName("/Filespec");
indexFileDictionary["/F"] = new PdfCosString("c:\\Folder1\\Folder2\\index.pdx");
PdfPage page = document.Pages.Add();
document.Save("D:\\Temp\\Sample_SearchIndex.pdf");
La estructura /Search se puede ver en la siguiente imagen:
Descargo de responsabilidad: trabajo para la empresa que desarrolla la biblioteca.
Lo siento, no vi las respuestas antes. Pude resolver esto usando PdfSharp .
Código publicado aquí: https://stackoverflow.com/questions/51127552/how-to-associate-search-catalog-file-pdx-with-pdf-document/51177573#51177573