Inheritance: PdfDictionary
Example #1
0
 /**
  * Adds some <CODE>PdfContents</CODE> to this Writer.
  * <P>
  * The document has to be open before you can begin to add content
  * to the body of the document.
  *
  * @return a <CODE>PdfIndirectReference</CODE>
  * @param page the <CODE>PdfPage</CODE> to add
  * @param contents the <CODE>PdfContents</CODE> of the page
  * @throws PdfException on error
  */
  internal virtual PdfIndirectReference Add(PdfPage page, PdfContents contents) {
      if (!open) {
          throw new PdfException(MessageLocalization.GetComposedMessage("the.document.is.not.open"));
      }
      PdfIndirectObject objecta;
      objecta = AddToBody(contents);
      page.Add(objecta.IndirectReference);
      if (group != null) {
          page.Put(PdfName.GROUP, group);
          group = null;
      }
      else if (rgbTransparencyBlending) {
          PdfDictionary pp = new PdfDictionary();
          pp.Put(PdfName.TYPE, PdfName.GROUP);
          pp.Put(PdfName.S, PdfName.TRANSPARENCY);
          pp.Put(PdfName.CS, PdfName.DEVICERGB);
          page.Put(PdfName.GROUP, pp);
      }
      root.AddPage(page);
      currentPageNumber++;
      return null;
  }
Example #2
0
 internal override PdfIndirectReference Add(PdfPage page, PdfContents contents)
 {
     return null;
 }
        /**
        * Makes a new page and sends it to the <CODE>PdfWriter</CODE>.
        *
        * @return a <CODE>bool</CODE>
        * @throws DocumentException on error
        */
        public override bool NewPage() {
            FlushFloatingElements();

            lastElementType = -1;
            if (PageEmpty) {
                SetNewPageSizeAndMargins();
                return false;
            }
            if (!open || close) {
                throw new Exception(MessageLocalization.GetComposedMessage("the.document.is.not.open"));
            }
            IPdfPageEvent pageEvent = writer.PageEvent;
            if (pageEvent != null)
                pageEvent.OnEndPage(writer, this);
            
            //Added to inform any listeners that we are moving to a new page (added by David Freels)
            base.NewPage();
            
            // the following 2 lines were added by Pelikan Stephan
            indentation.imageIndentLeft = 0;
            indentation.imageIndentRight = 0;
            
            // we flush the arraylist with recently written lines
            FlushLines();
            // we prepare the elements of the page dictionary
            
            // [U1] page size and rotation
            int rotation = pageSize.Rotation;
            
            // [C10]
            if (writer.IsPdfIso()) {
                if (thisBoxSize.ContainsKey("art") && thisBoxSize.ContainsKey("trim"))
                    throw new PdfXConformanceException(MessageLocalization.GetComposedMessage("only.one.of.artbox.or.trimbox.can.exist.in.the.page"));
                if (!thisBoxSize.ContainsKey("art") && !thisBoxSize.ContainsKey("trim")) {
                    if (thisBoxSize.ContainsKey("crop"))
                        thisBoxSize["trim"] = thisBoxSize["crop"];
                    else
                        thisBoxSize["trim"] = new PdfRectangle(pageSize, pageSize.Rotation);
                }
            }
            
            // [M1]
            pageResources.AddDefaultColorDiff(writer.DefaultColorspace);        
            if (writer.RgbTransparencyBlending) {
                PdfDictionary dcs = new PdfDictionary();
                dcs.Put(PdfName.CS, PdfName.DEVICERGB);
                pageResources.AddDefaultColorDiff(dcs);
            }
            PdfDictionary resources = pageResources.Resources;
            
            // we create the page dictionary
            
            PdfPage page = new PdfPage(new PdfRectangle(pageSize, rotation), thisBoxSize, resources, rotation);
            if (IsTagged(writer)) {
                page.Put(PdfName.TABS, PdfName.S);
            } else {
                page.Put(PdfName.TABS, writer.Tabs);
            }
            page.Merge(writer.PageDictEntries);
            writer.ResetPageDictEntries();

            // we complete the page dictionary
            
        	// [U3] page actions: additional actions
            if (pageAA != null) {
                page.Put(PdfName.AA, writer.AddToBody(pageAA).IndirectReference);
                pageAA = null;
            }
            
            // [C5] and [C8] we add the annotations
            if (annotationsImp.HasUnusedAnnotations()) {
                PdfArray array = annotationsImp.RotateAnnotations(writer, pageSize);
                if (array.Size != 0)
                    page.Put(PdfName.ANNOTS, array);
            }
            
            // [F12] we add tag info
            if (IsTagged(writer))
                page.Put(PdfName.STRUCTPARENTS, new PdfNumber(GetStructParentIndex(writer.CurrentPage)));

             if (text.Size > textEmptySize || IsTagged(writer))
                text.EndText();
            else
                text = null;
             IList<IAccessibleElement> mcBlocks = null;
             if (IsTagged(writer)) {
                 mcBlocks = writer.DirectContent.SaveMCBlocks();
             }
            writer.Add(page, new PdfContents(writer.DirectContentUnder, graphics, !IsTagged(writer) ? text : null, writer.DirectContent, pageSize));
            // we initialize the new page
            InitPage();
            if (IsTagged(writer)) {
                writer.DirectContentUnder.RestoreMCBlocks(mcBlocks);
            }
            return true;
        }
Example #4
0
 /**
  * Adds a blank page.
  * @param	rect The page dimension
  * @param	rotation The rotation angle in degrees
  * @since	2.1.5
  * @throws DocumentException
  */
 public void AddPage(Rectangle rect, int rotation) {
     if (mergeFields && !mergeFieldsInternalCall) {
         throw new ArgumentException(MessageLocalization.GetComposedMessage("1.method.cannot.be.used.in.mergeFields.mode.please.use.addDocument", "addPage"));
     }
     PdfRectangle mediabox = new PdfRectangle(rect, rotation);
     PageResources resources = new PageResources();
     PdfPage page = new PdfPage(mediabox, new Dictionary<String, PdfRectangle>(), resources.Resources, 0);
     page.Put(PdfName.TABS, Tabs);
     root.AddPage(page);
     ++currentPageNumber;
 }
Example #5
0
 /**
  * Adds a blank page.
  * @param	rect The page dimension
  * @param	rotation The rotation angle in degrees
  * @since	2.1.5
  */
 public void AddPage(Rectangle rect, int rotation)
 {
     PdfRectangle mediabox = new PdfRectangle(rect, rotation);
     PageResources resources = new PageResources();
     PdfPage page = new PdfPage(mediabox, new Dictionary<String, PdfRectangle>(), resources.Resources, 0);
     page.Put(PdfName.TABS, Tabs);
     root.AddPage(page);
     ++currentPageNumber;
 }
Example #6
0
 /**
 * Adds some <CODE>PdfContents</CODE> to this Writer.
 * <P>
 * The document has to be open before you can begin to add content
 * to the body of the document.
 *
 * @return a <CODE>PdfIndirectReference</CODE>
 * @param page the <CODE>PdfPage</CODE> to add
 * @param contents the <CODE>PdfContents</CODE> of the page
 * @throws PdfException on error
 */
 internal virtual PdfIndirectReference Add(PdfPage page, PdfContents contents)
 {
     if (!open) {
         throw new PdfException("The document isn't open.");
     }
     PdfIndirectObject objecta;
     objecta = AddToBody(contents);
     page.Add(objecta.IndirectReference);
     if (group != null) {
         page.Put(PdfName.GROUP, group);
         group = null;
     }
     root.AddPage(page);
     currentPageNumber++;
     return null;
 }
