示例#1
0
 public void alterContents() throws IOException {
   if (over == null && under == null) return;
   PdfArray ar = null;
   PdfObject content = PdfReader.getPdfObject(pageN.get(PdfName.CONTENTS), pageN);
   if (content == null) {
     ar = new PdfArray();
     pageN.put(PdfName.CONTENTS, ar);
   } else if (content.isArray()) {
     ar = (PdfArray) content;
   } else if (content.isStream()) {
     ar = new PdfArray();
     ar.add(pageN.get(PdfName.CONTENTS));
     pageN.put(PdfName.CONTENTS, ar);
   } else {
     ar = new PdfArray();
     pageN.put(PdfName.CONTENTS, ar);
   }
   ByteBuffer out = new ByteBuffer();
   if (under != null) {
     out.append(PdfContents.SAVESTATE);
     applyRotation(pageN, out);
     out.append(under.getInternalBuffer());
     out.append(PdfContents.RESTORESTATE);
   }
   if (over != null) out.append(PdfContents.SAVESTATE);
   PdfStream stream = new PdfStream(out.toByteArray());
   stream.flateCompress(cstp.getCompressionLevel());
   PdfIndirectReference ref1 = cstp.addToBody(stream).getIndirectReference();
   ar.addFirst(ref1);
   out.reset();
   if (over != null) {
     out.append(' ');
     out.append(PdfContents.RESTORESTATE);
     out.append(PdfContents.SAVESTATE);
     applyRotation(pageN, out);
     out.append(over.getInternalBuffer());
     out.append(PdfContents.RESTORESTATE);
     stream = new PdfStream(out.toByteArray());
     stream.flateCompress(cstp.getCompressionLevel());
     ar.add(cstp.addToBody(stream).getIndirectReference());
   }
   pageN.put(PdfName.RESOURCES, pageResources.getResources());
 }
示例#2
0
 public static PdfObject createInfoId(byte id[]) {
   ByteBuffer buf = new ByteBuffer(90);
   buf.append('[').append('<');
   for (int k = 0; k < 16; ++k) buf.appendHex(id[k]);
   buf.append('>').append('<');
   id = createDocumentId();
   for (int k = 0; k < 16; ++k) buf.appendHex(id[k]);
   buf.append('>').append(']');
   return new PdfLiteral(buf.toByteArray());
 }
示例#3
0
 /**
  * Constructs a new <CODE>PdfName</CODE>.
  *
  * @param name the new name
  * @param lengthCheck if <CODE>true</CODE> check the lenght validity, if <CODE>false</CODE> the
  *     name can have any length
  */
 public PdfDicString(String name, boolean lengthCheck) {
   super(PdfObject.NAME);
   // The minimum number of characters in a name is 0, the maximum is 127 (the '/' not included)
   int length = name.length();
   // if (lengthCheck && length > 127) {
   //    throw new IllegalArgumentException("The name '" + name + "' is too long (" + length + "
   // characters).");
   // }
   // The name has to be checked for illegal characters
   // every special character has to be substituted
   ByteBuffer pdfName = new ByteBuffer(length + 20);
   char character;
   char chars[] = name.toCharArray();
   // loop over all the characters
   for (int index = 0; index < length; index++) {
     character = (char) (chars[index] & 0xff);
     pdfName.append(character);
   }
   bytes = pdfName.toByteArray();
 }