Ejemplo n.º 1
0
        public virtual void CollapsingMarginsTest01()
        {
            String      outFileName = destinationFolder + "collapsingMarginsTest01.pdf";
            String      cmpFileName = sourceFolder + "cmp_collapsingMarginsTest01.pdf";
            PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName));

            DrawPageBorders(pdfDocument, 4);
            Document doc = new Document(pdfDocument);

            doc.SetProperty(Property.COLLAPSING_MARGINS, true);
            doc.Add(new Paragraph("marker text").SetMargin(0));
            Paragraph p = new Paragraph(TEXT_BYRON);

            for (int i = 0; i < 5; i++)
            {
                p.Add(TEXT_BYRON);
            }
            Div div1 = new Div();
            Div div2 = new Div();

            div1.Add(p).SetBackgroundColor(new DeviceRgb(65, 151, 29));
            div2.Add(p).SetBackgroundColor(new DeviceRgb(209, 247, 29));
            div1.SetMarginBottom(20);
            div2.SetMarginTop(150);
            div2.SetMarginBottom(150);
            Div div = new Div().SetMarginTop(20).SetMarginBottom(10).SetBackgroundColor(new DeviceRgb(78, 151, 205));

            div.Add(div1);
            div.Add(div2);
            doc.Add(div);
            doc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             , "diff"));
        }
        public virtual void FirstLineIndentTest01()
        {
            String      outFileName = destinationFolder + "firstLineIndentTest01.pdf";
            String      cmpFileName = sourceFolder + "cmp_firstLineIndentTest01.pdf";
            PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName));
            Document    document    = new Document(pdfDocument);

            document.SetProperty(Property.FIRST_LINE_INDENT, 25);
            document.Add(new Paragraph("Portable Document Format (PDF) is a file format used to present documents in a manner "
                                       + "independent of application software, hardware, and operating systems.[2] Each PDF file encapsulates a complete "
                                       + "description of a fixed-layout flat document, including the text, fonts, graphics, and other information needed to "
                                       + "display it. In 1991, Adobe Systems co-founder John Warnock outlined a system called \"Camelot\"[3] that evolved into PDF."
                                       ));
            document.Add(new Paragraph("While Adobe Systems made the PDF specification available free of charge in 1993, PDF was a proprietary format, controlled "
                                       + "by Adobe, until it was officially released as an open standard on July 1, 2008, and published by the International Organization for"
                                       + " Standardization as ISO 32000-1:2008,[4][5] at which time control of the specification passed to an ISO Committee of volunteer industry "
                                       + "experts. In 2008, Adobe published a Public Patent License to ISO 32000-1 granting royalty-free rights for all patents owned by Adobe that "
                                       + "are necessary to make, use, sell and distribute PDF compliant implementations.[6] However, there are still some proprietary technologies"
                                       + " with published specification defined only by Adobe, such as Adobe XML Forms Architecture, and JavaScript for Acrobat, which are referenced "
                                       + "by ISO 32000-1 as normative and indispensable for the application of ISO 32000-1 specification.[7][8][9][10][11] The ISO committee is actively"
                                       + " standardizing many of these as part of ISO 32000-2.").SetFirstLineIndent(50));
            document.Add(new AreaBreak());
            document.Add(new Paragraph("During Harry's fourth year of school (detailed in Harry Potter and the Goblet of Fire), Harry is unwillingly entered as a participant in the Triwizard Tournament, a dangerous contest where Harry must compete against a witch and a wizard \"champion\" from visiting schools as well as another Hogwarts student, causing Harry's friends to distance themselves from him.[18] Harry is guided through the tournament by their new Defence Against the Dark Arts professor, Alastor \"Mad-Eye\" Moody, who turns out to be an impostor\u2014one of Voldemort's supporters named Barty Crouch, Jr. in disguise. The point at which the mystery is unravelled marks the series' shift from foreboding and uncertainty into open conflict. Voldemort's plan to have Crouch use the tournament to bring Harry to Voldemort succeeds. Although Harry manages to escape, Cedric Diggory, the other Hogwarts champion in the tournament, is killed by Peter Pettigrew and Voldemort re-enters the wizarding world with a physical body.\n"
                                       + "\n" + "In the fifth book, Harry Potter and the Order of the Phoenix, Harry must confront the newly resurfaced Voldemort. In response to Voldemort's reappearance, Dumbledore re-activates the Order of the Phoenix, a secret society which works from Sirius Black's dark family home to defeat Voldemort's minions and protect Voldemort's targets, especially Harry. Despite Harry's description of Voldemort's recent activities, the Ministry of Magic and many others in the magical world refuse to believe that Voldemort has returned.[19] In an attempt to counter and eventually discredit Dumbledore, who along with Harry is the most prominent voice in the wizarding world attempting to warn of Voldemort's return, the Ministry appoints Dolores Umbridge as the High Inquisitor of Hogwarts and the new Defence Against the Dark Arts teacher. She transforms the school into a dictatorial regime and refuses to allow the students to learn ways to defend themselves against dark magic.[19]\n"
                                       + "\n" + "With Ron and Hermione's suggestion, Harry reluctantly forms \"Dumbledore's Army,\" a secret study group aimed to teach his classmates the higher-level skills of Defence Against the Dark Arts that he has learned from his previous encounters with Dark wizards. An important prophecy concerning Harry and Lord Voldemort is revealed,[20] and Harry discovers that he and Voldemort have a painful connection, allowing Harry to view some of Voldemort's actions telepathically. In the novel's climax, Harry and his friends face off against Voldemort's Death Eaters at the Ministry of Magic. Although the timely arrival of members of the Order of the Phoenix saves the children's lives, Sirius Black is killed in the conflict.\n"
                                       + "\n" + "In the sixth book, Harry Potter and the Half-Blood Prince, Voldemort begins waging open warfare. Harry and his friends are relatively protected from that danger at Hogwarts. They are subject to all the difficulties of adolescence\u2014Harry eventually begins dating Ginny, Ron establishes a strong infatuation with fellow Hogwarts student Lavender Brown, and Hermione starts recognising her loving feelings for Ron. Near the beginning of the novel, lacking his own book, Harry is given an old potions textbook filled with many annotations and recommendations signed by a mysterious writer; \"the Half-Blood Prince.\" This book is a source of scholastic success and great recognition from their new potions master, Horace Slughorn, but because of the potency of the spells that are written in it, becomes a source of concern. Harry takes private lessons with Dumbledore, who shows him various memories concerning the early life of Voldemort in a device called a Pensieve. These reveal that in order to preserve his life, Voldemort has split his soul into pieces, creating a series of horcruxes - evil enchanted items hidden in various locations, one of which was the diary destroyed in the second book.[21] Harry's snobbish adversary, Draco Malfoy, attempts to attack Dumbledore, and the book culminates in the killing of Dumbledore by Professor Snape, the titular Half-Blood Prince.\n"
                                       + "\n" + "Harry Potter and the Deathly Hallows, the last book in the series, begins directly after the events of the sixth book. Lord Voldemort has completed his ascension to power and gains control of the Ministry of Magic. Harry, Ron and Hermione drop out of school so that they can find and destroy Voldemort's remaining horcruxes. To ensure their own safety as well as that of their family and friends, they are forced to isolate themselves. As they search for the horcruxes, the trio learns details about Dumbledore's past, as well as Snape's true motives\u2014he had worked on Dumbledore's behalf since the murder of Harry's mother.\n"
                                       + "\n" + "The book culminates in the Battle of Hogwarts. Harry, Ron and Hermione, in conjunction with members of the Order of the Phoenix and many of the teachers and students, defend Hogwarts from Voldemort, his Death Eaters, and various dangerous magical creatures. Several major characters are killed in the first wave of the battle, including Remus Lupin and Fred Weasley. After learning that he himself is a horcrux, Harry surrenders himself to Voldemort in the Forbidden Forest, who casts a killing curse (Avada Kedavra) at him. The defenders of Hogwarts do not surrender after learning of Harry's presumed death and continue to fight on. Harry awakens and faces Voldemort, whose horcruxes have all been destroyed. In the final battle, Voldemort's killing curse rebounds off Harry's defensive spell (Expelliarmus) killing Voldemort.\n"
                                       + "\n" + "An epilogue describes the lives of the surviving characters and the effects of Voldemort's death on the wizarding world."
                                       ));
            document.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             , "diff"));
        }
