Exemplo n.º 1
0
        protected void ManipulatePdf(string dest)
        {
            PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
            Document    doc    = new Document(pdfDoc);

            Paragraph p = new Paragraph("Hello World.");

            doc.Add(p);

            p = new Paragraph();
            p.AddTabStops(new TabStop(60f, TabAlignment.LEFT));
            p.Add(new Tab());
            p.Add("Hello World with tab.");
            doc.Add(p);

            p = new Paragraph();
            p.AddTabStops(new TabStop(200f, TabAlignment.LEFT));
            p.Add(new Text("Hello World with"));
            p.Add(new Tab());
            p.Add(new Text("an inline tab."));
            doc.Add(p);

            p = new Paragraph();
            p.AddTabStops(new TabStop(60f, TabAlignment.LEFT));
            p.Add(new Tab());
            p.AddTabStops(new TabStop(200f, TabAlignment.LEFT));
            p.Add(new Text("Hello World with"));
            p.Add(new Tab());
            p.Add(new Text("an inline tab."));
            doc.Add(p);

            doc.Close();
        }
Exemplo n.º 2
0
        protected void ManipulatePdf(String dest)
        {
            PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
            Document    doc    = new Document(pdfDoc);

            for (int i = 0; i < 10; i++)
            {
                String title = "This is title " + i;
                Text   text  = new Text(title).SetFontSize(16);
                text.SetNextRenderer(new TOCTextRenderer(text));
                doc.Add(new Paragraph(text));
                for (int j = 0; j < 50; j++)
                {
                    doc.Add(new Paragraph("Line " + j + " of title " + i));
                }
            }

            doc.Add(new AreaBreak());

            // Create a table of contents
            doc.Add(new Paragraph("Table of Contents").SetFontSize(16));
            foreach (KeyValuePair <String, int> entry in toc)
            {
                Paragraph p = new Paragraph(entry.Key);
                p.AddTabStops(new TabStop(750, TabAlignment.RIGHT, new DottedLine()));
                p.Add(new Tab());
                p.Add(entry.Value.ToString());
                doc.Add(p);
            }

            doc.Close();
        }
Exemplo n.º 3
0
        public virtual void CreatePdf(String dest)
        {
            PdfDocument pdf      = new PdfDocument(new PdfWriter(dest));
            Document    document = new Document(pdf, PageSize.A4.Rotate());

            float[]         stops     = new float[] { 80, 120, 430, 640, 720 };
            IList <TabStop> tabstops  = new List <TabStop>();
            PdfCanvas       pdfCanvas = new PdfCanvas(pdf.AddNewPage());

            for (int i = 0; i < stops.Length; i++)
            {
                tabstops.Add(new TabStop(stops[i]));
                pdfCanvas.MoveTo(document.GetLeftMargin() + stops[i], 0);
                pdfCanvas.LineTo(document.GetLeftMargin() + stops[i], 595);
            }
            pdfCanvas.Stroke();
            IList <IList <String> > resultSet = CsvTo2DList.Convert(SRC, "|");

            foreach (IList <String> record in resultSet)
            {
                Paragraph p = new Paragraph();
                p.AddTabStops(tabstops);
                p.Add(record[0].Trim()).Add(new Tab()).Add(record[1].Trim()).Add(new Tab()).Add(record[2].Trim()).Add(new
                                                                                                                      Tab()).Add(record[3].Trim()).Add(new Tab()).Add(record[4].Trim()).Add(new Tab()).Add(record[5].Trim());
                document.Add(p);
            }
            document.Close();
        }
Exemplo n.º 4
0
        public virtual void TabsInParagraphTest01()
        {
            String      outFileName = destinationFolder + "tabsInParagraphTest01.pdf";
            String      cmpFileName = sourceFolder + "cmp_tabsInParagraphTest01.pdf";
            PdfDocument pdfDoc      = new PdfDocument(new PdfWriter(outFileName));
            Document    doc         = new Document(pdfDoc);
            float       tabWidth    = pdfDoc.GetDefaultPageSize().GetWidth() - doc.GetLeftMargin() - doc.GetRightMargin();
            Paragraph   p           = new Paragraph();

            p.AddTabStops(new TabStop(tabWidth, TabAlignment.RIGHT)).Add("There is a right-aligned tab after me. And then three chunks of text."
                                                                         ).Add(new Tab()).Add("Text1").Add("Text2").Add("Text3");
            doc.Add(p);
            p = new Paragraph();
            p.AddTabStops(new TabStop(tabWidth, TabAlignment.RIGHT)).Add("There is a right-aligned tab after me. And then three chunks of text."
                                                                         ).Add(new Tab()).Add("Text1").Add("Tex\nt2").Add("Text3");
            doc.Add(p);
            p = new Paragraph();
            p.AddTabStops(new TabStop(tabWidth, TabAlignment.RIGHT)).Add("There is a right-aligned tab after me. And then three chunks of text."
                                                                         ).Add(new Tab()).Add("Long Long Long Long Long Long Long Text1").Add("Tex\nt2").Add("Text3");
            doc.Add(p);
            PdfImageXObject xObject = new PdfImageXObject(ImageDataFactory.CreateJpeg(UrlUtil.ToURL(sourceFolder + "Desert.jpg"
                                                                                                    )));

            iText.Layout.Element.Image image = new iText.Layout.Element.Image(xObject, 100);
            p = new Paragraph();
            p.AddTabStops(new TabStop(tabWidth, TabAlignment.RIGHT)).Add("There is a right-aligned tab after me. And then texts and an image."
                                                                         ).Add(new Tab()).Add("Text1").Add(image).Add("Text3");
            doc.Add(p);
            doc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             , "diff"));
        }
Exemplo n.º 5
0
        public virtual void SeveralTabsInRowTest()
        {
            String   fileName    = "severalTabsInRowTest.pdf";
            String   outFileName = destinationFolder + fileName;
            String   cmpFileName = sourceFolder + "cmp_" + fileName;
            Document doc         = InitDocument(outFileName);
            float    tabInterval = doc.GetPdfDocument().GetDefaultPageSize().GetWidth() / 8;

            float[]        positions  = new float[] { tabInterval * 2, tabInterval * 4, tabInterval * 6 };
            TabAlignment[] alignments = new TabAlignment[] { TabAlignment.RIGHT, TabAlignment.CENTER, TabAlignment.CENTER };
            //        Drawable[] leaders = {null, null, null};
            ILineDrawer[] leaders = new ILineDrawer[] { new DottedLine(), new DashedLine(.5f), new SolidLine(.5f) };
            Paragraph     p       = new Paragraph();

            p.SetFontSize(8);
            IList <TabStop> tabStops = new List <TabStop>();

            for (int i = 0; i < positions.Length; ++i)
            {
                TabStop tabStop = new TabStop(positions[i], alignments[i], leaders[i]);
                tabStops.Add(tabStop);
            }
            p.AddTabStops(tabStops);
            p.Add(new Tab()).Add("ttttttttttttttttttttttttttttttttttttttttttttt").Add(new Tab()).Add(new Tab()).Add("ttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt\n"
                                                                                                                    );
            p.Add(new Tab()).Add(new Tab()).Add(new Tab()).Add("ttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt\n"
                                                               );
            p.Add(new Tab()).Add(new Tab()).Add("ttttttttttttttttttttttttttttttttttttttttttttt").Add(new Tab()).Add("ttttttttttttttttttttttttttttttttttttttttttt"
                                                                                                                    );
            doc.Add(p);
            DrawTabStopsPositions(positions, doc, 1, 0, 120);
            doc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             , "diff" + outFileName));
        }
