Java Code Examples for com.itextpdf.text.pdf.PdfReader#getInfo()

The following examples show how to use com.itextpdf.text.pdf.PdfReader#getInfo() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UpdateMetaData.java    From testarea-itext5 with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * <a href="http://stackoverflow.com/questions/43511558/how-to-set-attributes-for-existing-pdf-that-contains-only-images-using-java-itex">
 * how to set attributes for existing pdf that contains only images using java itext?
 * </a>
 * <p>
 * The OP indicated in a comment that he searches a solution without a second file.
 * This test shows how to work with a single file, by first loading the file into a byte array.
 * </p>
 */
@Test
public void testChangeTitleWithoutTempFile() throws IOException, DocumentException
{
    File singleFile = new File(RESULT_FOLDER, "eg_01-singleFile.pdf");
    try (   InputStream resource = getClass().getResourceAsStream("eg_01.pdf")  )
    {
        Files.copy(resource, singleFile.toPath());
    }

    byte[] original = Files.readAllBytes(singleFile.toPath());

    PdfReader reader = new PdfReader(original);
    PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(singleFile));
    Map<String, String> info = reader.getInfo();
    info.put("Title", "New title");
    info.put("CreationDate", new PdfDate().toString());
    stamper.setMoreInfo(info);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    XmpWriter xmp = new XmpWriter(baos, info);
    xmp.close();
    stamper.setXmpMetadata(baos.toByteArray());
    stamper.close();
    reader.close();
}
 
Example 2
Source File: CropManager.java    From Briss-2.0 with GNU General Public License v3.0 5 votes vote down vote up
public static CropJob createCropJob(ClusterJob curClusterJob) throws IOException {
    File source = curClusterJob.getSource();
    if (source != null && source.exists()) {
        PdfReader reader = new PdfReader(source.getAbsolutePath());
        CropJob result = new CropJob(source, reader.getNumberOfPages(), reader.getInfo(),
            SimpleBookmark.getBookmark(reader));
        reader.close();
        result.setClusterCollection(curClusterJob.getClusterCollection());
        return result;
    }
    return null;
}
 
Example 3
Source File: CropManager.java    From Briss-2.0 with GNU General Public License v3.0 5 votes vote down vote up
public static CropJob createCropJob(File source) throws IOException {
    CropJob result = null;
    if (source != null && source.exists()) {
        PdfReader reader = new PdfReader(source.getAbsolutePath());
        result = new CropJob(source, reader.getNumberOfPages(), reader.getInfo(), SimpleBookmark.getBookmark(reader));
        reader.close();
        return result;
    }
    return result;
}
 
Example 4
Source File: DocumentCropper.java    From Briss-2.0 with GNU General Public License v3.0 5 votes vote down vote up
public PdfMetaInformation(final File source) throws IOException {
    PdfReader reader = new PdfReader(source.getAbsolutePath());
    this.sourcePageCount = reader.getNumberOfPages();
    this.sourceMetaInfo = reader.getInfo();
    this.sourceBookmarks = SimpleBookmark.getBookmark(reader);
    reader.close();

}