Ejemplo n.º 3
0
 public virtual void ColumnRendererTest()
 {
     NUnit.Framework.Assert.That(() => {
         // TODO DEVSIX-2901 the exception should not be thrown
         String outFileName      = destinationFolder + "columnRendererTest.pdf";
         String cmpFileName      = sourceFolder + "cmp_columnRendererTest.pdf";
         PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName));
         String textByron        = "When a man hath no freedom to fight for at home,\n" + "    Let him combat for that of his neighbours;\n"
                                   + "Let him think of the glories of Greece and of Rome,\n" + "    And get knocked on the head for his labours.\n"
                                   + "\n" + "To do good to Mankind is the chivalrous plan,\n" + "    And is always as nobly requited;\n"
                                   + "Then battle for Freedom wherever you can,\n" + "    And, if not shot or hanged, you'll get knighted.";
         Document doc = new Document(pdfDocument);
         doc.SetProperty(Property.COLLAPSING_MARGINS, true);
         Paragraph p = new Paragraph();
         for (int i = 0; i < 10; i++)
         {
             p.Add(textByron);
         }
         Div div = new Div().Add(p);
         IList <Rectangle> areas = new List <Rectangle>();
         areas.Add(new Rectangle(30, 30, 150, 600));
         areas.Add(new Rectangle(200, 30, 150, 600));
         areas.Add(new Rectangle(370, 30, 150, 600));
         div.SetNextRenderer(new CollapsingMarginsTest.CustomColumnDocumentRenderer(div, areas));
         doc.Add(div);
         doc.Close();
         NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                          , "diff"));
     }
                                 , NUnit.Framework.Throws.InstanceOf <ArgumentOutOfRangeException>())
     ;
 }