Exemplo n.º 6
0
        public virtual void TabsAnchorSemicolonTest02()
        {
            String      outFileName = destinationFolder + "tabsAnchorSemicolonTest02.pdf";
            String      cmpFileName = sourceFolder + "cmp_tabsAnchorSemicolonTest02.pdf";
            PdfDocument pdfDoc      = new PdfDocument(new PdfWriter(outFileName));
            Document    document    = new Document(pdfDoc);
            float       w           = document.GetPageEffectiveArea(PageSize.A4).GetWidth();
            Paragraph   p           = new Paragraph();

            p.SetProperty(Property.TAB_DEFAULT, 0.01f);
            IList <TabStop> tabstops = new List <TabStop>();

            tabstops.Add(new TabStop(w / 2, TabAlignment.RIGHT));
            p.AddTabStops(tabstops);
            p.Add(new Tab()).Add("Test:").Add(new Tab()).Add("Answer");
            document.Add(p);
            p = new Paragraph();
            p.SetProperty(Property.TAB_DEFAULT, 0.01f);
            p.AddTabStops(tabstops);
            p.Add(new Tab()).Add("Test245454:").Add(new Tab()).Add("Answer2");
            document.Add(p);
            document.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             , "diff"));
        }
        private static void AddParagraphWithTwoParts1(Document doc, PdfFont font, string string1, string string2, float fontSize)
        {
            if (string1 == null)
            {
                string1 = "";
            }

            if (string1.Length > 10)
            {
                string1 = string1.Substring(0, 10);
            }

            Text chunk1 = new Text(string1).SetFont(font).SetFontSize(fontSize);

            if (string2 == null)
            {
                string2 = "";
            }

            if (string1.Length + string2.Length > 100)
            {
                string2 = string2.Substring(0, 100 - string1.Length);
            }

            Text chunk2 = new Text(string2).SetFont(font).SetFontSize(fontSize);

            Paragraph p = new Paragraph();

            p.Add(chunk1);
            p.AddTabStops(new TabStop(1000, TabAlignment.RIGHT));
            p.Add(new Tab());
            p.Add(chunk2);
            doc.Add(p);
            doc.Add(new LineSeparator(new SolidLine(1)).SetMarginTop(-6));
        }
Exemplo n.º 8
0
        private void AddTabbedTextToParagraph(Paragraph p, String text, float[] positions, TabAlignment[] alignments
                                              , ILineDrawer[] tabLeadings, char?[] tabAnchorCharacters)
        {
            IList <TabStop> tabStops = new List <TabStop>();

            for (int i = 0; i < positions.Length; ++i)
            {
                TabStop tabStop = new TabStop(positions[i], alignments[i], tabLeadings[i]);
                tabStop.SetTabAnchor(tabAnchorCharacters[i]);
                tabStops.Add(tabStop);
            }
            p.AddTabStops(tabStops);
            foreach (String line in iText.IO.Util.StringUtil.Split(text, "\n"))
            {
                foreach (String chunk in iText.IO.Util.StringUtil.Split(line, "\t"))
                {
                    foreach (String piece in iText.IO.Util.StringUtil.Split(chunk, "#"))
                    {
                        if (!String.IsNullOrEmpty(piece))
                        {
                            p.Add(piece);
                        }
                    }
                    p.Add(new Tab());
                }
                p.Add("\n");
            }
        }
Exemplo n.º 9
0
        public virtual void ChunkEndsAfterOrBeforeTabPosition()
        {
            String      outFileName   = destinationFolder + "chunkEndsAfterOrBeforeTabPosition.pdf";
            String      cmpFileName   = sourceFolder + "cmp_chunkEndsAfterOrBeforeTabPosition.pdf";
            PdfDocument pdfDoc        = new PdfDocument(new PdfWriter(outFileName));
            Document    doc           = new Document(pdfDoc);
            String      textBeforeTab = "a";
            String      textAfterTab  = "tab stop's position = ";
            Paragraph   paragraph;

            for (int i = 0; i < 20; i++)
            {
                paragraph = new Paragraph();
                paragraph.Add(new Text(textBeforeTab));
                TabStop[] tabStop = new TabStop[1];
                tabStop[0] = new TabStop(i);
                paragraph.AddTabStops(tabStop);
                paragraph.Add(new Tab());
                paragraph.Add(new Text(textAfterTab));
                paragraph.Add(JavaUtil.IntegerToString(i));
                doc.Add(paragraph);
            }
            doc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             , "diff"));
        }
Exemplo n.º 10
0
        private static Paragraph CreateParagraphWithTab(string key, string value1, string value2)
        {
            Paragraph p = new Paragraph();

            p.AddTabStops(new TabStop(200f, TabAlignment.LEFT));
            p.Add(key);
            p.Add(value1);
            p.Add(new Tab());
            p.Add(value2);
            return(p);
        }
Exemplo n.º 11
0
        private Paragraph createParagraphWithTab(string key, string value)
        {
            Paragraph p = new Paragraph();

            p.AddTabStops(new TabStop(100f, TabAlignment.LEFT));
            p.Add(key);
            p.Add(new Tab());
            p.Add(new Paragraph(": " + value));

            return(p);
        }
Exemplo n.º 12
0
        public virtual void OutOfPageBoundsTest()
        {
            String      outFileName = destinationFolder + "outOfPageBoundsTest.pdf";
            String      cmpFileName = sourceFolder + "cmp_outOfPageBoundsTest.pdf";
            FileStream  file        = new FileStream(outFileName, FileMode.Create);
            PdfWriter   writer      = new PdfWriter(file);
            PdfDocument pdfDoc      = new PdfDocument(writer);
            Document    doc         = new Document(pdfDoc);
            //tabstops out of page bounds
            Paragraph p = new Paragraph();

            p.SetFontColor(Color.GREEN);
            p.Add("left tab stop out of page bounds:");
            doc.Add(p);
            p = new Paragraph();
            p.AddTabStops(new TabStop(1000, TabAlignment.LEFT, new DashedLine(.5f)));
            p.Add("text").Add(new Tab()).Add("some interesting text after left-tabstop");
            doc.Add(p);
            p = new Paragraph();
            p.SetFontColor(Color.GREEN);
            p.Add("right tab stop out of page bounds:");
            doc.Add(p);
            p = new Paragraph();
            p.AddTabStops(new TabStop(1000, TabAlignment.RIGHT, new DashedLine(.5f)));
            p.Add("text").Add(new Tab()).Add("some interesting text after right-tabstop");
            doc.Add(p);
            //text out of page bounds
            p = new Paragraph();
            p.SetFontColor(Color.GREEN);
            p.Add("text out of page bounds after left tab stop:");
            doc.Add(p);
            p = new Paragraph();
            p.AddTabStops(new TabStop(450, TabAlignment.LEFT, new DashedLine(.5f)));
            p.Add("text").Add(new Tab()).Add("some interesting text after left-tabstop\n");
            p.Add("text").Add(new Tab()).Add("someinterestingtextafterleft-tabstop");
            doc.Add(p);
            p = new Paragraph();
            p.SetFontColor(Color.GREEN);
            p.Add("text out of page bounds after right tab stop:");
            doc.Add(p);
            p = new Paragraph();
            p.AddTabStops(new TabStop(450, TabAlignment.RIGHT, new DashedLine(.5f)));
            p.Add("teeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeext").Add(new Tab()).Add("some interesting text after right-tabstop\n"
                                                                                                     );
            p.Add("teeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeext").Add(new Tab()).Add("someinterestingtextafterright-tabstop\n"
                                                                                                     );
            p.Add("teeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeext").Add(new Tab()).Add("word.");
            doc.Add(p);
            doc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             , "diff"));
        }
