public void saveFile( String fileName, PdfDocument document) { try { File mypath=new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),"filename.pdf"); document.writeTo(new FileOutputStream(mypath)); document.close(); }
/** * Signals that the <CODE>Document</CODE> was closed and that no other * <CODE>Elements</CODE> will be added. * <P> * The pages-tree is built and written to the outputstream. * A Catalog is constructed, as well as an Info-object, * the reference table is composed and everything is written * to the outputstream embedded in a Trailer. */ @Override public void close() { if (open) { pdf.close(); super.close(); // Users are responsible for closing PdfReader // if (ri != null) { // try { // ri.getReader().close(); // ri.getReaderFile().close(); // } // catch (IOException ioe) { // // empty on purpose // } // } } }
public createFile(String fileName, PdfDocument document){ FileOutputStream os; try { //Create folder in which you want to save Pdf documents File folder = new File(Environment.getExternalStorageDirectory(), "PdfFolder"); if(!folder.exists()){ folder.mkdirs(); } //Create pdf file File mPdfFile = new File(folder,fileName); //Make sure that there isn't a file with the same name if(!mPdfFile.exists(){ mPdfFile.createNewFile(); } os = new FileOutputStream(mPdfFile); document.writeTo(os); Toast.makeText(getApplicationContext, "File saved succesfully", Toast.LENGTH_SHORT).show(); } catch (IOException e) { Toast.makeText(getApplicationContext, "Something was wrong", Toast.LENGTH_SHORT).show(); e.printStackTrace(); }finally{ document.close(); if(os!=null)os.close(); } }
/** * Signals that the <CODE>Document</CODE> was closed and that no other * <CODE>Elements</CODE> will be added. * <P> * The pages-tree is built and written to the outputstream. * A Catalog is constructed, as well as an Info-object, * the reference table is composed and everything is written * to the outputstream embedded in a Trailer. */ @Override public void close() { if (open) { pdf.close(); super.close(); // Users are responsible for closing PdfReader // if (ri != null) { // try { // ri.getReader().close(); // ri.getReaderFile().close(); // } // catch (IOException ioe) { // // empty on purpose // } // } } }
// create a new document PdfDocument document = new PdfDocument(); // crate a page description PageInfo pageInfo = new PageInfo.Builder(new Rect(0, 0, 100, 100), 1).create(); // start a page Page page = document.startPage(pageInfo); // draw something on the page View content = getContentView(); content.draw(page.getCanvas()); // finish the page document.finishPage(page); . . . // add more pages . . . // write the document content document.writeTo(getOutputStream()); // close the document document.close();
PdfDocument doc = new PdfDocument(); // Read the image as BufferedImage object BufferedImage bufImg = ImageIO.read(new File( "SampleImage.PNG")); // Create PdfImage object using the above BufferedImage object PdfImage img = PdfImage.create(bufImg); // Create a PdfPage of image size (image width x image Height) PdfPage page1 = new PdfPage(img.width(), img.height()); // draw the image at 0, 0 page1.drawImage(img, 0, 0); // add the page to the document object doc.add(page1); // save the document to the output file doc.save("PNGImageToPDF.pdf"); doc.close();
PdfDocument pdfDoc = new PdfDocument(new PdfReader(SRC)); PdfObject obj; for (int i = 1; i <= pdfDoc.getNumberOfPdfObjects(); i++) { obj = pdfDoc.getPdfObject(i); if (obj != null && obj.isStream()) { byte[] b; try { b = ((PdfStream) obj).getBytes(); } catch (PdfException exc) { b = ((PdfStream) obj).getBytes(false); } FileOutputStream fos = new FileOutputStream(String.format(DEST, i)); fos.write(b); fos.close(); } } pdfDoc.close();
// create a new document PdfDocument document = new PdfDocument(); // crate a page description PageInfo pageInfo = new PageInfo.Builder(300, 300, 1).create(); // start a page Page page = document.startPage(pageInfo); // draw something on the page View content = getContentView(); content.draw(page.getCanvas()); // finish the page document.finishPage(page); . . . // add more pages . . . // write the document content document.writeTo(getOutputStream()); // close the document document.close();
OutputStream out = new FileOutputStream(mFile); document.writeTo(out); document.close(); out.close(); } catch (IOException e) {
public static File generate(View salesFragmentTableLayout, Context context) throws KingdomSpasException { PdfDocument document = new PdfDocument(); PageInfo pageInfo = new PageInfo.Builder(300, 300, 1).create(); Page page = document.startPage(pageInfo); // Try adding these lines // draw view on the page int measureWidth = View.MeasureSpec.makeMeasureSpec(page.getCanvas().getWidth(), View.MeasureSpec.EXACTLY); int measuredHeight = View.MeasureSpec.makeMeasureSpec(page.getCanvas().getHeight(), View.MeasureSpec.EXACTLY); salesFragmentTableLayout.measure(measureWidth, measuredHeight); salesFragmentTableLayout.layout(0, 0, page.getCanvas().getWidth(), page.getCanvas().getHeight()); salesFragmentTableLayout.draw(page.getCanvas()); document.finishPage(page); File result = null; try { result = File.createTempFile("Kingdom Spas Agreement", ".pdf", context.getCacheDir()); document.writeTo(new BufferedOutputStream(new FileOutputStream(result))); } catch (FileNotFoundException e) { throw new KingdomSpasException("Failed to find relevent file", e); } catch (IOException e) { throw new KingdomSpasException("IO Problem occured while creatin the PDF", e); } document.close(); return result; }
OutputStream out = new FileOutputStream(outputFile); document.writeTo(out); document.close(); out.close(); } catch (IOException e) {
OutputStream out = new FileOutputStream(outputFile); document.writeTo(out); document.close(); out.close(); } catch (IOException e) {
os = new FileOutputStream(file); document.writeTo(os); document.close(); os.close(); Log.i("done", file.getAbsolutePath().toString());
FileOutputStream fos = new FileOutputStream(f); document.writeTo(fos); document.close(); fos.close(); } catch (IOException e) {
FileOutputStream fos = new FileOutputStream(f); document.writeTo(fos); document.close(); fos.close(); } catch (IOException e) {
document.close(); PdfSigner signer = new PdfSigner(new PdfReader(dest + "_temp"), new FileOutputStream(dest), true);
document.close();
e.printStackTrace(); document.close();