Ejemplo n.º 4
0
 public virtual void ColumnRendererTest()
 {
     NUnit.Framework.Assert.That(() => {
         /* TODO DEVSIX-2901 the exception should not be thrown
          * if after DEVSIX-2901 the exception persists,
          * change the type of the expected exception to a more specific one to make the test stricter.
          */
         String outFileName      = destinationFolder + "columnRendererTest.pdf";
         String cmpFileName      = sourceFolder + "cmp_columnRendererTest.pdf";
         PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName));
         Document doc            = new Document(pdfDocument);
         doc.SetProperty(Property.COLLAPSING_MARGINS, true);
         Paragraph p = new Paragraph();
         for (int i = 0; i < 10; i++)
         {
             p.Add(TEXT_BYRON);
         }
         Div div = new Div().Add(p);
         IList <Rectangle> areas = new List <Rectangle>();
         areas.Add(new Rectangle(30, 30, 150, 600));
         areas.Add(new Rectangle(200, 30, 150, 600));
         areas.Add(new Rectangle(370, 30, 150, 600));
         div.SetNextRenderer(new CollapsingMarginsTest.CustomColumnDocumentRenderer(div, areas));
         doc.Add(div);
         doc.Close();
         NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                          , "diff"));
     }
                                 , NUnit.Framework.Throws.InstanceOf <Exception>())
     ;
 }
Ejemplo n.º 5
0
        public virtual void CollapsingMarginsTest05()
        {
            String      outFileName = destinationFolder + "collapsingMarginsTest05.pdf";
            String      cmpFileName = sourceFolder + "cmp_collapsingMarginsTest05.pdf";
            PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName));

            DrawPageBorders(pdfDocument, 2);
            String textByron = "When a man hath no freedom to fight for at home,\n" + "    Let him combat for that of his neighbours;\n"
                               + "Let him think of the glories of Greece and of Rome,\n" + "    And get knocked on the head for his labours.\n"
                               + "\n" + "To do good to Mankind is the chivalrous plan,\n" + "    And is always as nobly requited;\n"
                               + "Then battle for Freedom wherever you can,\n" + "    And, if not shot or hanged, you'll get knighted.";
            Document doc = new Document(pdfDocument);

            doc.SetProperty(Property.COLLAPSING_MARGINS, true);
            Paragraph p = new Paragraph(textByron).SetBackgroundColor(ColorConstants.YELLOW);

            for (int i = 0; i < 3; i++)
            {
                p.Add(textByron);
            }
            doc.Add(p);
            p.SetMarginTop(80);
            Div div = new Div();

            div.Add(p).SetBackgroundColor(new DeviceRgb(65, 151, 29));
            doc.Add(div);
            doc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             , "diff"));
        }