Exemplo n.º 13
0
        private void ManipulatePdf(string dest)
        {
            PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
            Document    doc    = new Document(pdfDoc);

            // By default column width is calculated automatically for the best fit.
            // useAllAvailableWidth() method makes table use the whole page's width while placing the content.
            Table table = new Table(UnitValue.CreatePercentArray(2));

            table.SetHorizontalAlignment(HorizontalAlignment.LEFT);
            table.SetWidth(UnitValue.CreatePercentValue(60));
            table.SetMarginBottom(20);

            Cell cell = new Cell().Add(new Paragraph("Received Rs (in Words):"));

            // Set all the cell's borders except for the right one to have black color and width of 1 point
            cell.SetBorder(new SolidBorder(1));
            cell.SetBorderRight(Border.NO_BORDER);
            table.AddCell(cell);

            cell = new Cell().Add(new Paragraph("Priceless"));
            cell.SetTextAlignment(TextAlignment.RIGHT);
            cell.SetBorder(new SolidBorder(1));
            cell.SetBorderLeft(Border.NO_BORDER);
            table.AddCell(cell);

            doc.Add(table);

            table.SetWidth(UnitValue.CreatePercentValue(50));

            doc.Add(table);

            table = new Table(UnitValue.CreatePercentArray(1));
            table.SetHorizontalAlignment(HorizontalAlignment.LEFT);
            table.SetWidth(UnitValue.CreatePercentValue(50));

            Paragraph p = new Paragraph();

            p.Add(new Text("Received Rs (In Words):"));
            p.AddTabStops(new TabStop(1000, TabAlignment.RIGHT));
            p.Add(new Tab());
            p.Add(new Text("Priceless"));
            table.AddCell(new Cell().Add(p));

            doc.Add(table);

            doc.Close();
        }
Exemplo n.º 14
0
        private int AddTOCItem(ref Document document, List <Tuple <string, int> > tocItems, bool addAfterRemove, int locationToStartTOC, int?amountPages = null)
        {
            var pdf = document.GetPdfDocument();

            int startingTOC       = pdf.GetNumberOfPages();
            int amountToIncrement = 0;

            if (amountPages != null)
            {
                amountToIncrement = amountPages.Value;
            }

            foreach (var entry in tocItems)
            {
                string   destinationKey   = "p" + entry.Item2 + amountToIncrement;
                PdfArray destinationArray = new PdfArray();
                destinationArray.Add(new PdfNumber(entry.Item2 + amountToIncrement - 1));
                destinationArray.Add(PdfName.XYZ);
                pdf.AddNamedDestination(destinationKey, destinationArray);

                Paragraph p = new Paragraph();
                p.AddTabStops(new TabStop(540, TabAlignment.RIGHT, new DottedLine()));
                p.Add(entry.Item1);
                p.Add(new Tab());
                p.Add((entry.Item2 + amountToIncrement).ToString());
                p.SetProperty(Property.ACTION, PdfAction.CreateGoTo(destinationKey));
                document.Add(p);
            }

            int endingTOC = pdf.GetNumberOfPages();

            if (amountPages == null)
            {
                amountPages = (endingTOC - startingTOC) + 1;
            }

            for (int i = 0; i < amountPages.Value; i++)
            {
                var tocPage = pdf.GetLastPage();
                pdf.RemovePage(tocPage);
                if (addAfterRemove && tocPage.IsFlushed() == false)
                {
                    pdf.AddPage(locationToStartTOC, tocPage);
                }
            }
            return(amountPages.Value);
        }
Exemplo n.º 15
0
        private void ManipulatePdf(String dest)
        {
            PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
            Document    doc    = new Document(pdfDoc);

            Table     table = new Table(UnitValue.CreatePercentArray(1)).UseAllAvailableWidth();
            Paragraph p     = new Paragraph();

            p.Add("Left");
            p.AddTabStops(new TabStop(1000, TabAlignment.RIGHT));
            p.Add(new Tab());
            p.Add("Right");
            table.AddCell(p);

            doc.Add(table);

            doc.Close();
        }
Exemplo n.º 16
0
        public static void Create(List <Exam> exams, string path)
        {
            var writer   = new PdfWriter(path);
            var pdf      = new PdfDocument(writer);
            var document = new Document(pdf);

            document.SetMargins(20, 20, 20, 20);

            System.Drawing.ImageConverter converter = new System.Drawing.ImageConverter();
            var       bytes = (byte[])converter.ConvertTo(Properties.Resources.wordLogo, typeof(byte[]));
            Paragraph p     = new Paragraph();
            Image     logo  = new Image(ImageDataFactory.Create(bytes));

            p.Add(logo);
            p.Add(new Tab());
            p.AddTabStops(new TabStop(1000, TabAlignment.RIGHT));
            p.Add(DateTime.Now.ToString("MM/dd/yyyy"));

            document.Add(p);

            var table = new Table(new float[] { 2, 2, 1, 2, 2, 1 });

            table.SetWidth(UnitValue.CreatePercentValue(100));

            table.AddHeaderCell(new Cell().Add(new Paragraph("Zdający")));
            table.AddHeaderCell(new Cell().Add(new Paragraph("Egzaminator")));
            table.AddHeaderCell(new Cell().Add(new Paragraph("Kategoria")));
            table.AddHeaderCell(new Cell().Add(new Paragraph("Data")));
            table.AddHeaderCell(new Cell().Add(new Paragraph("Czas Trwania")));
            table.AddHeaderCell(new Cell().Add(new Paragraph("Wynik")));

            foreach (var exam in exams)
            {
                table.AddCell(new Cell().Add(new Paragraph(exam.Examinee.FullName)));
                table.AddCell(new Cell().Add(new Paragraph(exam.Examiner.FullName)));
                table.AddCell(new Cell().Add(new Paragraph(exam.Category)));
                table.AddCell(new Cell().Add(new Paragraph(exam.Date.ToString("yyyy-MM-dd"))));
                table.AddCell(new Cell().Add(new Paragraph(exam.Duration.ToString("t"))));
                table.AddCell(new Cell().Add(new Paragraph((bool)exam.Result ? "Pozytywny" : "Negatywny")));
            }

            document.Add(table);
            document.Close();
        }
Exemplo n.º 17
0
        public virtual void TablesAndTabInsideOfParagraph()
        {
            String   testName    = "tablesAndTabInsideOfParagraph.pdf";
            String   outFileName = destinationFolder + testName;
            String   cmpFileName = sourceFolder + "cmp_" + testName;
            Document doc         = InitDocument(outFileName, false);
            Table    leftTable   = new Table(1);

            for (int x = 0; x < 3; x++)
            {
                leftTable.AddCell("Table 1, Line " + (x + 1));
            }
            Table rightTable = new Table(1);

            for (int x = 0; x < 3; x++)
            {
                rightTable.AddCell("Table 2, Line " + (x + 1));
            }
            Paragraph p = new Paragraph().Add(leftTable);

            p.Add(new Tab());
            p.AddTabStops(new TabStop(300, TabAlignment.LEFT));
            p.Add(rightTable);
            doc.Add(new Paragraph("TabAlignment: LEFT"));
            doc.Add(p);
            p = new Paragraph().Add(leftTable);
            p.Add(new Tab());
            p.AddTabStops(new TabStop(300, TabAlignment.CENTER));
            p.Add(rightTable);
            doc.Add(new Paragraph("TabAlignment: CENTER"));
            doc.Add(p);
            p = new Paragraph().Add(leftTable);
            p.Add(new Tab());
            p.AddTabStops(new TabStop(300, TabAlignment.RIGHT));
            p.Add(rightTable);
            doc.Add(new Paragraph("TabAlignment: RIGHT"));
            doc.Add(p);
            doc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             , testName + "_diff"));
        }
Exemplo n.º 18
0
        protected void ManipulatePdf(string dest)
        {
            PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
            Document    doc    = new Document(pdfDoc);

            Paragraph p = new Paragraph("Text to the left");

            p.Add(new Tab());
            p.AddTabStops(new TabStop(1000, TabAlignment.RIGHT));
            p.Add("Text to the right");
            doc.Add(p);

            Table table = new Table(UnitValue.CreatePercentArray(3)).UseAllAvailableWidth();

            table.AddCell(GetCell("Text to the left", TextAlignment.LEFT));
            table.AddCell(GetCell("Text in the middle", TextAlignment.CENTER));
            table.AddCell(GetCell("Text to the right", TextAlignment.RIGHT));
            doc.Add(table);

            doc.Close();
        }
Exemplo n.º 19
0
        private void AddTabbedTextToParagraph(Paragraph p, String text, float[] positions, TabAlignment[] alignments
                                              , ILineDrawer[] tabLeadings, char?[] tabAnchorCharacters)
        {
            IList <TabStop> tabStops = new List <TabStop>();

            for (int i = 0; i < positions.Length; ++i)
            {
                TabStop tabStop = new TabStop(positions[i], alignments[i], tabLeadings[i]);
                tabStop.SetTabAnchor(tabAnchorCharacters[i]);
                tabStops.Add(tabStop);
            }
            p.AddTabStops(tabStops);
            foreach (String line in text.Split("\n"))
            {
                foreach (String chunk in line.Split("\t"))
                {
                    p.Add(chunk).Add(new Tab());
                }
                p.Add("\n");
            }
        }
Exemplo n.º 20
0
        protected void ManipulatePdf(string dest)
        {
            PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
            Document    doc    = new Document(pdfDoc);

            Paragraph p = new Paragraph("Ends with dots ");

            p.AddTabStops(new TabStop(523, TabAlignment.RIGHT, new DottedLine()));
            p.Add(new Tab());
            doc.Add(p);

            p = new Paragraph("This is a much longer paragraph that spans "
                              + "several lines. The String used to create this paragraph "
                              + "will be split automatically at the end of the line. The "
                              + "final line of this paragraph will end in a dotted line. ");
            p.AddTabStops(new TabStop(523, TabAlignment.LEFT, new DottedLine()));
            p.Add(new Tab());
            doc.Add(p);

            doc.Close();
        }
Exemplo n.º 21
0
        public virtual void TabsAnchorSemicolonTest03()
        {
            String      outFileName = destinationFolder + "tabsAnchorSemicolonTest03.pdf";
            String      cmpFileName = sourceFolder + "cmp_tabsAnchorSemicolonTest03.pdf";
            PdfDocument pdfDoc      = new PdfDocument(new PdfWriter(outFileName));
            Document    document    = new Document(pdfDoc);
            float       w           = document.GetPageEffectiveArea(PageSize.A4).GetWidth();
            Paragraph   p           = new Paragraph();
            TabStop     tabStop     = new TabStop(w / 2, TabAlignment.ANCHOR);

            tabStop.SetTabAnchor(':');
            p.AddTabStops(tabStop);
            p.Add(new Tab()).Add("Test:Answer");
            document.Add(p);
            p = new Paragraph();
            p.AddTabStops(tabStop);
            p.Add(new Tab()).Add("Test245454:Answer2");
            document.Add(p);
            document.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             , "diff"));
        }
Exemplo n.º 22
0
        private void ManipulatePdf(string dest)
        {
            PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
            Document    doc    = new Document(pdfDoc);

            Table table = new Table(UnitValue.CreatePercentArray(new float[] { 10, 30, 10 }));

            table.SetWidth(UnitValue.CreatePercentValue(50));

            // Creates dotted line leader
            ILineDrawer leader = new DottedLine(1.5f, 6);

            table.AddCell(GetCell(new Paragraph("fig 1"), VerticalAlignment.TOP));

            Paragraph p = new Paragraph("Title text");

            p.AddTabStops(new TabStop(150, TabAlignment.RIGHT, leader));
            p.Add(new Tab());
            table.AddCell(GetCell(p, VerticalAlignment.TOP));
            table.AddCell(GetCell(new Paragraph("2"), VerticalAlignment.BOTTOM));
            table.AddCell(GetCell(new Paragraph("fig 2"), VerticalAlignment.TOP));

            p = new Paragraph("This is a longer title text that wraps");
            p.AddTabStops(new TabStop(150, TabAlignment.RIGHT, leader));
            p.Add(new Tab());
            table.AddCell(GetCell(p, VerticalAlignment.TOP));
            table.AddCell(GetCell(new Paragraph("55"), VerticalAlignment.BOTTOM));
            table.AddCell(GetCell(new Paragraph("fig 3"), VerticalAlignment.TOP));

            p = new Paragraph("Another title text");
            table.AddCell(GetCell(p, VerticalAlignment.TOP));
            p.AddTabStops(new TabStop(150, TabAlignment.RIGHT, leader));
            p.Add(new Tab());
            table.AddCell(GetCell(new Paragraph("89"), VerticalAlignment.BOTTOM));

            doc.Add(table);

            doc.Close();
        }
        public virtual void CreatePdf(String dest)
        {
            PdfDocument pdf      = new PdfDocument(new PdfWriter(dest));
            Document    document = new Document(pdf, PageSize.A4.Rotate());

            float[]         stops    = new float[] { 40, 580, 590, 720 };
            IList <TabStop> tabstops = new List <TabStop>();

            tabstops.Add(new TabStop(stops[0], TabAlignment.LEFT));
            tabstops.Add(new TabStop(stops[1], TabAlignment.RIGHT));
            tabstops.Add(new TabStop(stops[2], TabAlignment.LEFT));
            TabStop anchor = new TabStop(stops[3], TabAlignment.ANCHOR);

            anchor.SetTabAnchor(' ');
            tabstops.Add(anchor);
            PdfCanvas pdfCanvas = new PdfCanvas(pdf.AddNewPage());

            for (int i = 0; i < stops.Length; i++)
            {
                pdfCanvas.MoveTo(document.GetLeftMargin() + stops[i], 0);
                pdfCanvas.LineTo(document.GetLeftMargin() + stops[i], 595);
            }
            pdfCanvas.Stroke();
            IList <IList <String> > resultSet = CsvTo2DList.Convert(SRC, "|");

            foreach (IList <String> record in resultSet)
            {
                Paragraph p = new Paragraph();
                p.AddTabStops(tabstops);
                PdfAction uri  = PdfAction.CreateURI(String.Format("http://www.imdb.com/title/tt{0}", record[0]));
                Link      link = new Link(record[2].Trim(), uri);
                p.Add(record[1].Trim()).Add(new Tab()).Add(link).Add(new Tab()).Add(record[3].Trim()).Add(new Tab()).Add(record
                                                                                                                         [4].Trim()).Add(new Tab()).Add(record[5].Trim() + " \'");
                document.Add(p);
            }
            document.Close();
        }
Exemplo n.º 24
0
        public virtual void CreatePdf(String dest)
        {
            PdfDocument pdf      = new PdfDocument(new PdfWriter(dest));
            Document    document = new Document(pdf, PageSize.A4);

            float[]         stops    = new float[] { 70, 90, 420, 430, 520 };
            IList <TabStop> tabstops = new List <TabStop>();

            tabstops.Add(new TabStop(stops[0], TabAlignment.CENTER, new DottedLine()));
            tabstops.Add(new TabStop(stops[1], TabAlignment.LEFT));
            tabstops.Add(new TabStop(stops[2], TabAlignment.RIGHT, new SolidLine(0.5f)));
            tabstops.Add(new TabStop(stops[3], TabAlignment.LEFT));
            TabStop anchor = new TabStop(stops[4], TabAlignment.ANCHOR, new DashedLine());

            anchor.SetTabAnchor(' ');
            tabstops.Add(anchor);
            PdfCanvas pdfCanvas = new PdfCanvas(pdf.AddNewPage());

            for (int i = 0; i < stops.Length; i++)
            {
                pdfCanvas.MoveTo(document.GetLeftMargin() + stops[i], 0);
                pdfCanvas.LineTo(document.GetLeftMargin() + stops[i], 842);
            }
            pdfCanvas.Stroke();
            IList <IList <String> > resultSet = CsvTo2DList.Convert(SRC, "|");

            foreach (IList <String> record in resultSet)
            {
                Paragraph p = new Paragraph();
                p.AddTabStops(tabstops);
                p.Add(record[0].Trim()).Add(new Tab()).Add(record[1].Trim()).Add(new Tab()).Add(record[2].Trim()).Add(new
                                                                                                                      Tab()).Add(record[3].Trim()).Add(new Tab()).Add(record[4].Trim()).Add(new Tab()).Add(record[5].Trim()
                                                                                                                                                                                                           + " \'");
                document.Add(p);
            }
            document.Close();
        }
Exemplo n.º 25
0
        public void ExportPDF(string ordernr, string adres1, string adres2, string Client, Company comp, float subtotal, string uwagi)
        {
            var exportFolder = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            var exportFile   = System.IO.Path.Combine(exportFolder, "Zamówienie " + ordernr + " " + Client + " " + DateTime.Now.ToString("MM/dd/yyyy") + ".pdf");

            string miasto = "Lodz";
            uint   lp     = 2;

            using (var writer = new PdfWriter(exportFile))
            {
                using (var pdf = new PdfDocument(writer))
                {
                    var doc = new Document(pdf);

                    // Line Separator
                    LineSeparator ls = new LineSeparator(new SolidLine());

                    // New line
                    Paragraph newline = new Paragraph(new Text("\n"));

                    string compInfo = comp.CompanyName + "\n" + comp.Address;
                    // COMPANY NAME
                    Paragraph addresses = new Paragraph();

                    doc.Add(ls);



                    addresses.AddTabStops(new TabStop(1000, TabAlignment.RIGHT));
                    addresses.Add(new Tab());
                    addresses.Add(DateTime.Now.ToString("MM/dd/yyyy") + " " + miasto + "\n");



                    doc.Add(addresses);


                    //TITLE
                    Paragraph title = new Paragraph("WZ " + Client + " " + DateTime.Now.ToString("MM/dd/yyyy"))
                                      .SetTextAlignment(TextAlignment.CENTER)
                                      .SetFontSize(20);
                    doc.Add(newline);
                    doc.Add(newline);
                    doc.Add(title);
                    doc.Add(newline);
                    doc.Add(newline);
                    doc.Add(newline);
                    doc.Add(newline);

                    // COMPANYS DATA

                    // COMPANY NAME
                    Paragraph temp = new Paragraph()
                                     .SetTextAlignment(TextAlignment.LEFT)
                                     .SetFontSize(10);

                    temp.AddTabStops(new TabStop(1000, TabAlignment.RIGHT));
                    temp.Add("Firma");
                    temp.Add(new Tab());
                    temp.Add(Client + "\n");
                    temp.Add("Sloneczna 56");
                    temp.Add(new Tab());
                    temp.Add(adres1 + "\n");
                    temp.Add("Lodz, 98-765");
                    temp.Add(new Tab());
                    temp.Add(adres2 + "\n");

                    doc.Add(temp);


                    Table table = new Table(5);
                    table.SetWidth(UnitValue.CreatePercentValue(100));
                    table.SetBorder(Border.NO_BORDER);


                    // info to table
                    Cell[] info = new Cell[5 * (lp + 1)];

                    string[] inf = { "lp.", "Nazwa towaru", "ilosc", "Jm", "Uwagi" };

                    for (int i = 0; i < 5; i++)
                    {
                        Cell c = new Cell(1, 1)
                                 .SetBackgroundColor(ColorConstants.GRAY)
                                 .SetTextAlignment(TextAlignment.LEFT)
                                 .SetBorder(Border.NO_BORDER)
                                 .Add(new Paragraph(inf[i]));
                        info[i] = c;
                        table.AddCell(info[i]);
                    }

                    /* List<Cell> pos = new List<Cell>();*/
                    Cell[] pos = new Cell[5 * (lp + 1)];


                    for (int j = 0; j < lp; j++)
                    {
                        for (int i = 0; i < 5; i++)
                        {
                            Cell dat = new Cell(1, 1)
                                       .SetBackgroundColor(ColorConstants.WHITE)
                                       .SetTextAlignment(TextAlignment.RIGHT)
                                       .SetBorder(Border.NO_BORDER)
                                       .Add(new Paragraph("co"));
                            pos[i] = dat;
                            table.AddCell(pos[i]);
                        }
                    }
                    table.SetTextAlignment(TextAlignment.CENTER);
                    doc.Add(table);


                    doc.Add(newline);
                    doc.Add(newline);
                    doc.Add(newline);
                    doc.Add(newline);
                    doc.Add(newline);

                    string dot = "...............................";

                    Paragraph d = new Paragraph(dot)
                                  .SetTextAlignment(TextAlignment.LEFT)
                                  .SetFontSize(10);

                    d.Add(new Tab());

                    d.AddTabStops(new TabStop(1000, TabAlignment.RIGHT));
                    d.Add(dot);
                    doc.Add(d);


                    string spr = "Towar Sprawdzil i odebral";
                    string odb = "Towar wydal";

                    Paragraph sprodb = new Paragraph(spr)
                                       .SetTextAlignment(TextAlignment.LEFT)
                                       .SetFontSize(10);

                    sprodb.Add(new Tab());

                    sprodb.AddTabStops(new TabStop(1000, TabAlignment.RIGHT));
                    sprodb.Add(odb);
                    doc.Add(sprodb);
                }
            }
        }
Exemplo n.º 26
0
        public static void Write()
        {
            PdfDocument pdfDoc = new PdfDocument(new PdfWriter("D:\\output.pdf"));
            Document    doc    = new Document(pdfDoc, PageSize.A4);

            doc.SetMargins(CentimeterToPoint(10f), CentimeterToPoint(0.8f), CentimeterToPoint(1f), CentimeterToPoint(1.2f));
            PdfFont font = PdfFontFactory.CreateFont(FONT, PdfEncodings.IDENTITY_H, false);

            PageXofY e = new PageXofY(pdfDoc);

            pdfDoc.AddEventHandler(PdfDocumentEvent.END_PAGE, e);



            Paragraph title = new Paragraph("设计成果交接单");

            title.SetWidth(CentimeterToPoint(19f));
            title.SetFont(font);
            title.SetTextAlignment(TextAlignment.CENTER);
            doc.Add(title);

            Paragraph p = new Paragraph();

            p.SetWidth(CentimeterToPoint(19f));
            p.SetFont(font);
            p.SetTextAlignment(TextAlignment.JUSTIFIED);

            Text t1 = new Text("编号:");

            t1.SetTextAlignment(TextAlignment.LEFT);

            TabStop tab = new TabStop(12f, TabAlignment.RIGHT);

            Text t2 = new Text("日期:" + DateTime.Now.ToString("yyyy年MM月dd日"));

            t2.SetTextAlignment(TextAlignment.RIGHT);

            p.Add(t1);
            p.AddTabStops(tab);
            p.Add(t2);
            doc.Add(p);

            Table table1 = new Table(new float[] {
                CentimeterToPoint(2.35f),
                CentimeterToPoint(4f),
                CentimeterToPoint(2.35f),
                CentimeterToPoint(4f),
                CentimeterToPoint(2.3f),
                CentimeterToPoint(4f)
            });

            table1.SetWidth(CentimeterToPoint(19f));

            Cell cell1 = new Cell();

            cell1.SetFont(font);
            cell1.Add(new Paragraph("项目名称"));
            table1.AddCell(cell1);

            Cell cell2 = new Cell(1, 5);

            cell2.SetFont(font);
            table1.AddCell(cell2);

            Cell cell3 = new Cell();

            cell3.SetFont(font);
            cell3.Add(new Paragraph("建设单位"));
            table1.AddCell(cell3);

            Cell cell4 = new Cell(1, 5);

            cell4.SetFont(font);
            table1.AddCell(cell4);

            Cell cell5 = new Cell();

            cell5.SetFont(font);
            cell5.Add(new Paragraph("设计部门"));
            table1.AddCell(cell5);

            Cell cel6 = new Cell();

            cel6.SetFont(font);
            table1.AddCell(cel6);

            Cell cel7 = new Cell();

            cel7.SetFont(font);
            cel7.Add(new Paragraph("设计号"));
            table1.AddCell(cel7);

            Cell cel8 = new Cell();

            cel8.SetFont(font);
            table1.AddCell(cel8);


            Cell cel9 = new Cell();

            cel9.SetFont(font);
            cel9.Add(new Paragraph("项目负责人"));
            table1.AddCell(cel9);

            Cell cel10 = new Cell();

            cel10.SetFont(font);
            table1.AddCell(cel10);

            Cell cell = new Cell(1, 6);

            cell.Add(new Paragraph("成果类别及数量"));
            cell.SetFont(font);
            cell.SetTextAlignment(TextAlignment.CENTER);
            table1.AddCell(cell);

            doc.Add(table1);

            Table table = new Table(new float[] {
                CentimeterToPoint(1.5f),
                CentimeterToPoint(4f),
                CentimeterToPoint(3f),
                CentimeterToPoint(1f),
                CentimeterToPoint(1f),
                CentimeterToPoint(1f),
                CentimeterToPoint(1f),
                CentimeterToPoint(1f),
                CentimeterToPoint(1.5f),
                CentimeterToPoint(4f)
            });

            table.SetWidth(CentimeterToPoint(19f));


            Cell seq = new Cell();

            seq.SetFont(font);
            seq.SetTextAlignment(TextAlignment.CENTER);
            seq.Add(new Paragraph("序号"));
            table.AddHeaderCell(seq);

            Cell name = new Cell();

            name.SetFont(font);
            name.SetTextAlignment(TextAlignment.CENTER);
            name.Add(new Paragraph("名称"));
            table.AddHeaderCell(name);

            Cell subject = new Cell();

            subject.SetFont(font);
            subject.SetTextAlignment(TextAlignment.CENTER);
            subject.Add(new Paragraph("专业"));
            table.AddHeaderCell(subject);

            Cell A0 = new Cell();

            A0.SetFont(font);
            A0.SetTextAlignment(TextAlignment.CENTER);
            A0.Add(new Paragraph("A0"));
            table.AddHeaderCell(A0);

            Cell A1 = new Cell();

            A1.SetFont(font);
            A1.SetTextAlignment(TextAlignment.CENTER);
            A1.Add(new Paragraph("A1"));
            table.AddHeaderCell(A1);

            Cell A2 = new Cell();

            A2.SetFont(font);
            A2.SetTextAlignment(TextAlignment.CENTER);
            A2.Add(new Paragraph("A2"));
            table.AddHeaderCell(A2);

            Cell A3 = new Cell();

            A3.SetFont(font);
            A3.SetTextAlignment(TextAlignment.CENTER);
            A3.Add(new Paragraph("A3"));
            table.AddHeaderCell(A3);

            Cell A4 = new Cell();

            A4.SetFont(font);
            A4.SetTextAlignment(TextAlignment.CENTER);
            A4.Add(new Paragraph("A4"));
            table.AddHeaderCell(A4);

            Cell Copies = new Cell();

            Copies.SetFont(font);
            Copies.SetTextAlignment(TextAlignment.CENTER);
            Copies.Add(new Paragraph("份数"));
            table.AddHeaderCell(Copies);

            Cell comments = new Cell();

            comments.SetFont(font);
            comments.SetTextAlignment(TextAlignment.CENTER);
            comments.Add(new Paragraph("备注"));
            table.AddHeaderCell(comments);


            for (int i = 1; i < 101; i++)
            {
                table.AddCell(i.ToString());
                table.AddCell(string.Empty);
                table.AddCell(string.Empty);
                table.AddCell(string.Empty);
                table.AddCell(string.Empty);
                table.AddCell(string.Empty);
                table.AddCell(string.Empty);
                table.AddCell(string.Empty);
                table.AddCell(string.Empty);
                table.AddCell(string.Empty);
            }
            doc.Add(table);

            e.WriteTotal(pdfDoc);


            doc.Close();

            //pdfDoc.GetWriter().GetOutputStream().
            //PrintQueue queue = LocalPrintServer.GetDefaultPrintQueue();
            //using (PrintSystemJobInfo job = queue.AddJob())
            //{
            //    using (Stream stream = job.JobStream)
            //    {
            //        stream.Write()
            //    }
            //}
        }
Exemplo n.º 27
0
        protected void ManipulatePdf(String dest)
        {
            MemoryStream baos   = new MemoryStream();
            PdfDocument  pdfDoc = new PdfDocument(new PdfWriter(baos));
            Document     doc    = new Document(pdfDoc);

            // Copier contains the additional logic to copy acroform fields to a new page.
            // PdfPageFormCopier uses some caching logic which can potentially improve performance
            // in case of the reusing of the same instance.
            PdfPageFormCopier formCopier = new PdfPageFormCopier();

            // Copy all merging file's pages to the temporary pdf file
            Dictionary <String, PdfDocument> filesToMerge = InitializeFilesToMerge();
            Dictionary <int, String>         toc          = new Dictionary <int, String>();
            int page = 1;

            foreach (KeyValuePair <String, PdfDocument> entry in filesToMerge)
            {
                PdfDocument srcDoc        = entry.Value;
                int         numberOfPages = srcDoc.GetNumberOfPages();

                toc.Add(page, entry.Key);

                for (int i = 1; i <= numberOfPages; i++, page++)
                {
                    Text text = new Text(String.Format("Page {0}", page));
                    srcDoc.CopyPagesTo(i, i, pdfDoc, formCopier);

                    // Put the destination at the very first page of each merged document
                    if (i == 1)
                    {
                        text.SetDestination("p" + page);

                        PdfOutline rootOutLine = pdfDoc.GetOutlines(false);
                        PdfOutline outline     = rootOutLine.AddOutline("p" + page);
                        outline.AddDestination(PdfDestination.MakeDestination(new PdfString("p" + page)));
                    }

                    doc.Add(new Paragraph(text)
                            .SetFixedPosition(page, 549, 810, 40)
                            .SetMargin(0)
                            .SetMultipliedLeading(1));
                }
            }

            PdfDocument tocDoc = new PdfDocument(new PdfReader(SRC3));

            tocDoc.CopyPagesTo(1, 1, pdfDoc, formCopier);
            tocDoc.Close();

            // Create a table of contents
            float tocYCoordinate = 750;
            float tocXCoordinate = doc.GetLeftMargin();
            float tocWidth       = pdfDoc.GetDefaultPageSize().GetWidth() - doc.GetLeftMargin() - doc.GetRightMargin();

            foreach (KeyValuePair <int, String> entry in toc)
            {
                Paragraph p = new Paragraph();
                p.AddTabStops(new TabStop(500, TabAlignment.LEFT, new DashedLine()));
                p.Add(entry.Value);
                p.Add(new Tab());
                p.Add(entry.Key.ToString());
                p.SetAction(PdfAction.CreateGoTo("p" + entry.Key));
                doc.Add(p
                        .SetFixedPosition(pdfDoc.GetNumberOfPages(), tocXCoordinate, tocYCoordinate, tocWidth)
                        .SetMargin(0)
                        .SetMultipliedLeading(1));

                tocYCoordinate -= 20;
            }

            foreach (PdfDocument srcDocument in filesToMerge.Values)
            {
                srcDocument.Close();
            }

            doc.Close();

            PdfDocument resultDoc = new PdfDocument(new PdfWriter(dest));
            PdfDocument srcPdfDoc = new PdfDocument(new PdfReader(new MemoryStream(baos.ToArray()),
                                                                  new ReaderProperties()));

            srcPdfDoc.InitializeOutlines();

            // Create a copy order list and set the page with a table of contents as the first page
            int        tocPageNumber      = srcPdfDoc.GetNumberOfPages();
            List <int> copyPagesOrderList = new List <int>();

            copyPagesOrderList.Add(tocPageNumber);
            for (int i = 1; i < tocPageNumber; i++)
            {
                copyPagesOrderList.Add(i);
            }

            srcPdfDoc.CopyPagesTo(copyPagesOrderList, resultDoc, formCopier);

            srcPdfDoc.Close();
            resultDoc.Close();
        }
Exemplo n.º 28
0
        public static string PrintManaulInvoice(ReceiptHeader header, ReceiptItemTotal itemTotals, ReceiptDetails details, List <ReceiptItemDetails> itemDetail, bool isRePrint = true)
        {
            try
            {
                string fName    = "MInvoiceNo_" + details.BillNo.Substring(9) + ".pdf";
                string fileName = Path.Combine("wwwroot", fName);


                using PdfWriter pdfWriter = new PdfWriter(fileName);
                using PdfDocument pdf     = new PdfDocument(pdfWriter);

                Document pdfDoc = new Document(pdf, new PageSize(240, 1170));

                pdfDoc.SetMargins(10, 5, 10, 5);

                Style   code       = new Style();
                PdfFont timesRoman = PdfFontFactory.CreateFont(iText.IO.Font.Constants.StandardFonts.TIMES_ROMAN);
                code.SetFont(timesRoman).SetFontSize(12);

                //Header
                Paragraph p = new Paragraph(header.StoreName + "\n").SetFontSize(12);
                p.SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER);
                p.Add(header.StoreAddress + "\n");
                p.Add(header.StoreCity + "\n");
                p.Add("Ph No: " + header.StorePhoneNo + "\n");
                p.Add(header.StoreGST + "\n");

                pdfDoc.Add(p);

                //Details
                Paragraph ip = new Paragraph().SetFontSize(12);

                ip.Add(PrintInvoiceLine.DotedLine);
                ip.AddTabStops(new TabStop(50));
                ip.Add(" " + PrintInvoiceLine.InvoiceTitle + "\n");
                ip.Add(PrintInvoiceLine.DotedLine);
                ip.Add(ReceiptDetails.Employee + "\n");
                ip.Add(details.BillNo + "\n");
                ip.AddTabStops(new TabStop(30));
                ip.Add("  " + details.BillDate + "\n");
                ip.AddTabStops(new TabStop(30));
                ip.Add("  " + details.BillTime + "\n");


                ip.Add(details.CustomerName + "\n");
                ip.Add(PrintInvoiceLine.DotedLine);

                ip.Add(PrintInvoiceLine.ItemLineHeader1 + "\n");
                ip.Add(PrintInvoiceLine.ItemLineHeader2 + "\n");

                ip.Add(PrintInvoiceLine.DotedLine);


                double gstPrice   = 0.00;
                double basicPrice = 0.00;
                string tab        = "    ";

                foreach (ReceiptItemDetails itemDetails in itemDetail)
                {
                    if (itemDetails != null)
                    {
                        ip.Add(itemDetails.SKUDescription + itemDetails.HSN + "/\n");
                        ip.Add(itemDetails.MRP + tab + tab);
                        ip.Add(itemDetails.QTY + tab + tab + itemDetails.Discount + tab + tab + itemDetails.Amount);
                        //ip.Add(itemDetails.GSTPercentage + "%" + tab + tab + itemDetails.GSTAmount + tab + tab);
                        //ip.Add(itemDetails.GSTPercentage + "%" + tab + tab + itemDetails.GSTAmount + "\n");
                        gstPrice   += Double.Parse(itemDetails.GSTAmount);
                        basicPrice += Double.Parse(itemDetails.BasicPrice);
                    }
                }

                ip.Add("\n" + PrintInvoiceLine.DotedLine);

                ip.Add("Total: " + itemTotals.TotalItem + tab + tab + tab + tab + tab + itemTotals.NetAmount + "\n");
                ip.Add("item(s): " + itemTotals.ItemCount + tab + "Net Amount:" + tab + itemTotals.NetAmount + "\n");
                ip.Add(PrintInvoiceLine.DotedLine);

                ip.Add("Tender(s)\n Paid Amount:\t\t Rs. " + itemTotals.CashAmount); //TODO: cash/Card option can be changed here

                // ip.Add("\n" + PrintInvoiceLine.DotedLine);
                //ip.Add("Basic Price:\t\t" + basicPrice.ToString("0.##"));
                //ip.Add("\nCGST:\t\t" + gstPrice.ToString("0.##"));
                //ip.Add("\nSGST:\t\t" + gstPrice.ToString("0.##") + "\n");
                //ip.Add (PrintLine.DotedLine);
                pdfDoc.Add(ip);

                //Footer
                Paragraph foot = new Paragraph().SetFontSize(12);
                //foot.SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER);
                foot.Add(PrintInvoiceLine.FooterFirstMessage + "\n");
                foot.Add(PrintInvoiceLine.DotedLine);
                foot.Add(PrintInvoiceLine.FooterThanksMessage + "\n");
                foot.Add(PrintInvoiceLine.FooterLastMessage + "\n");
                foot.Add(PrintInvoiceLine.DotedLine);
                foot.Add("\n");// Just to Check;
                if (isRePrint)
                {
                    foot.Add("(Reprinted)\n");
                }
                foot.Add("Printed on: " + DateTime.Now + "\n");
                pdfDoc.Add(foot);
                pdfDoc.Close();

                //Print to Default Local Added Printer
                // PrintPDFLocal(fileName);
                return(fName);
            }
            catch (Exception exp)
            {
                return(exp.Message);
            }
        }
        public virtual void CreatePdf(String dest)
        {
            PdfDocument pdfDoc   = new PdfDocument(new PdfWriter(dest));
            Document    document = new Document(pdfDoc);

            document.Add(new Paragraph(new Text("The Revenant nominations list")).SetTextAlignment(TextAlignment.CENTER
                                                                                                   ));
            PdfDocument firstSourcePdf = new PdfDocument(new PdfReader(SRC1));

            foreach (KeyValuePair <String, int> entry in TheRevenantNominations)
            {
                //Copy page
                PdfPage page = firstSourcePdf.GetPage(entry.Value).CopyTo(pdfDoc);
                pdfDoc.AddPage(page);
                //Overwrite page number
                Text text = new Text(String.Format("Page {0}", pdfDoc.GetNumberOfPages() - 1));
                text.SetBackgroundColor(ColorConstants.WHITE);
                document.Add(new Paragraph(text).SetFixedPosition(pdfDoc.GetNumberOfPages(), 549, 742, 100));
                //Add destination
                String   destinationKey   = "p" + (pdfDoc.GetNumberOfPages() - 1);
                PdfArray destinationArray = new PdfArray();
                destinationArray.Add(page.GetPdfObject());
                destinationArray.Add(PdfName.XYZ);
                destinationArray.Add(new PdfNumber(0));
                destinationArray.Add(new PdfNumber(page.GetMediaBox().GetHeight()));
                destinationArray.Add(new PdfNumber(1));
                pdfDoc.AddNamedDestination(destinationKey, destinationArray);
                //Add TOC line with bookmark
                Paragraph p = new Paragraph();
                p.AddTabStops(new TabStop(540, TabAlignment.RIGHT, new DottedLine()));
                p.Add(entry.Key);
                p.Add(new Tab());
                p.Add((pdfDoc.GetNumberOfPages() - 1).ToString());
                p.SetProperty(Property.ACTION, PdfAction.CreateGoTo(destinationKey));
                document.Add(p);
            }
            firstSourcePdf.Close();
            //Add the last page
            PdfDocument secondSourcePdf = new PdfDocument(new PdfReader(SRC2));
            PdfPage     page_1          = secondSourcePdf.GetPage(1).CopyTo(pdfDoc);

            pdfDoc.AddPage(page_1);
            //Add destination
            PdfArray destinationArray_1 = new PdfArray();

            destinationArray_1.Add(page_1.GetPdfObject());
            destinationArray_1.Add(PdfName.XYZ);
            destinationArray_1.Add(new PdfNumber(0));
            destinationArray_1.Add(new PdfNumber(page_1.GetMediaBox().GetHeight()));
            destinationArray_1.Add(new PdfNumber(1));
            pdfDoc.AddNamedDestination("checklist", destinationArray_1);
            //Add TOC line with bookmark
            Paragraph p_1 = new Paragraph();

            p_1.AddTabStops(new TabStop(540, TabAlignment.RIGHT, new DottedLine()));
            p_1.Add("Oscars\u00ae 2016 Movie Checklist");
            p_1.Add(new Tab());
            p_1.Add((pdfDoc.GetNumberOfPages() - 1).ToString());
            p_1.SetProperty(Property.ACTION, PdfAction.CreateGoTo("checklist"));
            document.Add(p_1);
            secondSourcePdf.Close();
            // close the document
            document.Close();
        }
Exemplo n.º 30
0
        protected void ManipulatePdf(String dest)
        {
            PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
            Document    doc    = new Document(pdfDoc);

            // Initialize a resultant document outlines in order to copy outlines from the source documents.
            // Note that outlines still could be copied even if in destination document outlines
            // are not initialized, by using PdfMerger with mergeOutlines vakue set as true
            pdfDoc.InitializeOutlines();

            // Copier contains the additional logic to copy acroform fields to a new page.
            // PdfPageFormCopier uses some caching logic which can potentially improve performance
            // in case of the reusing of the same instance.
            PdfPageFormCopier formCopier = new PdfPageFormCopier();

            // Copy all merging file's pages to the result pdf file
            Dictionary <String, PdfDocument> filesToMerge = InitializeFilesToMerge();
            Dictionary <int, String>         toc          = new Dictionary <int, String>();
            int page = 1;

            foreach (KeyValuePair <String, PdfDocument> entry in filesToMerge)
            {
                PdfDocument srcDoc        = entry.Value;
                int         numberOfPages = srcDoc.GetNumberOfPages();

                toc.Add(page, entry.Key);

                for (int i = 1; i <= numberOfPages; i++, page++)
                {
                    Text text = new Text(String.Format("Page {0}", page));
                    srcDoc.CopyPagesTo(i, i, pdfDoc, formCopier);

                    // Put the destination at the very first page of each merged document
                    if (i == 1)
                    {
                        text.SetDestination("p" + page);
                    }

                    doc.Add(new Paragraph(text).SetFixedPosition(page, 549, 810, 40)
                            .SetMargin(0)
                            .SetMultipliedLeading(1));
                }
            }

            PdfDocument tocDoc = new PdfDocument(new PdfReader(SRC3));

            tocDoc.CopyPagesTo(1, 1, pdfDoc, formCopier);
            tocDoc.Close();

            // Create a table of contents
            float tocYCoordinate = 750;
            float tocXCoordinate = doc.GetLeftMargin();
            float tocWidth       = pdfDoc.GetDefaultPageSize().GetWidth() - doc.GetLeftMargin() - doc.GetRightMargin();

            foreach (KeyValuePair <int, String> entry in toc)
            {
                Paragraph p = new Paragraph();
                p.AddTabStops(new TabStop(500, TabAlignment.LEFT, new DashedLine()));
                p.Add(entry.Value);
                p.Add(new Tab());
                p.Add(entry.Key.ToString());
                p.SetAction(PdfAction.CreateGoTo("p" + entry.Key));
                doc.Add(p.SetFixedPosition(pdfDoc.GetNumberOfPages(), tocXCoordinate, tocYCoordinate, tocWidth)
                        .SetMargin(0)
                        .SetMultipliedLeading(1));

                tocYCoordinate -= 20;
            }

            foreach (PdfDocument srcDoc in filesToMerge.Values)
            {
                srcDoc.Close();
            }

            doc.Close();
        }