Package org.pdfclown.objects

Examples of org.pdfclown.objects.PdfStream


    Serializes the contents into the content stream.
  */
  public void flush(
    )
  {
    PdfStream stream;
    PdfDataObject baseDataObject = getBaseDataObject();
    // Are contents just a single stream object?
    if(baseDataObject instanceof PdfStream) // Single stream.
    {stream = (PdfStream)baseDataObject;}
    else // Array of streams.
    {
      PdfArray streams = (PdfArray)baseDataObject;
      // No stream available?
      if(streams.size() == 0) // No stream.
      {
        // Add first stream!
        stream = new PdfStream();
        streams.add( // Inserts the new stream into the content stream.
          getFile().register(stream) // Inserts the new stream into the file.
          );
      }
      else // Streams exist.
      {
        // Eliminating exceeding streams...
        /*
          NOTE: Applications that consume or produce PDF files are not required to preserve
          the existing structure of the Contents array [PDF:1.6:3.6.2].
        */
        while(streams.size() > 1)
        {
          getFile().unregister( // Removes the exceeding stream from the file.
            (PdfReference)streams.remove(1) // Removes the exceeding stream from the content stream.
            );
        }

        PdfReference streamReference = (PdfReference)streams.get(0);
        File.update(streamReference); // Updates the existing stream into the file.
        stream = (PdfStream)streamReference.getDataObject();
      }
    }

    // Get the stream buffer!
    IBuffer buffer = stream.getBody();
    // Delete old contents from the stream buffer!
    buffer.setLength(0);
    // Serializing the new contents into the stream buffer...
    for(ContentObject item : items)
    {item.writeTo(buffer);}
View Full Code Here


  // <private>
  private PrimitiveComposer createFilter(
    )
  {
    PdfReference reference = page.getFile().register(new PdfStream());

    return new PrimitiveComposer(
      new ContentScanner(
        new Contents(
          reference,
View Full Code Here

        },
        new PdfDirectObject[]
        {
          PdfName.Page,
          context.getFile().register(
            new PdfStream()
            )
        }
        )
      );
  }
View Full Code Here

        new PdfDirectObject[]
        {
          PdfName.Page,
          new Rectangle(0,0,size.getWidth(),size.getHeight()).getBaseDataObject(),
          context.getFile().register(
            new PdfStream()
            ),
          resources.getBaseObject()
        }
        )
      );
View Full Code Here

    )
  {
    File contextFile = context.getFile();

    FormXObject form = new FormXObject(context);
    PdfStream formStream = form.getBaseDataObject();

    // Header.
    {
      PdfDictionary formHeader = formStream.getHeader();
      // Bounding box.
      formHeader.put(
        PdfName.BBox,
        (PdfDirectObject)getInheritableAttribute(PdfName.MediaBox).clone(contextFile)
        );
      // Resources.
      {
        PdfDirectObject resourcesObject = getInheritableAttribute(PdfName.Resources);
        formHeader.put(
          PdfName.Resources,
          // Same document?
          /* NOTE: Try to reuse the resource dictionary whenever possible. */
          (context.equals(getDocument()) ?
            resourcesObject
            : (PdfDirectObject)resourcesObject.clone(contextFile))
          );
      }
    }

    // Body (contents).
    {
      IBuffer formBody = formStream.getBody();
      PdfDataObject contentsDataObject = getBaseDataObject().resolve(PdfName.Contents);
      if(contentsDataObject instanceof PdfStream)
      {formBody.append(((PdfStream)contentsDataObject).getBody());}
      else
      {
View Full Code Here

    IInputStream stream
    )
  {
    super(
      context.getFile(),
      new PdfStream(
        new PdfDictionary(
          new PdfName[]{PdfName.Type},
          new PdfDirectObject[]{PdfName.Sound}
          )
        )
View Full Code Here

    OpenFontParser parser;
    {
      PdfDictionary descriptor = getDescriptor();
      if(descriptor.containsKey(PdfName.FontFile2)) // Embedded TrueType font file (without 'glyf' table).
      {
        PdfStream fontFileStream = (PdfStream)descriptor.resolve(PdfName.FontFile2);
        parser = new OpenFontParser(fontFileStream.getBody());
      }
      else if(descriptor.containsKey(PdfName.FontFile3))
      {
        PdfStream fontFileStream = (PdfStream)descriptor.resolve(PdfName.FontFile3);
        PdfName fontFileSubtype = (PdfName)fontFileStream.getHeader().get(PdfName.Subtype);
        if(fontFileSubtype.equals(PdfName.OpenType)) // Embedded OpenFont/TrueType font file (with 'glyf' table).
        {parser = new OpenFontParser(fontFileStream.getBody());}
        else // Unknown.
          throw new UnsupportedOperationException("Unknown embedded font file format: " + fontFileSubtype);
      }
      else
      {parser = null;}
View Full Code Here

TOP

Related Classes of org.pdfclown.objects.PdfStream

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.