Ejemplo n.º 6
0
        public virtual void CollapsingMarginsTest03()
        {
            String      outFileName = destinationFolder + "collapsingMarginsTest03.pdf";
            String      cmpFileName = sourceFolder + "cmp_collapsingMarginsTest03.pdf";
            PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName));

            DrawPageBorders(pdfDocument, 3);
            Document doc = new Document(pdfDocument);

            doc.SetProperty(Property.COLLAPSING_MARGINS, true);
            doc.Add(new Paragraph("marker text").SetMargin(0));
            Paragraph p = new Paragraph(TEXT_BYRON);

            for (int i = 0; i < 3; i++)
            {
                p.Add(TEXT_BYRON);
            }
            p.Add("When a man hath no freedom to fight for at home,\n" + "    Let him combat for that of his neighbours;\n"
                  + "Let him think of the glories of Greece and of Rome,\n" + "    And get knocked on the head for his labours.\n"
                  + "To do good to Mankind is the chivalrous plan,\n");
            Div div1 = new Div();
            Div div2 = new Div();

            div1.Add(p).SetBackgroundColor(new DeviceRgb(65, 151, 29));
            div2.Add(p).SetBackgroundColor(new DeviceRgb(209, 247, 29));
            div1.SetMarginBottom(80);
            div2.SetMarginTop(80);
            div2.SetMarginBottom(150);
            doc.Add(div1);
            doc.Add(div2);
            doc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             , "diff"));
        }
Ejemplo n.º 7
0
        public virtual void SingleFontWithUnicodeRange()
        {
            String fileName = "singleFontWithUnicodeRange";
            //In the result pdf will be two equal fonts but with different subsets
            String       outFileName = destinationFolder + fileName + ".pdf";
            String       cmpFileName = sourceFolder + "cmp_" + fileName + ".pdf";
            FontProvider sel         = new FontProvider();

            NUnit.Framework.Assert.IsTrue(sel.GetFontSet().AddFont(fontsFolder + "NotoSans-Regular.ttf", null, "FontAlias"
                                                                   ));
            NUnit.Framework.Assert.IsFalse(sel.GetFontSet().AddFont(fontsFolder + "NotoSans-Regular.ttf", null, "FontAlias"
                                                                    ));
            NUnit.Framework.Assert.IsTrue(sel.GetFontSet().Size() == 1);
            String      s      = "Hello world! Здравствуй мир! Hello world! Здравствуй мир!";
            PdfDocument pdfDoc = new PdfDocument(new PdfWriter(new FileStream(outFileName, FileMode.Create)));
            Document    doc    = new Document(pdfDoc);

            doc.SetFontProvider(sel);
            doc.SetProperty(Property.FONT, new String[] { "FontAlias" });
            Text      text      = new Text(s).SetBackgroundColor(ColorConstants.LIGHT_GRAY);
            Paragraph paragraph = new Paragraph(text);

            doc.Add(paragraph);
            doc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             , "diff" + fileName));
        }
Ejemplo n.º 8
0
        public virtual void CyrillicAndLatinGroup()
        {
            String       fileName    = "cyrillicAndLatinGroup";
            String       outFileName = destinationFolder + "cyrillicAndLatinGroup.pdf";
            String       cmpFileName = sourceFolder + "cmp_" + fileName + ".pdf";
            FontProvider sel         = new FontProvider();

            NUnit.Framework.Assert.IsTrue(sel.AddFont(fontsFolder + "NotoSans-Regular.ttf"));
            NUnit.Framework.Assert.IsTrue(sel.AddFont(fontsFolder + "FreeSans.ttf"));
            NUnit.Framework.Assert.IsTrue(sel.GetFontSet().AddFont(fontsFolder + "Puritan2.otf", PdfEncodings.IDENTITY_H
                                                                   , "Puritan42"));
            String      s      = "Hello world! Здравствуй мир! Hello world! Здравствуй мир!";
            PdfDocument pdfDoc = new PdfDocument(new PdfWriter(new FileStream(outFileName, FileMode.Create)));
            Document    doc    = new Document(pdfDoc);

            doc.SetFontProvider(sel);
            doc.SetProperty(Property.FONT, new String[] { "Puritan42" });
            Text      text      = new Text(s).SetBackgroundColor(ColorConstants.LIGHT_GRAY);
            Paragraph paragraph = new Paragraph(text);

            doc.Add(paragraph);
            doc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             , "diff" + fileName));
        }
Ejemplo n.º 9
0
        public virtual void FloatAlignmentTest03()
        {
            String      outFileName = destinationFolder + "floatAlignmentTest03.pdf";
            String      cmpFileName = sourceFolder + "cmp_floatAlignmentTest03.pdf";
            PdfWriter   writer      = new PdfWriter(outFileName);
            PdfDocument pdfDoc      = new PdfDocument(writer);

            pdfDoc.SetDefaultPageSize(new PageSize(350, 450));
            Document doc = new Document(pdfDoc);

            doc.Add(new Paragraph("All lines after this one have first line indent = 20."));
            doc.SetProperty(Property.FIRST_LINE_INDENT, 20f);
            Text text = new Text("float");

            text.SetBorder(new SolidBorder(1));
            text.SetProperty(Property.FLOAT, FloatPropertyValue.LEFT);
            AddInlineBlockFloatAndText(doc, text);
            doc.Add(new AreaBreak());
            text.SetProperty(Property.FLOAT, FloatPropertyValue.RIGHT);
            AddInlineBlockFloatAndText(doc, text);
            doc.Close();
            doc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             , "diff"));
        }
Ejemplo n.º 10
0
        public virtual void CyrillicAndLatinWithUnicodeRange()
        {
            String       fileName    = "cyrillicAndLatinWithUnicodeRange";
            String       outFileName = destinationFolder + fileName + ".pdf";
            String       cmpFileName = sourceFolder + "cmp_" + fileName + ".pdf";
            FontProvider sel         = new FontProvider();

            NUnit.Framework.Assert.IsTrue(sel.GetFontSet().AddFont(fontsFolder + "NotoSans-Regular.ttf", null, "FontAlias"
                                                                   , new RangeBuilder(0, 255).Create()));
            NUnit.Framework.Assert.IsTrue(sel.GetFontSet().AddFont(fontsFolder + "FreeSans.ttf", null, "FontAlias", new
                                                                   RangeBuilder(1024, 1279).Create()));
            NUnit.Framework.Assert.IsTrue(sel.GetFontSet().Size() == 2);
            String      s      = "Hello world! Здравствуй мир! Hello world! Здравствуй мир!";
            PdfDocument pdfDoc = new PdfDocument(new PdfWriter(new FileStream(outFileName, FileMode.Create)));
            Document    doc    = new Document(pdfDoc);

            doc.SetFontProvider(sel);
            doc.SetProperty(Property.FONT, new String[] { "FontAlias" });
            Text      text      = new Text(s).SetBackgroundColor(ColorConstants.LIGHT_GRAY);
            Paragraph paragraph = new Paragraph(text);

            doc.Add(paragraph);
            doc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             , "diff" + fileName));
        }
Ejemplo n.º 11
0
        public virtual void CollapsingMarginsTest05()
        {
            String      outFileName = destinationFolder + "collapsingMarginsTest05.pdf";
            String      cmpFileName = sourceFolder + "cmp_collapsingMarginsTest05.pdf";
            PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName));

            DrawPageBorders(pdfDocument, 2);
            Document doc = new Document(pdfDocument);

            doc.SetProperty(Property.COLLAPSING_MARGINS, true);
            Paragraph p = new Paragraph(TEXT_BYRON).SetBackgroundColor(ColorConstants.YELLOW);

            for (int i = 0; i < 3; i++)
            {
                p.Add(TEXT_BYRON);
            }
            doc.Add(p);
            p.SetMarginTop(80);
            Div div = new Div();

            div.Add(p).SetBackgroundColor(new DeviceRgb(65, 151, 29));
            doc.Add(div);
            doc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             , "diff"));
        }
Ejemplo n.º 12
0
        public virtual void KeepWithNextTest07()
        {
            String      outFileName = destinationFolder + "keepWithNextTest07.pdf";
            String      cmpFileName = sourceFolder + "cmp_keepWithNextTest07.pdf";
            PdfDocument pdf         = new PdfDocument(new PdfWriter(outFileName));
            Document    document    = new Document(pdf, PageSize.A4);

            document.SetProperty(Property.FIRST_LINE_INDENT, 20f);
            document.Add(new Paragraph(LONG_TEXT).SetKeepWithNext(true));
            document.Add(new Paragraph(LONG_TEXT));
            document.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             , "diff"));
        }
