List of usage examples for com.lowagie.text.pdf RandomAccessFileOrArray RandomAccessFileOrArray
public RandomAccessFileOrArray(RandomAccessFileOrArray file)
From source file:org.sejda.impl.itext.component.input.PartialReadPdfSourceOpener.java
License:Apache License
@Override PdfReader openSource(PdfFileSource source) throws IOException { return new PdfReader(new RandomAccessFileOrArray(source.getSource().getAbsolutePath()), source.getPasswordBytes());/*from w ww . ja v a2 s.c o m*/ }
From source file:org.sejda.impl.itext.component.input.PartialReadPdfSourceOpener.java
License:Apache License
@Override PdfReader openSource(PdfStreamSource source) throws IOException { return new PdfReader(new RandomAccessFileOrArray(source.getSource()), source.getPasswordBytes()); }
From source file:org.sipfoundry.faxrx.FaxProcessor.java
License:Open Source License
private File tiff2Pdf(File tiffFile) { Pattern pattern = Pattern.compile("(.*).tiff"); Matcher matcher = pattern.matcher(tiffFile.getName()); boolean matchFound = matcher.find(); // check if tiffFile is actually a TIFF file, just in case if (matchFound) { // located at default tmp-file directory File pdfFile = new File(System.getProperty("java.io.tmpdir"), matcher.group(1) + ".pdf"); try {//from w w w. ja va2 s.co m // read TIFF file RandomAccessFileOrArray tiff = new RandomAccessFileOrArray(tiffFile.getAbsolutePath()); // get number of pages of TIFF file int pages = TiffImage.getNumberOfPages(tiff); // create PDF file Document pdf = new Document(PageSize.LETTER, 0, 0, 0, 0); PdfWriter writer = PdfWriter.getInstance(pdf, new FileOutputStream(pdfFile)); writer.setStrictImageSequence(true); // open PDF filex pdf.open(); PdfContentByte contentByte = writer.getDirectContent(); // write PDF file page by page for (int page = 1; page <= pages; page++) { Image temp = TiffImage.getTiffImage(tiff, page); temp.scalePercent(7200f / temp.getDpiX(), 7200f / temp.getDpiY()); pdf.setPageSize(new Rectangle(temp.getScaledWidth(), temp.getScaledHeight())); temp.setAbsolutePosition(0, 0); contentByte.addImage(temp); pdf.newPage(); } // close PDF file pdf.close(); } catch (Exception e) { LOG.error("faxrx::tiff2Pdf error " + e.getMessage()); e.printStackTrace(); return null; } return pdfFile; } else { return null; } }
From source file:org.sipfoundry.faxrx.FaxRx.java
License:Contributor Agreement License
private File tiff2Pdf(File tiffFile) { Pattern pattern = Pattern.compile("(.*).tiff"); Matcher matcher = pattern.matcher(tiffFile.getName()); boolean matchFound = matcher.find(); // check if tiffFile is actually a TIFF file, just in case if (matchFound) { // located at default tmp-file directory File pdfFile = new File(System.getProperty("java.io.tmpdir"), matcher.group(1) + ".pdf"); try {/* w w w . java2 s . c o m*/ // read TIFF file RandomAccessFileOrArray tiff = new RandomAccessFileOrArray(tiffFile.getAbsolutePath()); // get number of pages of TIFF file int pages = TiffImage.getNumberOfPages(tiff); // create PDF file Document pdf = new Document(PageSize.LETTER); PdfWriter.getInstance(pdf, new FileOutputStream(pdfFile)); // open PDF filex pdf.open(); // write PDF file page by page for (int page = 1; page <= pages; page++) { Image temp = TiffImage.getTiffImage(tiff, page); pdf.add(temp); } // close PDF file pdf.close(); } catch (Exception e) { e.printStackTrace(); return null; } return pdfFile; } else { return null; } }
From source file:org.xhtmlrenderer.pdf.TrueTypeUtil.java
License:Open Source License
public static void populateDescription(String path, BaseFont font, FontDescription descr) throws IOException, NoSuchFieldException, IllegalAccessException, DocumentException { RandomAccessFileOrArray rf = null;// w w w .j ava2s. com try { rf = new RandomAccessFileOrArray(getTTCName(path)); rf = populateDescription0(path, font, descr, rf); } finally { if (rf != null) { try { rf.close(); } catch (IOException e) { // ignore } } } }
From source file:org.xhtmlrenderer.pdf.TrueTypeUtil.java
License:Open Source License
public static void populateDescription(String path, byte[] contents, BaseFont font, FontDescription descr) throws IOException, NoSuchFieldException, IllegalAccessException, DocumentException { RandomAccessFileOrArray rf = null;// w ww . ja v a2s.c o m try { rf = new RandomAccessFileOrArray(contents); rf = populateDescription0(path, font, descr, rf); } finally { if (rf != null) { try { rf.close(); } catch (IOException e) { // ignore } } } }
From source file:oscar.oscarEncounter.oscarConsultationRequest.pageUtil.ImagePDFCreator.java
License:Open Source License
/** * Prints the consultation request.//from w ww. ja va2s . c o m * @throws IOException when an error with the output stream occurs * @throws DocumentException when an error in document construction occurs */ public void printPdf() throws IOException, DocumentException { Image image; try { image = Image.getInstance((String) request.getAttribute("imagePath")); } catch (Exception e) { logger.error("Unexpected error:", e); throw new DocumentException(e); } // Create the document we are going to write to document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, os); document.setPageSize(PageSize.LETTER); ResourceBundle.getBundle("oscarResources", request.getLocale()) .getString("oscarEncounter.oscarConsultationRequest.consultationFormPrint.msgImage"); document.addCreator("OSCAR"); document.open(); int type = image.getOriginalType(); if (type == Image.ORIGINAL_TIFF) { // The following is composed of code from com.lowagie.tools.plugins.Tiff2Pdf modified to create the // PDF in memory instead of on disk RandomAccessFileOrArray ra = new RandomAccessFileOrArray((String) request.getAttribute("imagePath")); int comps = TiffImage.getNumberOfPages(ra); boolean adjustSize = false; PdfContentByte cb = writer.getDirectContent(); for (int c = 0; c < comps; ++c) { Image img = TiffImage.getTiffImage(ra, c + 1); if (img != null) { if (adjustSize) { document.setPageSize(new Rectangle(img.getScaledWidth(), img.getScaledHeight())); document.newPage(); img.setAbsolutePosition(0, 0); } else { if (img.getScaledWidth() > 500 || img.getScaledHeight() > 700) { img.scaleToFit(500, 700); } img.setAbsolutePosition(20, 20); document.newPage(); document.add( new Paragraph((String) request.getAttribute("imageTitle") + " - page " + (c + 1))); } cb.addImage(img); } } ra.close(); } else { PdfContentByte cb = writer.getDirectContent(); if (image.getScaledWidth() > 500 || image.getScaledHeight() > 700) { image.scaleToFit(500, 700); } image.setAbsolutePosition(20, 20); cb.addImage(image); } document.close(); }