You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Tilman Hausherr (JIRA)" <ji...@apache.org> on 2015/07/09 06:41:04 UTC
[jira] [Closed] (PDFBOX-2866) getDocumentCatalog() returns no
results
[ https://issues.apache.org/jira/browse/PDFBOX-2866?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Tilman Hausherr closed PDFBOX-2866.
-----------------------------------
Resolution: Not A Problem
Assignee: Tilman Hausherr
Your document is encrypted with an empty user password, there is a log message that hints at this: "Document is encrypted". Please do this:
{code}
if (document.isEncrypted())
{
document.openProtection(new StandardDecryptionMaterial(""));
}
{code}
> getDocumentCatalog() returns no results
> ---------------------------------------
>
> Key: PDFBOX-2866
> URL: https://issues.apache.org/jira/browse/PDFBOX-2866
> Project: PDFBox
> Issue Type: Bug
> Components: PDModel
> Affects Versions: 1.8.9
> Reporter: Joseph Jezerinac
> Assignee: Tilman Hausherr
> Attachments: bad-to-png-test-2.pdf
>
>
> Test below fails, getAllPages() returns empty list should return 2 pages (see attached test pdf)
> {code:title=TestPdfToPng.java|borderStyle=solid}
> import org.apache.pdfbox.pdmodel.PDDocument;
> import org.apache.pdfbox.pdmodel.PDPage;
> import org.junit.Assert;
> import org.junit.Test;
> import javax.imageio.ImageIO;
> import java.awt.image.BufferedImage;
> import java.io.File;
> import java.io.IOException;
> import java.net.URL;
> import java.nio.file.Files;
> import java.nio.file.Path;
> import java.util.ArrayList;
> import java.util.List;
> public class TestPdfToPng {
> public class PdfToPngTest {
> @Test
> public void testConvert() throws Exception {
> testConvert(TestPdfToPng.class.getResource("/bad-to-png-test-2.pdf"), 2);
> }
> public void testConvert(URL url, int expectedPages) throws IOException {
> final Path outDir2 = Files.createTempDirectory("test-convert-png");
> final List<Path> images2 = toImages(url, outDir2);
> Assert.assertEquals(expectedPages, images2.size());
> }
> public List<Path> toImages(URL url, Path outDir) throws IOException {
> List<Path> images = new ArrayList<>();
> System.out.println("Images copied to Folder: " + outDir);
> try (PDDocument document = PDDocument.load(url)) {
> List<PDPage> list = document.getDocumentCatalog().getAllPages();
> System.out.println("Total files to be converted -> " + list.size());
> int pageNumber = 1;
> for (PDPage page : list) {
> final Path path = outDir.resolve("test" + "_" + pageNumber + ".png");
> final File imageFile = path.toFile();
> imageFile.deleteOnExit();
> BufferedImage image = page.convertToImage();
> ImageIO.write(image, "png", imageFile);
> System.out.println("Image Created -> " + imageFile.getName());
> images.add(path);
> pageNumber++;
> }
> }
> return images;
> }
> }
> }
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org