Ejemplo n.º 13
0
        public virtual void KeepTogetherOnInnerElementTestEmptyPageTest()
        {
            // TODO DEVSIX-4023 cmp should be updated
            String      cmpFileName = sourceFolder + "cmp_keepTogetherOnInnerElementTestEmptyPageTest.pdf";
            String      outFile     = destinationFolder + "keepTogetherOnInnerElementTestEmptyPageTest.pdf";
            PdfDocument pdfDoc      = new PdfDocument(new PdfWriter(outFile));
            Document    doc         = new Document(pdfDoc);

            doc.SetProperty(Property.COLLAPSING_MARGINS, true);
            bool first = false;

            AddDivs(doc, 200, new Style(), new Style(), first);
            // Specifying height definitely bigger than page height
            float innerDivHeight = pdfDoc.GetDefaultPageSize().GetHeight() + 200;

            AddDivs(doc, innerDivHeight, new Style(), new Style(), first);
            doc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFile, cmpFileName, destinationFolder,
                                                                             "diff"));
        }
Ejemplo n.º 14
0
        public virtual void MarginsRotatedTest02()
        {
            //TODO: currently is incorrect. See DEVSIX-989
            String   outFileName = destinationFolder + "marginsRotatedTest02.pdf";
            String   cmpFileName = sourceFolder + cmpPrefix + "marginsRotatedTest02.pdf";
            Document doc         = new Document(new PdfDocument(new PdfWriter(outFileName)));

            doc.SetProperty(Property.COLLAPSING_MARGINS, true);
            Text text = new Text("Hello. I am a fairly long paragraph. I really want you to process me correctly. You heard that? Correctly!!! Even if you will have to wrap me."
                                 );
            Div d  = new Div().SetWidth(400).SetBorder(new SolidBorder(ColorConstants.RED, 5));
            Div d1 = new Div().Add(new Paragraph(text)).SetWidth(200).SetRotationAngle(Math.PI / 4).SetMargins(100, 10
                                                                                                               , 100, 10).SetBorder(new SolidBorder(ColorConstants.BLUE, 5));

            doc.Add(d.Add(d1).Add(new Paragraph("Hello").SetMargin(50).SetBorder(new SolidBorder(ColorConstants.GREEN,
                                                                                                 5))));
            doc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             , "diff"));
        }
Ejemplo n.º 15
0
        public virtual void KeepWithNextTest04()
        {
            String      outFileName = destinationFolder + "keepWithNextTest04.pdf";
            String      cmpFileName = sourceFolder + "cmp_keepWithNextTest04.pdf";
            PdfDocument pdf         = new PdfDocument(new PdfWriter(outFileName));
            Document    document    = new Document(pdf, PageSize.A4);

            for (int i = 0; i < 22; i++)
            {
                document.Add(new Paragraph("dummy"));
            }
            document.SetProperty(Property.FIRST_LINE_INDENT, 20);
            Paragraph title = new Paragraph(MIDDLE_TEXT);

            title.SetKeepWithNext(true);
            document.Add(title);
            document.Add(new Paragraph(LONG_TEXT));
            document.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             , "diff"));
        }
Ejemplo n.º 16
0
        public virtual void MarginCollapseKeptTogetherGoesOnNextAreaTest02()
        {
            String      cmpFileName = sourceFolder + "cmp_marginCollapseKeptTogetherGoesOnNextAreaTest02.pdf";
            String      outFile     = destinationFolder + "marginCollapseKeptTogetherGoesOnNextAreaTest02.pdf";
            PdfDocument pdfDoc      = new PdfDocument(new PdfWriter(outFile));
            Document    doc         = new Document(pdfDoc);

            doc.SetProperty(Property.COLLAPSING_MARGINS, true);
            Div div1 = new Div().SetMarginBottom(100).SetBackgroundColor(ColorConstants.RED).SetHeight(300).Add(new Paragraph
                                                                                                                    ("Bottom margin: 100"));

            doc.Add(div1);
            Div div2 = new Div().SetMarginTop(300).SetHeight(300).SetBackgroundColor(ColorConstants.RED).Add(new Paragraph
                                                                                                                 ("Top margin: 300"));

            div2.SetKeepTogether(true);
            doc.Add(div2);
            doc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFile, cmpFileName, destinationFolder,
                                                                             "diff"));
        }
