Когда у нас есть около 10 файлов для прикрепления к PDF, прикрепленный 10 -й файл не открывается. Он отображается должным образом в наложениях, но не открывается. Файл не поврежден.
PDFBox Версия: 2.0.16
PFB Код: < /p>
---------------Caller method code ---------------------------
// add the new node as kid to the root node
List kids = new
ArrayList();
int i=0;
for(String fileName : inboundFileNamesList)
{
i++;
attachFileToReport(pDDocument, kids, fileName, i);
}
efTree.setKids(kids);
// add the tree to the document catalog
names.setEmbeddedFiles(efTree);
pDDocument.getDocumentCatalog().setNames(names);
< /code>
------------------ Код метода абонента заканчивается --------------------------------- < /p>
private void attachFileToReport(PDDocument pDDocument,
List kids, String fileName, int fileIndex)
throws IOException
{
try
{
LOGGER.info("Picked GCAS file -> " + fileName);
PDComplexFileSpecification fs = new PDComplexFileSpecification();
fs.setFileUnicode(fileName);
File file = new File(fileName);
// now lets some of the optional parameters
PDEmbeddedFile ef = new PDEmbeddedFile(pDDocument, new FileInputStream(file));
ef.setSize((int)file.length());
LOGGER.debug("file size attached-> " + ef.getSize());
ef.setCreationDate(Calendar.getInstance());
fs.setEmbeddedFile(ef);
LOGGER.debug("Embeded file -> " + fs.getFile());
LOGGER.debug("fileIndex -> " + fileIndex);
// create a new tree node and add the embedded file
PDEmbeddedFilesNameTreeNode treeNode = new PDEmbeddedFilesNameTreeNode();
treeNode.setNames(Collections.singletonMap("File Index"+ fileIndex, fs));
kids.add(treeNode);
}
catch(Exception e)
{
LOGGER.error("Exception while attaching file : " + fileName + " to report");
}
}
Подробнее здесь: https://stackoverflow.com/questions/642 ... ttached-is
PDFBox - Если к PDF прикреплены несколько файлов, последний файл, который прикреплен не открывается ⇐ JAVA
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение