예제 #1
0
        public virtual void LayersRadioGroup()
        {
            String      outPdf     = destinationFolder + "layersRadioGroup.pdf";
            String      cmpPdf     = sourceFolder + "cmp_layersRadioGroup.pdf";
            PdfDocument pdfDoc     = new PdfDocument(new PdfWriter(outPdf));
            PdfFont     font       = PdfFontFactory.CreateFont();
            PdfLayer    radiogroup = PdfLayer.CreateTitle("Radio group", pdfDoc);
            PdfLayer    radio1     = new PdfLayer("Radiogroup: layer 1", pdfDoc);

            radio1.SetOn(true);
            PdfLayer radio2 = new PdfLayer("Radiogroup: layer 2", pdfDoc);

            radio2.SetOn(false);
            PdfLayer radio3 = new PdfLayer("Radiogroup: layer 3", pdfDoc);

            radio3.SetOn(false);
            radiogroup.AddChild(radio1);
            radiogroup.AddChild(radio2);
            radiogroup.AddChild(radio3);
            IList <PdfLayer> options = new List <PdfLayer>();

            options.Add(radio1);
            options.Add(radio2);
            options.Add(radio3);
            PdfLayer.AddOCGRadioGroup(pdfDoc, options);
            PdfCanvas canvas = new PdfCanvas(pdfDoc.AddNewPage());

            canvas.SetFontAndSize(font, 12);
            PdfLayerTestUtils.AddTextInsideLayer(radio1, canvas, "layer option 1", 50, 600);
            PdfLayerTestUtils.AddTextInsideLayer(radio2, canvas, "layer option 2", 50, 575);
            PdfLayerTestUtils.AddTextInsideLayer(radio3, canvas, "layer option 3", 50, 550);
            pdfDoc.Close();
            PdfLayerTestUtils.CompareLayers(outPdf, cmpPdf);
        }
예제 #2
0
 /// <summary>Reads the /Order in the /D entry and initialized the parent-child hierarchy.</summary>
 private void ReadOrderFromDictionary(PdfLayer parent, PdfArray orderArray, IDictionary <PdfIndirectReference
                                                                                         , PdfLayer> layerMap)
 {
     for (int i = 0; i < orderArray.Size(); i++)
     {
         PdfObject item = orderArray.Get(i);
         if (item.GetObjectType() == PdfObject.DICTIONARY)
         {
             PdfLayer layer = layerMap.Get(item.GetIndirectReference());
             if (layer != null)
             {
                 layers.Add(layer);
                 layer.onPanel = true;
                 if (parent != null)
                 {
                     parent.AddChild(layer);
                 }
                 if (i + 1 < orderArray.Size() && orderArray.Get(i + 1).GetObjectType() == PdfObject.ARRAY)
                 {
                     PdfArray nextArray = orderArray.GetAsArray(i + 1);
                     if (nextArray.Size() > 0 && nextArray.Get(0).GetObjectType() != PdfObject.STRING)
                     {
                         ReadOrderFromDictionary(layer, orderArray.GetAsArray(i + 1), layerMap);
                         i++;
                     }
                 }
             }
         }
         else
         {
             if (item.GetObjectType() == PdfObject.ARRAY)
             {
                 PdfArray subArray = (PdfArray)item;
                 if (subArray.IsEmpty())
                 {
                     continue;
                 }
                 PdfObject firstObj = subArray.Get(0);
                 if (firstObj.GetObjectType() == PdfObject.STRING)
                 {
                     PdfLayer titleLayer = PdfLayer.CreateTitleSilent(((PdfString)firstObj).ToUnicodeString(), GetDocument());
                     titleLayer.onPanel = true;
                     layers.Add(titleLayer);
                     if (parent != null)
                     {
                         parent.AddChild(titleLayer);
                     }
                     ReadOrderFromDictionary(titleLayer, new PdfArray(subArray.SubList(1, subArray.Size())), layerMap);
                 }
                 else
                 {
                     ReadOrderFromDictionary(parent, subArray, layerMap);
                 }
             }
         }
     }
 }
예제 #3
0
        public virtual void LayerGroup()
        {
            String      outPdf = destinationFolder + "layerGroup.pdf";
            String      cmpPdf = sourceFolder + "cmp_layerGroup.pdf";
            PdfDocument pdfDoc = new PdfDocument(new PdfWriter(outPdf));
            PdfFont     font   = PdfFontFactory.CreateFont();
            PdfLayer    group  = PdfLayer.CreateTitle("Grouped layers", pdfDoc);
            PdfLayer    layer1 = new PdfLayer("Group: layer 1", pdfDoc);
            PdfLayer    layer2 = new PdfLayer("Group: layer 2", pdfDoc);

            group.AddChild(layer1);
            group.AddChild(layer2);
            PdfCanvas canvas = new PdfCanvas(pdfDoc.AddNewPage());

            canvas.SetFontAndSize(font, 12);
            PdfLayerTestUtils.AddTextInsideLayer(layer1, canvas, "layer 1 in the group", 50, 700);
            PdfLayerTestUtils.AddTextInsideLayer(layer2, canvas, "layer 2 in the group", 50, 675);
            pdfDoc.Close();
            PdfLayerTestUtils.CompareLayers(outPdf, cmpPdf);
        }
예제 #4
0
        public virtual void NestedLayers()
        {
            String      outPdf   = destinationFolder + "nestedLayers.pdf";
            String      cmpPdf   = sourceFolder + "cmp_nestedLayers.pdf";
            PdfDocument pdfDoc   = new PdfDocument(new PdfWriter(outPdf));
            PdfFont     font     = PdfFontFactory.CreateFont();
            PdfLayer    nested   = new PdfLayer("Parent layer", pdfDoc);
            PdfLayer    nested_1 = new PdfLayer("Nested layer 1", pdfDoc);
            PdfLayer    nested_2 = new PdfLayer("Nested layer 2", pdfDoc);

            nested.AddChild(nested_1);
            nested.AddChild(nested_2);
            PdfCanvas canvas = new PdfCanvas(pdfDoc.AddNewPage());

            canvas.SetFontAndSize(font, 12);
            PdfLayerTestUtils.AddTextInsideLayer(nested, canvas, "Parent layer text", 50, 755);
            PdfLayerTestUtils.AddTextInsideLayer(nested_1, canvas, "Nested layer 1 text", 100, 700);
            PdfLayerTestUtils.AddTextInsideLayer(nested_2, canvas, "Nested layers 2 text", 100, 650);
            pdfDoc.Close();
            PdfLayerTestUtils.CompareLayers(outPdf, cmpPdf);
        }