public int getStartxref() throws IOException {
   int size = Math.min(1024, file.length());
   int pos = file.length() - size;
   file.seek(pos);
   String str = readString(1024);
   int idx = str.lastIndexOf("startxref");
   if (idx < 0) throw new IOException("PDF startxref not found.");
   return pos + idx;
 }
Beispiel #2
0
 private void openpfm() throws IOException {
   in.seek(0);
   vers = in.readShortLE();
   h_len = in.readIntLE();
   copyright = readString(60);
   type = in.readShortLE();
   points = in.readShortLE();
   verres = in.readShortLE();
   horres = in.readShortLE();
   ascent = in.readShortLE();
   intleading = in.readShortLE();
   extleading = in.readShortLE();
   italic = (byte) in.read();
   uline = (byte) in.read();
   overs = (byte) in.read();
   weight = in.readShortLE();
   charset = (byte) in.read();
   pixwidth = in.readShortLE();
   pixheight = in.readShortLE();
   kind = (byte) in.read();
   avgwidth = in.readShortLE();
   maxwidth = in.readShortLE();
   firstchar = in.read();
   lastchar = in.read();
   defchar = (byte) in.read();
   brkchar = (byte) in.read();
   widthby = in.readShortLE();
   device = in.readIntLE();
   face = in.readIntLE();
   bits = in.readIntLE();
   bitoff = in.readIntLE();
   extlen = in.readShortLE();
   psext = in.readIntLE();
   chartab = in.readIntLE();
   res1 = in.readIntLE();
   kernpairs = in.readIntLE();
   res2 = in.readIntLE();
   fontname = in.readIntLE();
   if (h_len != in.length() || extlen != 30 || fontname < 75 || fontname > 512)
     throw new IOException(MessageLocalization.getComposedMessage("not.a.valid.pfm.file"));
   in.seek(psext + 14);
   capheight = in.readShortLE();
   xheight = in.readShortLE();
   ascender = in.readShortLE();
   descender = in.readShortLE();
 }
 /**
  * If the embedded flag is <CODE>false</CODE> or if the font is one of the 14 built in types, it
  * returns <CODE>null</CODE>, otherwise the font is read and output in a PdfStream object.
  *
  * @return the PdfStream containing the font or <CODE>null</CODE>
  * @throws DocumentException if there is an error reading the font
  */
 private PdfStream getFontStream() throws DocumentException {
   if (builtinFont || !embedded) return null;
   RandomAccessFileOrArray rf = null;
   try {
     String filePfb = fileName.substring(0, fileName.length() - 3) + "pfb";
     if (pfb == null) rf = new RandomAccessFileOrArray(filePfb);
     else rf = new RandomAccessFileOrArray(pfb);
     int fileLength = rf.length();
     byte st[] = new byte[fileLength - 18];
     int lengths[] = new int[3];
     int bytePtr = 0;
     for (int k = 0; k < 3; ++k) {
       if (rf.read() != 0x80) throw new DocumentException("Start marker missing in " + filePfb);
       if (rf.read() != PFB_TYPES[k])
         throw new DocumentException("Incorrect segment type in " + filePfb);
       int size = rf.read();
       size += rf.read() << 8;
       size += rf.read() << 16;
       size += rf.read() << 24;
       lengths[k] = size;
       while (size != 0) {
         int got = rf.read(st, bytePtr, size);
         if (got < 0) throw new DocumentException("Premature end in " + filePfb);
         bytePtr += got;
         size -= got;
       }
     }
     return new StreamFont(st, lengths);
   } catch (Exception e) {
     throw new DocumentException(e);
   } finally {
     if (rf != null) {
       try {
         rf.close();
       } catch (Exception e) {
         // empty on purpose
       }
     }
   }
 }
 public int length() throws IOException {
   return file.length();
 }