Ejemplo n.º 17
0
        public virtual void MarginCollapseKeptTogetherDivGoesBackTest02()
        {
            // TODO DEVSIX-3995 The margin between the divs occupies 100 points instead of 300. After a fix the cmp should be updated
            String      cmpFileName = sourceFolder + "cmp_marginCollapseKeptTogetherDivGoesBackTest02.pdf";
            String      outFile     = destinationFolder + "marginCollapseKeptTogetherDivGoesBackTest02.pdf";
            PdfDocument pdfDoc      = new PdfDocument(new PdfWriter(outFile));
            Document    doc         = new Document(pdfDoc);

            doc.SetProperty(Property.COLLAPSING_MARGINS, true);
            Div div1 = new Div().SetMarginBottom(300).SetBackgroundColor(ColorConstants.RED).SetHeight(300).Add(new Paragraph
                                                                                                                    ("Bottom margin: 300"));

            doc.Add(div1);
            Div div2 = new Div().SetMarginTop(100).SetHeight(1000).SetBackgroundColor(ColorConstants.RED).Add(new Paragraph
                                                                                                                  ("Top margin: 100"));

            div2.SetKeepTogether(true);
            doc.Add(div2);
            doc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFile, cmpFileName, destinationFolder,
                                                                             "diff"));
        }
Ejemplo n.º 18
0
        public virtual void KeepTogetherNotEmptyPageTest()
        {
            String      cmpFileName = sourceFolder + "cmp_keepTogetherNotEmptyPageTest.pdf";
            String      outFile     = destinationFolder + "keepTogetherNotEmptyPageTest.pdf";
            PdfDocument pdfDoc      = new PdfDocument(new PdfWriter(outFile));
            Document    doc         = new Document(pdfDoc);

            doc.SetProperty(Property.COLLAPSING_MARGINS, true);
            // Make page not empty to trigger KEEP_TOGETHER actual processing
            doc.Add(new Paragraph("Just some content to make this page not empty."));
            // Specifying height definitely bigger than page height
            float innerDivHeight = pdfDoc.GetDefaultPageSize().GetHeight() + 200;
            Div   innerDiv       = new Div();

            innerDiv.SetBackgroundColor(ColorConstants.RED);
            innerDiv.SetHeight(innerDivHeight);
            // Set KEEP_TOGETHER on inner div
            innerDiv.SetKeepTogether(true);
            doc.Add(innerDiv);
            doc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFile, cmpFileName, destinationFolder,
                                                                             "diff"));
        }
Ejemplo n.º 19
0
        public virtual void PreLayoutTest01()
        {
            String            outFileName         = destinationFolder + "preLayoutTest01.pdf";
            String            cmpFileName         = sourceFolder + "cmp_preLayoutTest01.pdf";
            PdfDocument       pdfDocument         = new PdfDocument(new PdfWriter(outFileName)).SetTagged();
            Document          document            = new Document(pdfDocument, PageSize.Default, false);
            IList <Text>      pageNumberTexts     = new List <Text>();
            IList <IRenderer> pageNumberRenderers = new List <IRenderer>();

            document.SetProperty(Property.FONT, PdfFontFactory.CreateFont(StandardFonts.HELVETICA));
            for (int i = 0; i < 200; i++)
            {
                document.Add(new Paragraph("This is just junk text"));
                if (i % 10 == 0)
                {
                    Text      pageNumberText = new Text("Page #: {pageNumber}");
                    IRenderer renderer       = new TextRenderer(pageNumberText);
                    pageNumberText.SetNextRenderer(renderer);
                    pageNumberRenderers.Add(renderer);
                    Paragraph pageNumberParagraph = new Paragraph().Add(pageNumberText);
                    pageNumberTexts.Add(pageNumberText);
                    document.Add(pageNumberParagraph);
                }
            }
            foreach (IRenderer renderer in pageNumberRenderers)
            {
                String currentData = renderer.ToString().Replace("{pageNumber}", renderer.GetOccupiedArea().GetPageNumber(
                                                                     ).ToString());
                ((TextRenderer)renderer).SetText(currentData);
                ((Text)renderer.GetModelElement()).SetNextRenderer(renderer);
            }
            document.Relayout();
            document.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             , "diff"));
        }