Java Code Examples for org.apache.pdfbox.io.RandomAccessBufferedFileInputStream

The following examples show how to use org.apache.pdfbox.io.RandomAccessBufferedFileInputStream. These examples are extracted from open source projects. 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 Project: gcs   Source File: PDDocument.java    License: Mozilla Public License 2.0 6 votes vote down vote up
/**
 * Parses a PDF.
 * 
 * @param file file to be loaded
 * @param password password to be used for decryption
 * @param keyStore key store to be used for decryption when using public key security 
 * @param alias alias to be used for decryption when using public key security
 * @param memUsageSetting defines how memory is used for buffering PDF streams 
 * 
 * @return loaded document
 * 
 * @throws IOException in case of a file reading or parsing error
 */
public static PDDocument load(File file, String password, InputStream keyStore, String alias,
                              MemoryUsageSetting memUsageSetting) throws IOException
{
    @SuppressWarnings({"squid:S2095"}) // raFile not closed here, may be needed for signing
    RandomAccessBufferedFileInputStream raFile = new RandomAccessBufferedFileInputStream(file);
    try
    {
        return load(raFile, password, keyStore, alias, memUsageSetting);
    }
    catch (IOException ioe)
    {
        IOUtils.closeQuietly(raFile);
        throw ioe;
    }
}
 
Example 2
Source Project: gcs   Source File: PDDocument.java    License: Mozilla Public License 2.0 6 votes vote down vote up
private static PDDocument load(RandomAccessBufferedFileInputStream raFile, String password,
                               InputStream keyStore, String alias,
                               MemoryUsageSetting memUsageSetting) throws IOException
{
    ScratchFile scratchFile = new ScratchFile(memUsageSetting);
    try
    {
        PDFParser parser = new PDFParser(raFile, password, keyStore, alias, scratchFile);
        parser.parse();
        return parser.getPDDocument();
    }
    catch (IOException ioe)
    {
        IOUtils.closeQuietly(scratchFile);
        throw ioe;
    }
}
 
Example 3
Source Project: DocBleach   Source File: PdfBleach.java    License: MIT License 5 votes vote down vote up
@Override
public void sanitize(InputStream inputStream, OutputStream outputStream, BleachSession session)
    throws BleachException {
  try (RandomAccessRead source = new RandomAccessBufferedFileInputStream(inputStream)) {
    new PdfBleachSession(session).sanitize(source, outputStream);
  } catch (IOException e) {
    throw new BleachException(e);
  }
}
 
Example 4
Source Project: shrink-pdf   Source File: ShrinkPDF.java    License: MIT License 5 votes vote down vote up
/**
 * Shrink a PDF
 * @param f {@code File} pointing to the PDF to shrink
 * @param compQual Compression quality parameter. 0 is
 *                 smallest file, 1 is highest quality.
 * @return The compressed {@code PDDocument}
 * @throws FileNotFoundException
 * @throws IOException 
 */
private PDDocument shrinkMe() 
        throws FileNotFoundException, IOException {
     if(compQual < 0)
         compQual = compQualDefault;
     final RandomAccessBufferedFileInputStream rabfis = 
             new RandomAccessBufferedFileInputStream(input);
     final PDFParser parser = new PDFParser(rabfis);
     parser.parse();
     final PDDocument doc = parser.getPDDocument();
     final PDPageTree pages = doc.getPages();
     final ImageWriter imgWriter;
     final ImageWriteParam iwp;
     if(tiff) {
         final Iterator<ImageWriter> tiffWriters =
               ImageIO.getImageWritersBySuffix("png");
         imgWriter = tiffWriters.next();
         iwp = imgWriter.getDefaultWriteParam();
         //iwp.setCompressionMode(ImageWriteParam.MODE_DISABLED);
     } else {
         final Iterator<ImageWriter> jpgWriters = 
               ImageIO.getImageWritersByFormatName("jpeg");
         imgWriter = jpgWriters.next();
         iwp = imgWriter.getDefaultWriteParam();
         iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
         iwp.setCompressionQuality(compQual);
     }
     for(PDPage p : pages) {
          scanResources(p.getResources(), doc, imgWriter, iwp);
     }
     return doc;
}
 
Example 5
Source Project: gcs   Source File: SignatureOptions.java    License: Mozilla Public License 2.0 2 votes vote down vote up
/**
 * Reads the visual signature from the given file.
 *
 * @param file the file containing the visual signature
 * @throws IOException when something went wrong during parsing
 */
public void setVisualSignature(File file) throws IOException
{
    initFromRandomAccessRead(new RandomAccessBufferedFileInputStream(file));
}