Finish() public method

public Finish ( ) : void
return void
Ejemplo n.º 1
0
 /**
 * Compresses the stream.
 * @param compressionLevel the compression level (0 = best speed, 9 = best compression, -1 is default)
 * @since   2.1.3
 */
 virtual public void FlateCompress(int compressionLevel) {
     if (!Document.Compress)
         return;
     // check if the flateCompress-method has already been used
     if (compressed) {
         return;
     }
     this.compressionLevel = compressionLevel;
     if (inputStream != null) {
         compressed = true;
         return;
     }
     // check if a filter already exists
     PdfObject filter = PdfReader.GetPdfObject(Get(PdfName.FILTER));
     if (filter != null) {
         if (filter.IsName()) {
             if (PdfName.FLATEDECODE.Equals(filter))
                 return;
         }
         else if (filter.IsArray()) {
             if (((PdfArray) filter).Contains(PdfName.FLATEDECODE))
                 return;
         }
         else {
             throw new PdfException(MessageLocalization.GetComposedMessage("stream.could.not.be.compressed.filter.is.not.a.name.or.array"));
         }
     }
     // compress
     MemoryStream stream = new MemoryStream();
     ZDeflaterOutputStream zip = new ZDeflaterOutputStream(stream, compressionLevel);
     if (streamBytes != null)
         streamBytes.WriteTo(zip);
     else
         zip.Write(bytes, 0, bytes.Length);
     //zip.Close();
     zip.Finish();
     // update the object
     streamBytes = stream;
     bytes = null;
     Put(PdfName.LENGTH, new PdfNumber(streamBytes.Length));
     if (filter == null) {
         Put(PdfName.FILTER, PdfName.FLATEDECODE);
     }
     else {
         PdfArray filters = new PdfArray(filter);
         filters.Add(0, PdfName.FLATEDECODE);
         Put(PdfName.FILTER, filters);
     }
     compressed = true;
 }
Ejemplo n.º 2
0
 public void WriteIccProfile(byte[] data)
 {
     MemoryStream stream = new MemoryStream();
     stream.WriteByte((byte)'I');
     stream.WriteByte((byte)'C');
     stream.WriteByte((byte)'C');
     stream.WriteByte(0);
     stream.WriteByte(0);
     ZDeflaterOutputStream zip = new ZDeflaterOutputStream(stream, 5);
     zip.Write(data, 0, data.Length);
     zip.Finish();
     WriteChunk(iCCP, stream.ToArray());
 }
Ejemplo n.º 3
0
 public void WriteData(byte[] data, int stride)
 {
     MemoryStream stream = new MemoryStream();
     ZDeflaterOutputStream zip = new ZDeflaterOutputStream(stream, 5);
     for (int k = 0; k < data.Length; k += stride) {
         zip.WriteByte(0);
         zip.Write(data, k, stride);
     }
     zip.Finish();
     WriteChunk(IDAT, stream.ToArray());
 }
Ejemplo n.º 4
0
 public void WriteData(byte[] data, int stride)
 {
     MemoryStream stream = new MemoryStream();
     ZDeflaterOutputStream zip = new ZDeflaterOutputStream(stream, 5);
     int k;
     for (k = 0; k < data.Length - stride; k += stride) {
         zip.WriteByte(0);
         zip.Write(data, k, stride);
     }
     int remaining = data.Length - k;
     if (remaining > 0){
         zip.WriteByte(0);
         zip.Write(data, k, remaining);
     }
     zip.Finish();
     WriteChunk(IDAT, stream.ToArray());
 }
Ejemplo n.º 5
0
 // methods
 /**
  * Compresses the stream.
  *
  * @throws PdfException if a filter is allready defined
  */
 public void FlateCompress()
 {
     if (!Document.Compress)
         return;
     // check if the flateCompress-method has allready been
     if (compressed) {
         return;
     }
     if (inputStream != null) {
         compressed = true;
         return;
     }
     // check if a filter allready exists
     PdfObject filter = PdfReader.GetPdfObject(Get(PdfName.FILTER));
     if (filter != null) {
         if (filter.IsName()) {
             if (PdfName.FLATEDECODE.Equals(filter))
                 return;
         }
         else if (filter.IsArray()) {
             if (((PdfArray) filter).Contains(PdfName.FLATEDECODE))
                 return;
         }
         else {
             throw new PdfException("Stream could not be compressed: filter is not a name or array.");
         }
     }
     // compress
     MemoryStream stream = new MemoryStream();
     ZDeflaterOutputStream zip = new ZDeflaterOutputStream(stream);
     if (streamBytes != null)
         streamBytes.WriteTo(zip);
     else
         zip.Write(bytes, 0, bytes.Length);
     //zip.Close();
     zip.Finish();
     // update the object
     streamBytes = stream;
     bytes = null;
     Put(PdfName.LENGTH, new PdfNumber(streamBytes.Length));
     if (filter == null) {
         Put(PdfName.FILTER, PdfName.FLATEDECODE);
     }
     else {
         PdfArray filters = new PdfArray(filter);
         filters.Add(PdfName.FLATEDECODE);
         Put(PdfName.FILTER, filters);
     }
     compressed = true;
 }