Example #7
0
        /**
        * Makes a new page and sends it to the <CODE>PdfWriter</CODE>.
        *
        * @return a <CODE>bool</CODE>
        * @throws DocumentException on error
        */
        public override bool NewPage() {
            lastElementType = -1;
            if (PageEmpty) {
                SetNewPageSizeAndMargins();
                return false;
            }
            if (!open || close) {
                throw new Exception(MessageLocalization.GetComposedMessage("the.document.is.not.open"));
            }
            IPdfPageEvent pageEvent = writer.PageEvent;
            if (pageEvent != null)
                pageEvent.OnEndPage(writer, this);
            
            //Added to inform any listeners that we are moving to a new page (added by David Freels)
            base.NewPage();
            
            // the following 2 lines were added by Pelikan Stephan
            indentation.imageIndentLeft = 0;
            indentation.imageIndentRight = 0;
            
            // we flush the arraylist with recently written lines
            FlushLines();
            // we prepare the elements of the page dictionary
            
            // [U1] page size and rotation
            int rotation = pageSize.Rotation;
            
            // [C10]
            if (writer.IsPdfX()) {
                if (thisBoxSize.ContainsKey("art") && thisBoxSize.ContainsKey("trim"))
                    throw new PdfXConformanceException(MessageLocalization.GetComposedMessage("only.one.of.artbox.or.trimbox.can.exist.in.the.page"));
                if (!thisBoxSize.ContainsKey("art") && !thisBoxSize.ContainsKey("trim")) {
                    if (thisBoxSize.ContainsKey("crop"))
                        thisBoxSize["trim"] = thisBoxSize["crop"];
                    else
                        thisBoxSize["trim"] = new PdfRectangle(pageSize, pageSize.Rotation);
                }
            }
            
            // [M1]
            pageResources.AddDefaultColorDiff(writer.DefaultColorspace);        
            if (writer.RgbTransparencyBlending) {
                PdfDictionary dcs = new PdfDictionary();
                dcs.Put(PdfName.CS, PdfName.DEVICERGB);
                pageResources.AddDefaultColorDiff(dcs);
            }
            PdfDictionary resources = pageResources.Resources;
            
            // we create the page dictionary
            
            PdfPage page = new PdfPage(new PdfRectangle(pageSize, rotation), thisBoxSize, resources, rotation);
            page.Put(PdfName.TABS, writer.Tabs);

            // we complete the page dictionary
            
            // [C9] if there is XMP data to add: add it
            if (xmpMetadata != null) {
                PdfStream xmp = new PdfStream(xmpMetadata);
                xmp.Put(PdfName.TYPE, PdfName.METADATA);
                xmp.Put(PdfName.SUBTYPE, PdfName.XML);
                PdfEncryption crypto = writer.Encryption;
                if (crypto != null && !crypto.IsMetadataEncrypted()) {
                    PdfArray ar = new PdfArray();
                    ar.Add(PdfName.CRYPT);
                    xmp.Put(PdfName.FILTER, ar);
                }
                page.Put(PdfName.METADATA, writer.AddToBody(xmp).IndirectReference);
            }
            
            // [U3] page actions: transition, duration, additional actions
            if (this.transition!=null) {
                page.Put(PdfName.TRANS, this.transition.TransitionDictionary);
                transition = null;
            }
            if (this.duration>0) {
                page.Put(PdfName.DUR,new PdfNumber(this.duration));
                duration = 0;
            }
            if (pageAA != null) {
                page.Put(PdfName.AA, writer.AddToBody(pageAA).IndirectReference);
                pageAA = null;
            }
            
            // [U4] we add the thumbs
            if (thumb != null) {
                page.Put(PdfName.THUMB, thumb);
                thumb = null;
            }
            
            // [U8] we check if the userunit is defined
            if (writer.Userunit > 0f) {
                page.Put(PdfName.USERUNIT, new PdfNumber(writer.Userunit));
            }
            
            // [C5] and [C8] we add the annotations
            if (annotationsImp.HasUnusedAnnotations()) {
                PdfArray array = annotationsImp.RotateAnnotations(writer, pageSize);
                if (array.Size != 0)
                    page.Put(PdfName.ANNOTS, array);
            }
            
            // [F12] we add tag info
            if (writer.IsTagged())
                 page.Put(PdfName.STRUCTPARENTS, new PdfNumber(writer.CurrentPageNumber - 1));
            
            if (text.Size > textEmptySize)
                text.EndText();
            else
                text = null;
            writer.Add(page, new PdfContents(writer.DirectContentUnder, graphics, text, writer.DirectContent, pageSize));
            // we initialize the new page
            InitPage();
            return true;
        }
