Ejemplo n.º 1
0
 /**
  * Opens the copier using the given reader and the given output version.
  *
  * @param reader
  * @param outputStream the output stream to write to.
  * @param version version for the created pdf copy, if null the version number is taken from the
  *     input {@link PdfReader}
  */
 void open(PdfReader reader, OutputStream outputStream, PdfVersion version) throws TaskException {
   try {
     pdfDocument = new Document(reader.getPageSizeWithRotation(1));
     pdfCopy = new PdfSmartCopy(pdfDocument, outputStream);
     if (version == null) {
       pdfCopy.setPdfVersion(reader.getPdfVersion());
     } else {
       pdfCopy.setPdfVersion(version.getVersionAsCharacter());
     }
     pdfDocument.addCreator(Sejda.CREATOR);
     pdfDocument.open();
   } catch (DocumentException e) {
     throw new TaskException("An error occurred opening the PdfSmartCopy.", e);
   }
 }
Ejemplo n.º 2
0
 public ImageResource getImageResource(String uri) {
   ImageResource resource = null;
   uri = resolveURI(uri);
   resource = (ImageResource) _imageCache.get(uri);
   if (resource == null) {
     InputStream is = resolveAndOpenStream(uri);
     if (is != null) {
       try {
         URL url = new URL(uri);
         if (url.getPath() != null && url.getPath().toLowerCase().endsWith(".pdf")) {
           PdfReader reader = _outputDevice.getReader(url);
           PDFAsImage image = new PDFAsImage(url);
           Rectangle rect = reader.getPageSizeWithRotation(1);
           image.setInitialWidth(rect.getWidth() * _outputDevice.getDotsPerPoint());
           image.setInitialHeight(rect.getHeight() * _outputDevice.getDotsPerPoint());
           resource = new ImageResource(uri, image);
         } else {
           Image image = Image.getInstance(url);
           scaleToOutputResolution(image);
           resource = new ImageResource(uri, new ITextFSImage(image));
         }
         _imageCache.put(uri, resource);
       } catch (IOException e) {
         XRLog.exception("Can't read image file; unexpected problem for URI '" + uri + "'", e);
       } catch (BadElementException e) {
         XRLog.exception("Can't read image file; unexpected problem for URI '" + uri + "'", e);
       } catch (URISyntaxException e) {
         XRLog.exception("Can't read image file; unexpected problem for URI '" + uri + "'", e);
       } finally {
         try {
           is.close();
         } catch (IOException e) {
           // ignore
         }
       }
     }
   }
   if (resource == null) {
     resource = new ImageResource(uri, null);
   }
   return resource;
 }