I am trying to retrieve a File or InputStream instance from PDDocument without saving a PDDocument to the file system.
 PDDocument doc= new PDDocument(); 
 ...     
 doc.save("D:\\document.pdf"); 
 File f= new File("D:\\document.pdf"); 
Is there any method in PDFBox which returns File or InputStream from an existing PDDocument?
I solved it:
PDDocument doc=new PDDocument();        
PDStream ps=new PDStream(doc);
InputStream is=ps.createInputStream();
                        I solve it in this way ( It's creating a file but in temporary-file directory ):
final PDDocument document = new PDDocument();
final File file = File.createTempFile(filename, ".pdf");
document.save(file);
and if you need
document.close();
                        What if you first create the outputstream
PDDocument doc= new PDDocument(); 
File f= new File("D:\\document.pdf");
FileOutputStream fOut = new FileOutputStream(f);  
doc.save(fOut); 
Take a look at this http://pdfbox.apache.org/apidocs/org/apache/pdfbox/pdmodel/PDDocument.html#save(java.io.OutputStream)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With