Example #8
0
        public IList<IAccessibleElement> EndPage() {
            if (PageEmpty) {
                return null;
            }

            IList<IAccessibleElement> savedMcBlocks = null;

            FlushFloatingElements();
            lastElementType = -1;

            IPdfPageEvent pageEvent = writer.PageEvent;
            if (pageEvent != null)
                pageEvent.OnEndPage(writer, this);

            // we flush the arraylist with recently written lines
            FlushLines();
            // we prepare the elements of the page dictionary

            // [U1] page size and rotation
            int rotation = pageSize.Rotation;

            // [C10]
            if (writer.IsPdfIso()) {
                if (thisBoxSize.ContainsKey("art") && thisBoxSize.ContainsKey("trim"))
                    throw new PdfXConformanceException(MessageLocalization.GetComposedMessage("only.one.of.artbox.or.trimbox.can.exist.in.the.page"));
                if (!thisBoxSize.ContainsKey("art") && !thisBoxSize.ContainsKey("trim")) {
                    if (thisBoxSize.ContainsKey("crop"))
                        thisBoxSize["trim"] = thisBoxSize["crop"];
                    else
                        thisBoxSize["trim"] = new PdfRectangle(pageSize, pageSize.Rotation);
                }
            }

            // [M1]
            pageResources.AddDefaultColorDiff(writer.DefaultColorspace);
            if (writer.RgbTransparencyBlending) {
                PdfDictionary dcs = new PdfDictionary();
                dcs.Put(PdfName.CS, PdfName.DEVICERGB);
                pageResources.AddDefaultColorDiff(dcs);
            }
            PdfDictionary resources = pageResources.Resources;

            // we create the page dictionary

            PdfPage page = new PdfPage(new PdfRectangle(pageSize, rotation), thisBoxSize, resources, rotation);
            if (IsTagged(writer)) {
                page.Put(PdfName.TABS, PdfName.S);
            } else {
                page.Put(PdfName.TABS, writer.Tabs);
            }
            page.Merge(writer.PageDictEntries);
            writer.ResetPageDictEntries();

            // we complete the page dictionary

            // [U3] page actions: additional actions
            if (pageAA != null) {
                page.Put(PdfName.AA, writer.AddToBody(pageAA).IndirectReference);
                pageAA = null;
            }

            // [C5] and [C8] we add the annotations
            if (annotationsImp.HasUnusedAnnotations()) {
                PdfArray array = annotationsImp.RotateAnnotations(writer, pageSize);
                if (array.Size != 0)
                    page.Put(PdfName.ANNOTS, array);
            }

            // [F12] we add tag info
            if (IsTagged(writer))
                page.Put(PdfName.STRUCTPARENTS, new PdfNumber(GetStructParentIndex(writer.CurrentPage)));

            if (text.Size > textEmptySize || IsTagged(writer))
                text.EndText();
            else
                text = null;
            if (IsTagged(writer)) {
                savedMcBlocks = writer.DirectContent.SaveMCBlocks();
            }
            writer.Add(page, new PdfContents(writer.DirectContentUnder, graphics, !IsTagged(writer) ? text : null, writer.DirectContent, pageSize));

            annotationsImp.ResetAnnotations();
            writer.ResetContent();

            return savedMcBlocks;
        }
