Java Code Examples for org.apache.pdfbox.pdmodel.PDDocumentInformation#setModificationDate()

The following examples show how to use org.apache.pdfbox.pdmodel.PDDocumentInformation#setModificationDate() . 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: PdfTools.java    From MyBox with Apache License 2.0 6 votes vote down vote up
public static PDDocument createPDF(File file, String author) {
    PDDocument targetDoc = null;
    try {
        PDDocument document = new PDDocument(AppVariables.pdfMemUsage);
        PDDocumentInformation info = new PDDocumentInformation();
        info.setCreationDate(Calendar.getInstance());
        info.setModificationDate(Calendar.getInstance());
        info.setProducer("MyBox v" + CommonValues.AppVersion);
        info.setAuthor(author);
        document.setDocumentInformation(info);
        document.setVersion(1.0f);
        document.save(file);
        targetDoc = document;
    } catch (Exception e) {
        logger.error(e.toString());
    }
    return targetDoc;
}
 
Example 2
Source File: PdfSplitBatchController.java    From MyBox with Apache License 2.0 5 votes vote down vote up
private int writeFiles(List<PDDocument> docs) {
    int index = 1;
    try {
        if (docs == null || docs.isEmpty()) {
            return 0;
        }
        PDDocumentInformation info = new PDDocumentInformation();
        info.setCreationDate(Calendar.getInstance());
        info.setModificationDate(Calendar.getInstance());
        info.setProducer("MyBox v" + CommonValues.AppVersion);
        info.setAuthor(AppVariables.getUserConfigValue("AuthorKey", System.getProperty("user.name")));
        String targetPrefix = FileTools.getFilePrefix(currentParameters.currentSourceFile.getName());
        int total = docs.size();
        for (PDDocument pd : docs) {
            pd.setDocumentInformation(info);
            pd.setVersion(1.0f);
            PDPage page = pd.getPage(0);
            PDPageXYZDestination dest = new PDPageXYZDestination();
            dest.setPage(page);
            dest.setZoom(1f);
            dest.setTop((int) page.getCropBox().getHeight());
            PDActionGoTo action = new PDActionGoTo();
            action.setDestination(dest);
            pd.getDocumentCatalog().setOpenAction(action);

            String namePrefix = targetPrefix + "_" + StringTools.fillLeftZero(index++, (total + "").length());
            File tFile = makeTargetFile(namePrefix, ".pdf", currentParameters.currentTargetPath);
            pd.save(tFile);
            pd.close();

            targetFileGenerated(tFile);
        }
    } catch (Exception e) {
        logger.error(e.toString());
    }
    return index - 1;
}
 
Example 3
Source File: PdfTools.java    From MyBox with Apache License 2.0 4 votes vote down vote up
public static boolean images2Pdf(List<Image> images, File targetFile,
        WeiboSnapParameters p) {
    try {
        if (images == null || images.isEmpty()) {
            return false;
        }
        int count = 0, total = images.size();
        try ( PDDocument document = new PDDocument(AppVariables.pdfMemUsage)) {
            PDDocumentInformation info = new PDDocumentInformation();
            info.setCreationDate(Calendar.getInstance());
            info.setModificationDate(Calendar.getInstance());
            info.setProducer("MyBox v" + CommonValues.AppVersion);
            info.setAuthor(p.getAuthor());
            document.setDocumentInformation(info);
            document.setVersion(1.0f);
            PDFont font = getFont(document, p.getFontName());

            BufferedImage bufferedImage;
            for (Image image : images) {
                if (null == p.getFormat()) {
                    bufferedImage = SwingFXUtils.fromFXImage(image, null);
                } else {
                    switch (p.getFormat()) {
                        case Tiff:
                            bufferedImage = SwingFXUtils.fromFXImage(image, null);
                            break;
                        case Jpeg:
                            bufferedImage = FxmlImageManufacture.checkAlpha(image, "jpg");
                            break;
                        default:
                            bufferedImage = SwingFXUtils.fromFXImage(image, null);
                            break;
                    }
                }
                imageInPdf(document, bufferedImage, p, ++count, total, font);
            }

            PDPage page = document.getPage(0);
            PDPageXYZDestination dest = new PDPageXYZDestination();
            dest.setPage(page);
            dest.setZoom(p.getPdfScale() / 100.0f);
            dest.setTop((int) page.getCropBox().getHeight());
            PDActionGoTo action = new PDActionGoTo();
            action.setDestination(dest);
            document.getDocumentCatalog().setOpenAction(action);

            document.save(targetFile);
            document.close();
            return true;
        }

    } catch (Exception e) {
        logger.error(e.toString());
        return false;
    }

}