Package org.jpedal.exception

Examples of org.jpedal.exception.PdfException


           } catch (Exception e) {
             if(LogWriter.isOutput())
               LogWriter.writeLog("Exception " + e + " reading last 1024 bytes");
              
             throw new PdfException( e + " reading last 1024 bytes");
           }

           //    for(int ii=0;ii<lastBytes.length;ii++){
           //    System.out.print((char)lastBytes[ii]);
           //    }
           //    System.out.println();

           //look for tref as end of startxref
           int fileSize=lastBytes.length;

           if(i>fileSize)
               i=fileSize-5;

           while (i >-1) {

               //first check is because startref works as well a startxref !!
               if (((lastBytes[i] == 116 && lastBytes[i + 1] == 120) || (lastBytes[i] == 114 && lastBytes[i + 1] == 116))
                       && (lastBytes[i + 2] == 114)
                       && (lastBytes[i + 3] == 101)
                       && (lastBytes[i + 4] == 102))
                   break;


               i--;

           }

           /**trap buggy files*/
           if(i==-1){
               try {
                   closeFile();
               } catch (IOException e1) {
                 if(LogWriter.isOutput())
                   LogWriter.writeLog("Exception "+e1+" closing file");
               }
               throw new PdfException( "No Startxref found in last 1024 bytes ");
           }

           i = i + 5; //allow for word length

           //move to start of value ignoring spaces or returns
           while (i < 1024 && (lastBytes[i] == 10 || lastBytes[i] == 32 || lastBytes[i] == 13))
               i++;

           //move to start of value ignoring spaces or returns
           while ((i < 1024)
                   && (lastBytes[i] != 10)
                   && (lastBytes[i] != 32)
                   && (lastBytes[i] != 13)) {
               startRef.append((char) lastBytes[i]);
               i++;
           }

           /**convert xref to string to get pointer*/
           if (startRef.length() > 0)
               pointer = Integer.parseInt(startRef.toString());

           if (pointer == -1){
             if(LogWriter.isOutput())
               LogWriter.writeLog("No Startref found in last 1024 bytes ");
               try {
                   closeFile();
               } catch (IOException e1) {
                 if(LogWriter.isOutput())
                   LogWriter.writeLog("Exception "+e1+" closing file");
               }
               throw new PdfException( "No Startref found in last 1024 bytes ");
           }

           return pointer;
       }
View Full Code Here


                closeFile();
            } catch (IOException e1) {
              if(LogWriter.isOutput())
                LogWriter.writeLog("Exception "+1+" closing file");
            }
            throw new PdfException("Exception unable to find ref or obj in trailer");
        }

        return type == COMPRESSED;
    }
View Full Code Here

                    current++;

                    break;

                default:
                    throw new PdfException("Exception Unsupported Compression mode with value "+nextValue[0]);
            }
        }

        return pntr;
    }
View Full Code Here

            CSToRGB = new ColorConvertOp(cmykCS, rgbCS, ColorSpaces.hints);
        } catch (Exception e) {
          if(LogWriter.isOutput())
            LogWriter.writeLog("Exception " + e.getMessage() + " initialising color components");
           
          throw new PdfException("[PDF] Unable to create CMYK colorspace. Check cmyk.icm in jar file");

        }
    }
View Full Code Here

            if(!JAIHelper.isJAIused())
            message="JPeg 2000 Images and JAI not setup.\nYou need both JAI and imageio.jar on classpath, " +
        "and the VM parameter -Dorg.jpedal.jai=true switch turned on";

            throw new PdfException(message);
        }

        if(iir==null)
        return null;

        try{
            //  ImageIO.setUseCache(false);
            ImageInputStream iin = ImageIO.createImageInputStream(in);

            try{
                iir.setInput(iin, true);   //new MemoryCacheImageInputStream(in));

                image = iir.read(0);

                //does not work correctly if indexed so we manipulate the data
                //if you need to alter check  the images on page 42, 53, 71, 80, 89, 98, 107 and 114 are displayed in black
                //infinite/Plumbing_Fixtures_2_V1_replaced.pdf
                byte[] index = getIndexedMap();
                if(index!=null && value==ColorSpaces.DeviceRGB){

                    data = ((DataBufferByte) image.getRaster().getDataBuffer()).getData();
                    image=ColorSpaceConvertor.convertIndexedToFlat(8,w, h, data, index,false,false);

                }
            }catch(Exception e){

                if(LogWriter.isOutput())
                    LogWriter.writeLog("Problem reading JPEG 2000: " + e);

                e.printStackTrace();
                image=null;
            }finally {
               iir.dispose();
               iin.close();
               in.close();
            }

            if(image!=null){

                image=cleanupImage(image,pX,pY,value);

                //ensure white background
                if(image.getType()== BufferedImage.TYPE_BYTE_INDEXED){
                    BufferedImage oldImage=image;
                    int newW=image.getWidth();
                    int newH=image.getHeight();
                    image=new BufferedImage(newW, newH, BufferedImage.TYPE_INT_RGB);
                    Graphics2D g2= (Graphics2D) image.getGraphics();
                    g2.setPaint(Color.WHITE);
                    g2.fillRect(0,0,newW,newH);
                    g2.drawImage(oldImage,0,0,null);

                }

                image=ColorSpaceConvertor.convertToRGB(image);

            }
        } catch (Exception ee) {
      image = null;
     
      if(LogWriter.isOutput())
        LogWriter.writeLog("Problem reading JPEG 2000: " + ee);

            String message="Exception "+ee+" with JPeg 2000 Image";

            if(!JAIHelper.isJAIused())
            message="JPeg 2000 Images and JAI not setup.\nYou need both JAI and imageio.jar on classpath, " +
        "and the VM parameter -Dorg.jpedal.jai=true switch turned on";

            throw new PdfException(message);
      //ee.printStackTrace();
    } catch (Error ee2) {
      image = null;
            ee2.printStackTrace();
           
            if(LogWriter.isOutput())
              LogWriter.writeLog("Problem reading JPEG 2000: " + ee2);

      throw new PdfException("JPeg 2000 Images need both JAI (imageio.jar) on classpath, " +
        "and the VM parameter -Dorg.jpedal.jai=true switch turned on");
      //ee.printStackTrace();
    }

    return image;
View Full Code Here

     *
     * @return PdfData object containing text content from PDF
     */
    final public PdfData getPdfData() throws PdfException {
        if ((extractionMode & PdfDecoder.TEXT) == 0)
            throw new PdfException(
                    "[PDF] Page data object requested will be empty as text extraction disabled. Enable with PdfDecoder method setExtractionMode(PdfDecoder.TEXT | other values");
        else
            return pdfData;
    }
View Full Code Here

          if(LogWriter.isOutput())
            LogWriter.writeLog("Page " + pageIndex + " not in range");
        } else {

            if (currentPdfFile == null)
                throw new PdfException("File not open - did you call closePdfFile() inside a loop and not reopen");

            /** get pdf object id for page to decode */
            String currentPageOffset = currentPdfFile.getReferenceforPage(pageIndex);

            if (currentPageOffset != null) {
View Full Code Here

                    /**
                     * decode the file if not already decoded, there is a valid
                     * object id and it is unencrypted
                     */
                    if (currentPageOffset != null && currentPdfFile == null)
                        throw new PdfException("File not open - did you call closePdfFile() inside a loop and not reopen");

                    /** get pdf object id for page to decode */
                    if(pdfObject==null){
                        pdfObject=new PageObject(currentPageOffset);
                        currentPdfFile.readObject(pdfObject);
View Full Code Here

                     * object id and it is unencrypted
                     */
                    if ((currentPageOffset != null)) {

                        if (currentPdfFile == null)
                            throw new PdfException(
                                    "File not open - did you call closePdfFile() inside a loop and not reopen");

                        /** read page or next pages */
                        PdfObject pdfObject=new PageObject(currentPageOffset);
                        currentPdfFile.readObject(pdfObject);
View Full Code Here

     * password- calls verifyAccess() from 2.74 so no separate call needed
     */
    final public void setEncryptionPassword(String password) throws PdfException {

        if (currentPdfFile == null)
            throw new PdfException("Must open PdfDecoder file first");

        currentPdfFile.getObjectReader().setPassword(password);

        verifyAccess();
    }
View Full Code Here

TOP

Related Classes of org.jpedal.exception.PdfException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.