Example #9
0
        /**
        * Makes a new page and sends it to the <CODE>PdfWriter</CODE>.
        *
        * @return a <CODE>bool</CODE>
        * @throws DocumentException on error
        */
        public override bool NewPage()
        {
            lastElementType = -1;
            isNewpage = true;
            if (writer == null || (writer.DirectContent.Size == 0 && writer.DirectContentUnder.Size == 0 && (pageEmpty || writer.IsPaused()))) {
                return false;
            }
            if (!open || close) {
                throw new Exception("The document isn't open.");
            }
            IPdfPageEvent pageEvent = writer.PageEvent;
            if (pageEvent != null)
                pageEvent.OnEndPage(writer, this);

            //Added to inform any listeners that we are moving to a new page (added by David Freels)
            base.NewPage();

            // the following 2 lines were added by Pelikan Stephan
            imageIndentLeft = 0;
            imageIndentRight = 0;

            // we flush the arraylist with recently written lines
            FlushLines();
            // we prepare the elements of the page dictionary

            // [U1] page size and rotation
            int rotation = pageSize.Rotation;

            // [C10]
            if (writer.IsPdfX()) {
                if (thisBoxSize.ContainsKey("art") && thisBoxSize.ContainsKey("trim"))
                    throw new PdfXConformanceException("Only one of ArtBox or TrimBox can exist in the page.");
                if (!thisBoxSize.ContainsKey("art") && !thisBoxSize.ContainsKey("trim")) {
                    if (thisBoxSize.ContainsKey("crop"))
                        thisBoxSize["trim"] = thisBoxSize["crop"];
                    else
                        thisBoxSize["trim"] = new PdfRectangle(pageSize, pageSize.Rotation);
                }
            }

            // [M1]
            pageResources.AddDefaultColorDiff(writer.DefaultColorspace);
            PdfDictionary resources = pageResources.Resources;

            // we create the page dictionary

            PdfPage page = new PdfPage(new PdfRectangle(pageSize, rotation), thisBoxSize, resources, rotation);

            // we complete the page dictionary

            // [U3] page actions: transition, duration, additional actions
            if (this.transition!=null) {
                page.Put(PdfName.TRANS, this.transition.TransitionDictionary);
                transition = null;
            }
            if (this.duration>0) {
                page.Put(PdfName.DUR,new PdfNumber(this.duration));
                duration = 0;
            }
            if (pageAA != null) {
                page.Put(PdfName.AA, writer.AddToBody(pageAA).IndirectReference);
                pageAA = null;
            }

            // [U4] we add the thumbs
            if (thumb != null) {
                page.Put(PdfName.THUMB, thumb);
                thumb = null;
            }

            // [U8] we check if the userunit is defined
            if (writer.Userunit > 0f) {
                page.Put(PdfName.USERUNIT, new PdfNumber(writer.Userunit));
            }

            // [C5] and [C8] we add the annotations
            if (annotationsImp.HasUnusedAnnotations()) {
                PdfArray array = annotationsImp.RotateAnnotations(writer, pageSize);
                if (array.Size != 0)
                    page.Put(PdfName.ANNOTS, array);
            }

            // [F12] we add tag info
            if (writer.IsTagged())
                 page.Put(PdfName.STRUCTPARENTS, new PdfNumber(writer.CurrentPageNumber - 1));

            if (text.Size > textEmptySize)
                text.EndText();
            else
                text = null;
            writer.Add(page, new PdfContents(writer.DirectContentUnder, graphics, text, writer.DirectContent, pageSize));
            // we initialize the new page
            InitPage();
            isNewpage = false;
            return true;
        }
Example #10
0
 internal override PdfIndirectReference Add(PdfPage page, PdfContents contents)
 {
     return(null);
 }