Example #1
0
        public PDocument(string fileFullName, HDocument hDocument)
        {
            /*
             * //DEBUG
             * PDocument_debug(fileFullName, hDocument);
             * return;
             */


            bodyNode = hDocument.BodyNode;

            pageTextState = PUtil.TextStateUtil.TextState_Default();
            PUtil.TextStateUtil.TextState_ModifyFromHStyles((bodyNode as HNodeTag).Styles, pageTextState);

            pageMargin     = new MarginInfo(4, 4, 4, 12);
            pageBackground = Aspose.Pdf.Color.FromRgb(1.00, 1.00, 1.00);

            pdfDocument           = new Document();
            pdfPage               = null;
            pdfTextFragment       = null;
            pdfImage              = null;
            hyperlinkNode         = null;
            pdfNewLine            = null;
            inlineParagraphMargin = null;
            pdfFormField          = null;
            pdfRadioButtonFields  = new Dictionary <string, RadioButtonField>();

            updateCurrentPage();
            createBody();

            pdfDocument.Save(fileFullName);
        }
        private static void CreateSectionFourExample001(PdfBuilder pdfBuilder, MarginInfo parentPadding)
        {
            const string columnWidths = "350 100";
            var          descriptions = new List <string[]> {
                new [] { "[ex code 01]", "ex foo", "cm" }, new [] { "[ex code 02]", "ex foo", "mm" }
            };

            if (descriptions.IsAny())
            {
                // Create an inner table
                var sectionFourExampleTable = pdfBuilder.CreateInnerTable(
                    columnWidths,
                    keepContentTogether: true);

                // Create inner table row
                var projectFundedServicesRow = pdfBuilder.CreateInnerTableRow(sectionFourExampleTable, parentPadding);

                // Create Header Cell Titles
                pdfBuilder.CreateInnerTableItemCells(
                    projectFundedServicesRow,
                    cellContent: new[] {
                    new DisplayCell {
                        Content = "Example Code", IsHeader = true
                    },
                    new DisplayCell {
                        Content = "Example Measure", IsHeader = true
                    }
                });

                // create a row for each description
                foreach (var item in descriptions)
                {
                    pdfBuilder.CreateInnerTableItemCells(
                        sectionFourExampleTable.Rows.Add(),
                        cellContent: new[] {
                        new DisplayCell {
                            Content = item[0] + " - " + item[1]
                        },
                        new DisplayCell {
                            Content = item[2]
                        }
                    });
                }
            }
            pdfBuilder.BlankRow();
        }
Example #3
0
		public Aspose.Pdf.Generator.Pdf GetTicket(PassengerInfo passengerInfo, FlightInfo flightInfo, BookingInfo bookingInfo)
		{
            
            Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();
			pdf.IsTruetypeFontMapCached = false;
            			
            pdf.Sections.Add();
            MarginInfo marginInfo = new MarginInfo();
            marginInfo.Top = 50;
            marginInfo.Left = 50;
            marginInfo.Right = 50;

            pdf.Sections[0].PageInfo.Margin = marginInfo;

            PutOrder(pdf, passengerInfo, flightInfo, bookingInfo);

            return pdf;
		}
Example #4
0
        public Aspose.Pdf.Generator.Pdf GetTicket(PassengerInfo passengerInfo, FlightInfo flightInfo, BookingInfo bookingInfo)
        {
            Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();
            pdf.IsTruetypeFontMapCached = false;

            pdf.Sections.Add();
            MarginInfo marginInfo = new MarginInfo();

            marginInfo.Top   = 50;
            marginInfo.Left  = 50;
            marginInfo.Right = 50;

            pdf.Sections[0].PageInfo.Margin = marginInfo;

            PutOrder(pdf, passengerInfo, flightInfo, bookingInfo);

            return(pdf);
        }
        public void AsposePdfBuilderShouldGenerateExample001()
        {
            // Arrange
            const string exampleHeaderText = "Example Header Text Title";
            const string exampleFooterText = "All Rights Reserved Footer Example © 2016";
            var          pdfBuilder        = PdfBuilderFactory.CreateAsposePdfBuilder();

            // set license, if available - e.g.
            var licensePath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "App_Data", "Aspose.Pdf.lic");

            PdfBuilderFactory.SetAsposeLicense(licensePath);

            // this is optional padding to be applied to all elements
            var parentPadding = new MarginInfo
            {
                Top    = 2,
                Bottom = 2,
                Left   = 2
            };

            // create sections of pdf
            CreateSectionOneExample001(pdfBuilder, parentPadding);
            CreateSectionTwoExample001(pdfBuilder, parentPadding);
            CreateSectionThreeExample001(pdfBuilder, parentPadding);
            CreateSectionFourExample001(pdfBuilder, parentPadding);
            CreateSectionFiveExample001(pdfBuilder, parentPadding);

            // create a header and footer for each section (page) in the pdf - also creates 'Page 1 of x' numbering.
            pdfBuilder.CreateHeaderAndFooterForPdf(exampleHeaderText, exampleFooterText);

            // Act - generate the pdf
            var generatedPdf = pdfBuilder.SaveFileStream();

            // Assert
            Assert.IsNotNull(generatedPdf);
            Assert.IsTrue(generatedPdf.Length > 0);

            // write file output so we can view it.
            var filename = GetTemporaryFileName("Example_001");

            File.WriteAllBytes(filename, generatedPdf);
        }
        public void AsposePdfBuilderShouldGenerateExample001()
        {
            // Arrange
            const string exampleHeaderText = "Example Header Text Title";
            const string exampleFooterText = "All Rights Reserved Footer Example © 2016";
            var pdfBuilder = PdfBuilderFactory.CreateAsposePdfBuilder();
            
            // set license, if available - e.g.
            var licensePath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "App_Data", "Aspose.Pdf.lic");
            PdfBuilderFactory.SetAsposeLicense(licensePath);
            
            // this is optional padding to be applied to all elements
            var parentPadding = new MarginInfo
            {
                Top = 2,
                Bottom = 2,
                Left = 2
            };

            // create sections of pdf
            CreateSectionOneExample001(pdfBuilder, parentPadding);
            CreateSectionTwoExample001(pdfBuilder, parentPadding);
            CreateSectionThreeExample001(pdfBuilder, parentPadding);
            CreateSectionFourExample001(pdfBuilder, parentPadding);
            CreateSectionFiveExample001(pdfBuilder, parentPadding);

            // create a header and footer for each section (page) in the pdf - also creates 'Page 1 of x' numbering.
            pdfBuilder.CreateHeaderAndFooterForPdf(exampleHeaderText, exampleFooterText);

            // Act - generate the pdf
            var generatedPdf = pdfBuilder.SaveFileStream();
            
            // Assert
            Assert.IsNotNull(generatedPdf);
            Assert.IsTrue(generatedPdf.Length > 0);

            // write file output so we can view it.
            var filename = GetTemporaryFileName("Example_001");
            File.WriteAllBytes(filename, generatedPdf);
        }
        private static void CreateSectionFiveExample001(PdfBuilder pdfBuilder, MarginInfo parentPadding)
        {
            var secionFiveExampleTable = pdfBuilder.CreateOuterTable(
                "140 310",
                Resources.ArialFont,
                PdfBuilder.DefaultHeadingTwoFontSize,
                parentPadding,
                keepContentTogether: true);

            // create table row heading
            pdfBuilder.CreateOuterTableRowHeading(
                secionFiveExampleTable,
                "Example Section 5 Heading");

            pdfBuilder.BlankRow(secionFiveExampleTable);

            // Create dates
            var exampleItem01Row = secionFiveExampleTable.Rows.Add();

            pdfBuilder.CreateOuterTableRowCells(
                exampleItem01Row,
                "Example item 01",
                DateTime.Now.ToShortDateString(),
                padding: PdfBuilder.DefaultSubHeadingBottomPadding);

            var exampleItem02Row = secionFiveExampleTable.Rows.Add();

            pdfBuilder.CreateOuterTableRowCells(
                exampleItem02Row,
                "Example item 02",
                "example info",
                padding: PdfBuilder.DefaultSubHeadingBottomPadding);

            var exampleItem03Row = secionFiveExampleTable.Rows.Add();

            pdfBuilder.CreateOuterTableRowCells(
                exampleItem03Row,
                "Example item 03",
                "example info",
                padding: PdfBuilder.DefaultSubHeadingBottomPadding);

            var exampleItem04Row = secionFiveExampleTable.Rows.Add();

            pdfBuilder.CreateOuterTableRowCells(
                exampleItem04Row,
                "Example item 04",
                "example info",
                padding: PdfBuilder.DefaultSubHeadingBottomPadding);

            pdfBuilder.BlankRow(secionFiveExampleTable);

            // create an overly complex arrangement of data and values to demonstrate the flexibility of the aspose pdf builder.
            var orderedNumbers      = new[] { "0001", "0002", "0003" };
            var examplePairsAsGroup = new List <KeyValuePair <string, decimal> >
            {
                new KeyValuePair <string, decimal>(orderedNumbers[0], 10000),
                new KeyValuePair <string, decimal>(orderedNumbers[0], 10000),
                new KeyValuePair <string, decimal>(orderedNumbers[0], 10000),
                new KeyValuePair <string, decimal>(orderedNumbers[1], 20000),
                new KeyValuePair <string, decimal>(orderedNumbers[1], 20000),
                new KeyValuePair <string, decimal>(orderedNumbers[1], 20000),
                new KeyValuePair <string, decimal>(orderedNumbers[2], 30000),
                new KeyValuePair <string, decimal>(orderedNumbers[2], 30000),
                new KeyValuePair <string, decimal>(orderedNumbers[2], 30000)
            }.OrderBy(x => x.Key)
            .GroupBy(x => x.Key)
            .ToArray();

            // calculate totals - terrible example...
            var orderedNumbers0001   = examplePairsAsGroup.SelectMany(x => x).Where(x => x.Key == orderedNumbers[0]).ToArray();
            var orderedNumbers0002   = examplePairsAsGroup.SelectMany(x => x).Where(x => x.Key == orderedNumbers[1]).ToArray();
            var orderedNumbers0003   = examplePairsAsGroup.SelectMany(x => x).Where(x => x.Key == orderedNumbers[2]).ToArray();
            var exampleTotalsAsGroup = new List <KeyValuePair <string, decimal> >
            {
                new KeyValuePair <string, decimal>(orderedNumbers[0], orderedNumbers0001[0].Value + orderedNumbers0002[0].Value + orderedNumbers0003[0].Value),
                new KeyValuePair <string, decimal>(orderedNumbers[1], orderedNumbers0001[1].Value + orderedNumbers0002[1].Value + orderedNumbers0003[1].Value),
                new KeyValuePair <string, decimal>(orderedNumbers[2], orderedNumbers0001[2].Value + orderedNumbers0002[2].Value + orderedNumbers0003[2].Value)
            }.OrderBy(x => x.Key)
            .GroupBy(x => x.Key)
            .ToArray();

            var useWidths = "53 80 79 79 80 79"; // remember - a user can specify less or more columns and pass them into CreateInnerTable.
            // Create an inner table
            var exampleInnerTable = pdfBuilder.CreateInnerTable(useWidths, secionFiveExampleTable);

            // Create Header Inner Table row
            var exampleInnerHeaderRow = pdfBuilder.CreateInnerTableRow(exampleInnerTable, parentPadding);

            // Create Header Cell Titles
            var titles = new List <HeaderCell> {
                new HeaderCell {
                    Content = "Side Content Name"
                }
            };
            var additionalNames = new [] { "example 01", "example 02", "example 03" }.GroupBy(x => x).ToArray();

            titles.AddRange(additionalNames.Select(name => new HeaderCell {
                Content = "ex name " + name.Key
            }));
            titles.Add(new HeaderCell {
                Content = "Total"
            });
            pdfBuilder.CreateInnerTableHeaderCells(exampleInnerHeaderRow, titles.ToArray());

            // Display example pairs by their ordered numbers
            foreach (var epag in examplePairsAsGroup)
            {
                var cellContentByFy = new List <DisplayCell> {
                    new DisplayCell {
                        Content = epag.Key, IsDate = true
                    }
                };
                cellContentByFy.AddRange(epag.Select(x => new DisplayCell {
                    Content = x.Value.ToString("C"), IsCurrency = true
                }).ToArray());
                cellContentByFy.Add(new DisplayCell {
                    Content = epag.Sum(x => x.Value).ToString("C"), IsCurrency = true
                });

                var itemRow = pdfBuilder.CreateInnerTableRow(exampleInnerTable, parentPadding);
                pdfBuilder.CreateInnerTableItemCells(
                    itemRow,
                    cellContent: cellContentByFy.ToArray());
            }

            // Display Totals
            var cellContentTotals = new List <DisplayCell> {
                new DisplayCell {
                    Content = "Totals", IsHeader = true
                }
            };

            cellContentTotals.AddRange(exampleTotalsAsGroup.Select(x => new DisplayCell {
                Content = x.Sum(sum => sum.Value).ToString("C"), IsTotal = true, IsCurrency = true
            }).ToArray());
            cellContentTotals.Add(new DisplayCell {
                Content = exampleTotalsAsGroup.Sum(sum => sum.Sum(x => x.Value)).ToString("C"), IsTotal = true, IsCurrency = true
            });
            var projectCostCentreTotalRow = pdfBuilder.CreateInnerTableRow(exampleInnerTable, PdfBuilder.DefaultOuterPadding);

            pdfBuilder.CreateInnerTableItemCells(
                projectCostCentreTotalRow,
                cellContent: cellContentTotals.ToArray());

            pdfBuilder.BlankRow();
        }
Example #8
0
 public PdfPage()
 {
     RenderToPDF    = false;
     OutputFileName = "aspose-pdf-demo.pdf";
     margins        = new MarginInfo(10, 10, 10, 10);
 }
        private static void CreateSectionThreeExample001(PdfBuilder pdfBuilder, MarginInfo parentPadding)
        {
            const bool keepContentTogether = true;
            const bool isKeptTogether      = false;
            const bool isKeptWithNext      = false;
            var        title = "Simple list example 01";

            string[] descriptions = { "example desc 01", "example desc 02", "example desc 03", "example desc 04" };
            if (descriptions.IsAny())
            {
                // Create an inner table
                var simpleThreeColumnInnerTable = pdfBuilder.CreateInnerTable(
                    Resources.ColumnSpanThreeWidth,
                    isKeptTogether: isKeptTogether,
                    isKeptWithNext: isKeptWithNext,
                    keepContentTogether: keepContentTogether);

                // Create inner table row
                var simpleThreeColumnInnerTableRow = pdfBuilder.CreateInnerTableRow(simpleThreeColumnInnerTable, parentPadding);

                // Create Header Cell Title
                pdfBuilder.CreateInnerTableItemCells(
                    simpleThreeColumnInnerTableRow,
                    parentPadding,
                    cellContent: new DisplayCell {
                    Content = title, IsHeader = true
                });

                // create a row for each description
                foreach (var description in descriptions)
                {
                    pdfBuilder.CreateInnerTableItemCells(
                        simpleThreeColumnInnerTable.Rows.Add(),
                        parentPadding,
                        cellContent: new DisplayCell {
                        Content = description
                    });
                }
            }
            pdfBuilder.BlankRow();

            title        = "Simple list example 02";
            descriptions = new[] { "example desc 05", "example desc 06", "example desc 07", "example desc 08" };
            if (descriptions.IsAny())
            {
                // Create an inner table
                var simpleThreeColumnInnerTable = pdfBuilder.CreateInnerTable(
                    Resources.ColumnSpanThreeWidth,
                    isKeptTogether: isKeptTogether,
                    isKeptWithNext: isKeptWithNext,
                    keepContentTogether: keepContentTogether);

                // Create inner table row
                var simpleThreeColumnInnerTableRow = pdfBuilder.CreateInnerTableRow(simpleThreeColumnInnerTable, parentPadding);

                // Create Header Cell Title
                pdfBuilder.CreateInnerTableItemCells(
                    simpleThreeColumnInnerTableRow,
                    parentPadding,
                    cellContent: new DisplayCell {
                    Content = title, IsHeader = true
                });

                // create a row for each description
                foreach (var description in descriptions)
                {
                    pdfBuilder.CreateInnerTableItemCells(
                        simpleThreeColumnInnerTable.Rows.Add(),
                        parentPadding,
                        cellContent: new DisplayCell {
                        Content = description
                    });
                }
            }
            pdfBuilder.BlankRow();
        }
        private static void CreateSectionTwoExample001(PdfBuilder pdfBuilder, MarginInfo parentPadding)
        {
            const VerticalAlignmentType parentVerticalAlignment = VerticalAlignmentType.Center;
            const bool   keepContentTogether = false;
            const bool   isKeptTogether      = false;
            const bool   isKeptWithNext      = false;
            const string exampleDocWidths    = "100 250 100";
            var          exampleDocPadding   = new MarginInfo
            {
                Left   = 2,
                Bottom = 2,
                Top    = 2
            };
            var exampleDocs = new List <string[]>
            {
                new[] { "item 1 type", "item 1 desc", "item 1 filename" },
                new[] { "item 2 type", "item 2 desc", "item 2 filename" },
                new[] { "item 3 type", "item 3 desc", "item 3 filename" },
                new[] { "item 4 type", "item 4 desc", "item 4 filename" },
            };

            if (exampleDocs.IsAny())
            {
                // Create an inner table
                var exampleDocumentTable = pdfBuilder.CreateInnerTable(
                    exampleDocWidths,
                    isKeptTogether: isKeptTogether,
                    isKeptWithNext: isKeptWithNext,
                    keepContentTogether: keepContentTogether);

                // Create inner table row
                var docRow = pdfBuilder.CreateInnerTableRow(exampleDocumentTable, exampleDocPadding);

                // Create inner table cells
                pdfBuilder.CreateInnerTableHeaderCells(docRow, new[]
                {
                    new HeaderCell {
                        Content = "Example 001 doc type"
                    },
                    new HeaderCell {
                        Content = "Example 001 doc desc"
                    },
                    new HeaderCell {
                        Content = "Example 001 doc filename"
                    }
                });

                // format rows for each document
                foreach (var document in exampleDocs)
                {
                    var itemRow = exampleDocumentTable.Rows.Add();
                    pdfBuilder.CreateInnerTableItemCells(
                        itemRow,
                        exampleDocPadding,
                        verticalAlignment: parentVerticalAlignment,
                        cellContent: new[]
                    {
                        new DisplayCell {
                            Content = document[0].Trim()
                        },
                        new DisplayCell {
                            Content = document[1].Trim()
                        },
                        new DisplayCell {
                            Content = document[2].Trim()
                        }
                    });
                }
            }
            pdfBuilder.BlankRow();
        }
        private static void CreateSectionOneExample001(PdfBuilder pdfBuilder, MarginInfo parentPadding)
        {
            const string detailsColumnWidths = "140 310";
            const bool boolValue = true;

            // Create Outer Table
            var exampleOuterTable = pdfBuilder.CreateOuterTable(
                detailsColumnWidths,
                Resources.ArialFont,
                PdfBuilder.DefaultHeadingTwoFontSize,
                parentPadding,
                keepContentTogether: true);

            // Create outer table heading
            pdfBuilder.CreateOuterTableRowHeading(
                exampleOuterTable,
                "Example Heading");

            // insert blank row
            pdfBuilder.BlankRow(exampleOuterTable);

            // Create details
            var exampleLabelTextBox01 = exampleOuterTable.Rows.Add();
            pdfBuilder.CreateOuterTableRowCells(
                exampleLabelTextBox01,
                "Example 01 (label-textbox)",
                "Description of example 01",
                padding: PdfBuilder.DefaultSubHeadingBottomPadding);

            var exampleLabelTextBox02 = exampleOuterTable.Rows.Add();
            pdfBuilder.CreateOuterTableRowCells(
                exampleLabelTextBox02,
                "Example 02 (label-textbox)",
                "Description of example 02",
                padding: PdfBuilder.DefaultSubHeadingBottomPadding);

            var exampleLabelTextBox03 = exampleOuterTable.Rows.Add();
            pdfBuilder.CreateOuterTableRowCells(
                exampleLabelTextBox03,
                "Example 03 (label-textbox)",
                "Description of example 03",
                padding: PdfBuilder.DefaultSubHeadingBottomPadding);

            var exampleLabelTextBox04 = exampleOuterTable.Rows.Add();
            pdfBuilder.CreateOuterTableRowCells(
                exampleLabelTextBox04,
                "Example 04 (label-textbox)",
                "Description of example 04",
                padding: PdfBuilder.DefaultSubHeadingBottomPadding);

            var exampleLabelTextBox05 = exampleOuterTable.Rows.Add();
            pdfBuilder.CreateOuterTableRowCells(
                exampleLabelTextBox05,
                "Example 05 (label-textbox)",
                "Description of example 05",
                padding: PdfBuilder.DefaultSubHeadingBottomPadding);

            var capitalOnlyRow = exampleOuterTable.Rows.Add();
            pdfBuilder.CreateOuterTableRowCells(
                capitalOnlyRow,
                "Example Name 06 (from bool as yes/no value)",
                pdfBuilder.CreateYesNoValue(boolValue),
                padding: PdfBuilder.DefaultSubHeadingBottomPadding);

            // project description
            pdfBuilder.CreateTextAreaCell(
                exampleOuterTable.ColumnWidths,
                "Example 07 (textarea)",
                "Description of example 07",
                Resources.TextAreaColumnWidths);
            pdfBuilder.BlankRow();
        }
        public ActionResult ExportPdf(List <GetTimeSheetModel> model)
        {
            List <List <TimeSheetModel> > timeSheets = new List <List <TimeSheetModel> >();

            Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document();

            Page page = pdfDocument.Pages.Add();

            page.PageInfo.IsLandscape = true;

            TextState tstate = new TextState();

            tstate.FontSize = 10;
            page.PageInfo.DefaultTextState = tstate;



            MarginInfo marginInfo = new MarginInfo();

            marginInfo.Left      = 35;
            marginInfo.Right     = 28;
            marginInfo.Top       = 28;
            marginInfo.Bottom    = 28;
            page.PageInfo.Margin = marginInfo;



            TextFragment text = new TextFragment("Time Sheets");

            text.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center;
            text.TextState.FontSize  = 16;
            text.Margin.Bottom       = 20;
            page.Paragraphs.Add(text);


            List <Table> tableList = new List <Table>();

            foreach (var item in model)
            {
                Table table = new Table
                {
                    ColumnWidths       = "80, 50, 65, 65, 60, 65, 50, 65, 50, 50, 65, 50",
                    DefaultCellPadding = new MarginInfo(10, 5, 10, 5),
                    Border             = new BorderInfo(BorderSide.All, .5f, Color.Black),
                    DefaultCellBorder  = new BorderInfo(BorderSide.All, .2f, Color.Black),
                };

                Aspose.Pdf.Row row1 = table.Rows.Add();

                row1.Cells.Add("Time Sheet Key");
                row1.Cells.Add("Type");
                row1.Cells.Add("Start Time");
                row1.Cells.Add("End Time");
                row1.Cells.Add("Breaks");
                row1.Cells.Add("Work Time");
                row1.Cells.Add("m3");
                row1.Cells.Add("Km - Stand");
                row1.Cells.Add("Privat");
                row1.Cells.Add("Fuel");
                row1.Cells.Add("Ad Blue");
                row1.Cells.Add("Notes");

                foreach (var sheet in GetTimeSheetsByEmployeeIdAndDate(item))
                {
                    if (sheet.startTime != "-1" || sheet.endTime != "-1" || sheet.breaks != "-1")
                    {
                        Aspose.Pdf.Row row = table.Rows.Add();
                        row.Cells.Add(sheet.timeSheetKey == "-1" ? "" : sheet.timeSheetKey);
                        row.Cells.Add(sheet.type == "-1" ? "" : sheet.type);
                        row.Cells.Add(sheet.startTime == "-1" ? "" : sheet.startTime);
                        row.Cells.Add(sheet.endTime == "-1" ? "" : sheet.endTime);
                        row.Cells.Add(sheet.breaks == "-1" ? "" : sheet.breaks);
                        row.Cells.Add(sheet.workTime == "-1" ? "" : sheet.workTime);
                        row.Cells.Add(Convert.ToString(sheet.m3 == -1 ? 0 : sheet.m3));
                        row.Cells.Add(Convert.ToString(sheet.kmStand == -1 ? 0 : sheet.kmStand));
                        row.Cells.Add(Convert.ToString(sheet.privat == -1 ? 0 : sheet.privat));
                        row.Cells.Add(Convert.ToString(sheet.fuel == -1 ? 0 : sheet.fuel));
                        row.Cells.Add(Convert.ToString(sheet.adblue == -1 ? 0 : sheet.adblue));
                        row.Cells.Add(sheet.notes == "-1" ? "" : sheet.notes);
                    }
                }
                tableList.Add(table);
                timeSheets.Add(GetTimeSheetsByEmployeeIdAndDate(item));
            }

            foreach (var table in tableList)
            {
                pdfDocument.Pages[1].Paragraphs.Add(table);

                text = new TextFragment("");

                text.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center;
                text.TextState.FontSize  = 16;
                text.Margin.Bottom       = 20;
                page.Paragraphs.Add(text);
            }

            using (var streamOut = new MemoryStream())
            {
                pdfDocument.Save(streamOut);
                return(new FileContentResult(streamOut.ToArray(), "application/pdf"));
            }
        }
        private static void CreateSectionFourExample001(PdfBuilder pdfBuilder, MarginInfo parentPadding)
        {
            const string columnWidths = "350 100";
            var descriptions = new List<string[]>{ new [] { "[ex code 01]", "ex foo", "cm" }, new [] { "[ex code 02]", "ex foo", "mm" } };
            if (descriptions.IsAny())
            {
                // Create an inner table
                var sectionFourExampleTable = pdfBuilder.CreateInnerTable(
                    columnWidths,
                    keepContentTogether: true);

                // Create inner table row
                var projectFundedServicesRow = pdfBuilder.CreateInnerTableRow(sectionFourExampleTable, parentPadding);

                // Create Header Cell Titles
                pdfBuilder.CreateInnerTableItemCells(
                        projectFundedServicesRow,
                        cellContent: new[] {
                            new DisplayCell { Content = "Example Code", IsHeader = true }, 
                            new DisplayCell { Content = "Example Measure", IsHeader = true }
                        });

                // create a row for each description
                foreach (var item in descriptions)
                {
                    pdfBuilder.CreateInnerTableItemCells(
                        sectionFourExampleTable.Rows.Add(),
                        cellContent: new[] {
                            new DisplayCell { Content = item[0] + " - " + item[1] }, 
                            new DisplayCell { Content = item[2] }
                        });
                }
            }
            pdfBuilder.BlankRow();
        }
        public static void Run()
        {
            // ExStart:ReplaceableSymbolsInHeaderFooter
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_Text();

            Document doc = new Document();
            Page page = doc.Pages.Add();

            MarginInfo marginInfo = new MarginInfo();
            marginInfo.Top = 90;
            marginInfo.Bottom = 50;
            marginInfo.Left = 50;
            marginInfo.Right = 50;
            // Assign the marginInfo instance to Margin property of sec1.PageInfo
            page.PageInfo.Margin = marginInfo;

            HeaderFooter hfFirst = new HeaderFooter();
            page.Header = hfFirst;
            hfFirst.Margin.Left = 50;
            hfFirst.Margin.Right = 50;

            // Instantiate a Text paragraph that will store the content to show as header
            TextFragment t1 = new TextFragment("report title");
            t1.TextState.Font = FontRepository.FindFont("Arial");
            t1.TextState.FontSize = 16;
            t1.TextState.ForegroundColor = Aspose.Pdf.Color.Black;
            t1.TextState.FontStyle = FontStyles.Bold;
            t1.TextState.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center;
            t1.TextState.LineSpacing = 5f;
            hfFirst.Paragraphs.Add(t1);

            TextFragment t2 = new TextFragment("Report_Name");
            t2.TextState.Font = FontRepository.FindFont("Arial");
            t2.TextState.ForegroundColor = Aspose.Pdf.Color.Black;
            t2.TextState.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center;
            t2.TextState.LineSpacing = 5f;
            t2.TextState.FontSize = 12;
            hfFirst.Paragraphs.Add(t2);

            // Create a HeaderFooter object for the section
            HeaderFooter hfFoot = new HeaderFooter();
            // Set the HeaderFooter object to odd & even footer
            page.Footer = hfFoot;
            hfFoot.Margin.Left = 50;
            hfFoot.Margin.Right = 50;

            // Add a text paragraph containing current page number of total number of pages
            TextFragment t3 = new TextFragment("Generated on test date");
            TextFragment t4 = new TextFragment("report name ");
            TextFragment t5 = new TextFragment("Page $p of $P");

            // Instantiate a table object
            Table tab2 = new Table();

            // Add the table in paragraphs collection of the desired section
            hfFoot.Paragraphs.Add(tab2);

            // Set with column widths of the table
            tab2.ColumnWidths = "165 172 165";

            // Create rows in the table and then cells in the rows
            Row row3 = tab2.Rows.Add();

            row3.Cells.Add();
            row3.Cells.Add();
            row3.Cells.Add();

            // Set the vertical allignment of the text as center alligned
            row3.Cells[0].Alignment = Aspose.Pdf.HorizontalAlignment.Left;
            row3.Cells[1].Alignment = Aspose.Pdf.HorizontalAlignment.Center;
            row3.Cells[2].Alignment = Aspose.Pdf.HorizontalAlignment.Right;

            row3.Cells[0].Paragraphs.Add(t3);
            row3.Cells[1].Paragraphs.Add(t4);
            row3.Cells[2].Paragraphs.Add(t5);

            // Sec1.Paragraphs.Add(New Text("Aspose.Total for Java is a compilation of every Java component offered by Aspose. It is compiled on a#$NL" + "daily basis to ensure it contains the most up to date versions of each of our Java components. #$NL " + "Using Aspose.Total for Java developers can create a wide range of applications. #$NL #$NL #$NP" + "Aspose.Total for Java is a compilation of every Java component offered by Aspose. It is compiled on a#$NL" + "daily basis to ensure it contains the most up to date versions of each of our Java components. #$NL " + "Using Aspose.Total for Java developers can create a wide range of applications. #$NL #$NL #$NP" + "Aspose.Total for Java is a compilation of every Java component offered by Aspose. It is compiled on a#$NL" + "daily basis to ensure it contains the most up to date versions of each of our Java components. #$NL " + "Using Aspose.Total for Java developers can create a wide range of applications. #$NL #$NL"))
            Table table = new Table();

            table.ColumnWidths = "33% 33% 34%";
            table.DefaultCellPadding = new MarginInfo();
            table.DefaultCellPadding.Top = 10;
            table.DefaultCellPadding.Bottom = 10;

            // Add the table in paragraphs collection of the desired section
            page.Paragraphs.Add(table);

            // Set default cell border using BorderInfo object
            table.DefaultCellBorder = new BorderInfo(BorderSide.All, 0.1f);

            // Set table border using another customized BorderInfo object
            table.Border = new BorderInfo(BorderSide.All, 1f);

            table.RepeatingRowsCount = 1;

            // Create rows in the table and then cells in the rows
            Row row1 = table.Rows.Add();

            row1.Cells.Add("col1");
            row1.Cells.Add("col2");
            row1.Cells.Add("col3");
            const string CRLF = "\r\n";
            for (int i = 0; i <= 10; i++)
            {
                Row row = table.Rows.Add();
                row.IsRowBroken = true;
                for (int c = 0; c <= 2; c++)
                {
                    Cell c1;
                    if (c == 2)
                        c1 = row.Cells.Add("Aspose.Total for Java is a compilation of every Java component offered by Aspose. It is compiled on a" + CRLF + "daily basis to ensure it contains the most up to date versions of each of our Java components. " + CRLF + "daily basis to ensure it contains the most up to date versions of each of our Java components. " + CRLF + "Using Aspose.Total for Java developers can create a wide range of applications.");
                    else
                        c1 = row.Cells.Add("item1" + c);
                    c1.Margin = new MarginInfo();
                    c1.Margin.Left = 30;
                    c1.Margin.Top = 10;
                    c1.Margin.Bottom = 10;
                }
            }

            dataDir = dataDir + "ReplaceableSymbolsInHeaderFooter_out.pdf";
            doc.Save(dataDir);
            // ExEnd:ReplaceableSymbolsInHeaderFooter            
            Console.WriteLine("\nSymbols replaced successfully in header and footer.\nFile saved at " + dataDir);
        }
        private static void CreateSectionThreeExample001(PdfBuilder pdfBuilder, MarginInfo parentPadding)
        {
            const bool keepContentTogether = true;
            const bool isKeptTogether = false;
            const bool isKeptWithNext = false;
            var title = "Simple list example 01";
            string[] descriptions = { "example desc 01", "example desc 02", "example desc 03", "example desc 04" };
            if (descriptions.IsAny())
            {
                // Create an inner table
                var simpleThreeColumnInnerTable = pdfBuilder.CreateInnerTable(
                    Resources.ColumnSpanThreeWidth,
                    isKeptTogether: isKeptTogether,
                    isKeptWithNext: isKeptWithNext,
                    keepContentTogether: keepContentTogether);

                // Create inner table row
                var simpleThreeColumnInnerTableRow = pdfBuilder.CreateInnerTableRow(simpleThreeColumnInnerTable, parentPadding);

                // Create Header Cell Title
                pdfBuilder.CreateInnerTableItemCells(
                        simpleThreeColumnInnerTableRow,
                        parentPadding,
                        cellContent: new DisplayCell { Content = title, IsHeader = true });

                // create a row for each description
                foreach (var description in descriptions)
                {
                    pdfBuilder.CreateInnerTableItemCells(
                        simpleThreeColumnInnerTable.Rows.Add(),
                        parentPadding,
                        cellContent: new DisplayCell { Content = description });
                }
            }
            pdfBuilder.BlankRow();

            title = "Simple list example 02";
            descriptions = new[]{ "example desc 05", "example desc 06", "example desc 07", "example desc 08" };
            if (descriptions.IsAny())
            {
                // Create an inner table
                var simpleThreeColumnInnerTable = pdfBuilder.CreateInnerTable(
                    Resources.ColumnSpanThreeWidth,
                    isKeptTogether: isKeptTogether,
                    isKeptWithNext: isKeptWithNext,
                    keepContentTogether: keepContentTogether);

                // Create inner table row
                var simpleThreeColumnInnerTableRow = pdfBuilder.CreateInnerTableRow(simpleThreeColumnInnerTable, parentPadding);

                // Create Header Cell Title
                pdfBuilder.CreateInnerTableItemCells(
                        simpleThreeColumnInnerTableRow,
                        parentPadding,
                        cellContent: new DisplayCell { Content = title, IsHeader = true });

                // create a row for each description
                foreach (var description in descriptions)
                {
                    pdfBuilder.CreateInnerTableItemCells(
                        simpleThreeColumnInnerTable.Rows.Add(),
                        parentPadding,
                        cellContent: new DisplayCell { Content = description });
                }
            }
            pdfBuilder.BlankRow();
        }
        private static void CreateSectionTwoExample001(PdfBuilder pdfBuilder, MarginInfo parentPadding)
        {
            const VerticalAlignmentType parentVerticalAlignment = VerticalAlignmentType.Center;
            const bool keepContentTogether = false;
            const bool isKeptTogether = false;
            const bool isKeptWithNext = false;
            const string exampleDocWidths = "100 250 100";
            var exampleDocPadding = new MarginInfo
            {
                Left = 2,
                Bottom = 2,
                Top = 2
            };
            var exampleDocs = new List<string[]>
            {
                new[]{ "item 1 type", "item 1 desc", "item 1 filename" }, 
                new[]{ "item 2 type", "item 2 desc", "item 2 filename" }, 
                new[]{ "item 3 type", "item 3 desc", "item 3 filename" }, 
                new[]{ "item 4 type", "item 4 desc", "item 4 filename" }, 
            };
            if (exampleDocs.IsAny())
            {
                // Create an inner table
                var exampleDocumentTable = pdfBuilder.CreateInnerTable(
                    exampleDocWidths,
                    isKeptTogether: isKeptTogether,
                    isKeptWithNext: isKeptWithNext,
                    keepContentTogether: keepContentTogether);

                // Create inner table row
                var docRow = pdfBuilder.CreateInnerTableRow(exampleDocumentTable, exampleDocPadding);

                // Create inner table cells
                pdfBuilder.CreateInnerTableHeaderCells(docRow, new[]
                {
                    new HeaderCell { Content = "Example 001 doc type" },
                    new HeaderCell { Content = "Example 001 doc desc" },
                    new HeaderCell { Content = "Example 001 doc filename" }
                });

                // format rows for each document
                foreach (var document in exampleDocs)
                {
                    var itemRow = exampleDocumentTable.Rows.Add();
                    pdfBuilder.CreateInnerTableItemCells(
                        itemRow,
                        exampleDocPadding,
                        verticalAlignment: parentVerticalAlignment,
                        cellContent: new[]
                        {
                            new DisplayCell { Content = document[0].Trim() }, 
                            new DisplayCell { Content = document[1].Trim() }, 
                            new DisplayCell { Content = document[2].Trim() }
                        });
                }
            }
            pdfBuilder.BlankRow();
        }
        public static void Run()
        {
            // ExStart:ReplaceableSymbolsInHeaderFooter
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_Text();

            Document doc  = new Document();
            Page     page = doc.Pages.Add();

            MarginInfo marginInfo = new MarginInfo();

            marginInfo.Top    = 90;
            marginInfo.Bottom = 50;
            marginInfo.Left   = 50;
            marginInfo.Right  = 50;
            // Assign the marginInfo instance to Margin property of sec1.PageInfo
            page.PageInfo.Margin = marginInfo;

            HeaderFooter hfFirst = new HeaderFooter();

            page.Header          = hfFirst;
            hfFirst.Margin.Left  = 50;
            hfFirst.Margin.Right = 50;

            // Instantiate a Text paragraph that will store the content to show as header
            TextFragment t1 = new TextFragment("report title");

            t1.TextState.Font                = FontRepository.FindFont("Arial");
            t1.TextState.FontSize            = 16;
            t1.TextState.ForegroundColor     = Aspose.Pdf.Color.Black;
            t1.TextState.FontStyle           = FontStyles.Bold;
            t1.TextState.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center;
            t1.TextState.LineSpacing         = 5f;
            hfFirst.Paragraphs.Add(t1);

            TextFragment t2 = new TextFragment("Report_Name");

            t2.TextState.Font                = FontRepository.FindFont("Arial");
            t2.TextState.ForegroundColor     = Aspose.Pdf.Color.Black;
            t2.TextState.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center;
            t2.TextState.LineSpacing         = 5f;
            t2.TextState.FontSize            = 12;
            hfFirst.Paragraphs.Add(t2);

            // Create a HeaderFooter object for the section
            HeaderFooter hfFoot = new HeaderFooter();

            // Set the HeaderFooter object to odd & even footer
            page.Footer         = hfFoot;
            hfFoot.Margin.Left  = 50;
            hfFoot.Margin.Right = 50;

            // Add a text paragraph containing current page number of total number of pages
            TextFragment t3 = new TextFragment("Generated on test date");
            TextFragment t4 = new TextFragment("report name ");
            TextFragment t5 = new TextFragment("Page $p of $P");

            // Instantiate a table object
            Table tab2 = new Table();

            // Add the table in paragraphs collection of the desired section
            hfFoot.Paragraphs.Add(tab2);

            // Set with column widths of the table
            tab2.ColumnWidths = "165 172 165";

            // Create rows in the table and then cells in the rows
            Row row3 = tab2.Rows.Add();

            row3.Cells.Add();
            row3.Cells.Add();
            row3.Cells.Add();

            // Set the vertical allignment of the text as center alligned
            row3.Cells[0].Alignment = Aspose.Pdf.HorizontalAlignment.Left;
            row3.Cells[1].Alignment = Aspose.Pdf.HorizontalAlignment.Center;
            row3.Cells[2].Alignment = Aspose.Pdf.HorizontalAlignment.Right;

            row3.Cells[0].Paragraphs.Add(t3);
            row3.Cells[1].Paragraphs.Add(t4);
            row3.Cells[2].Paragraphs.Add(t5);

            // Sec1.Paragraphs.Add(New Text("Aspose.Total for Java is a compilation of every Java component offered by Aspose. It is compiled on a#$NL" + "daily basis to ensure it contains the most up to date versions of each of our Java components. #$NL " + "Using Aspose.Total for Java developers can create a wide range of applications. #$NL #$NL #$NP" + "Aspose.Total for Java is a compilation of every Java component offered by Aspose. It is compiled on a#$NL" + "daily basis to ensure it contains the most up to date versions of each of our Java components. #$NL " + "Using Aspose.Total for Java developers can create a wide range of applications. #$NL #$NL #$NP" + "Aspose.Total for Java is a compilation of every Java component offered by Aspose. It is compiled on a#$NL" + "daily basis to ensure it contains the most up to date versions of each of our Java components. #$NL " + "Using Aspose.Total for Java developers can create a wide range of applications. #$NL #$NL"))
            Table table = new Table();

            table.ColumnWidths              = "33% 33% 34%";
            table.DefaultCellPadding        = new MarginInfo();
            table.DefaultCellPadding.Top    = 10;
            table.DefaultCellPadding.Bottom = 10;

            // Add the table in paragraphs collection of the desired section
            page.Paragraphs.Add(table);

            // Set default cell border using BorderInfo object
            table.DefaultCellBorder = new BorderInfo(BorderSide.All, 0.1f);

            // Set table border using another customized BorderInfo object
            table.Border = new BorderInfo(BorderSide.All, 1f);

            table.RepeatingRowsCount = 1;

            // Create rows in the table and then cells in the rows
            Row row1 = table.Rows.Add();

            row1.Cells.Add("col1");
            row1.Cells.Add("col2");
            row1.Cells.Add("col3");
            const string CRLF = "\r\n";

            for (int i = 0; i <= 10; i++)
            {
                Row row = table.Rows.Add();
                row.IsRowBroken = true;
                for (int c = 0; c <= 2; c++)
                {
                    Cell c1;
                    if (c == 2)
                    {
                        c1 = row.Cells.Add("Aspose.Total for Java is a compilation of every Java component offered by Aspose. It is compiled on a" + CRLF + "daily basis to ensure it contains the most up to date versions of each of our Java components. " + CRLF + "daily basis to ensure it contains the most up to date versions of each of our Java components. " + CRLF + "Using Aspose.Total for Java developers can create a wide range of applications.");
                    }
                    else
                    {
                        c1 = row.Cells.Add("item1" + c);
                    }
                    c1.Margin        = new MarginInfo();
                    c1.Margin.Left   = 30;
                    c1.Margin.Top    = 10;
                    c1.Margin.Bottom = 10;
                }
            }

            dataDir = dataDir + "ReplaceableSymbolsInHeaderFooter_out.pdf";
            doc.Save(dataDir);
            // ExEnd:ReplaceableSymbolsInHeaderFooter
            Console.WriteLine("\nSymbols replaced successfully in header and footer.\nFile saved at " + dataDir);
        }
        private void CreatePDFWithTable()
        {
            String   inFile  = myDir + "sample.pdf";
            Random   rand    = new Random();
            String   outFile = myDir + rand.Next(1000, 10000) + ".pdf";
            Document pdfDoc  = new Document(inFile);

            RemoveHeader(pdfDoc);
            RemoveFooter(pdfDoc);


            Table table = new Table();

            table.Border = new BorderInfo(BorderSide.All, 0.1F);
            var margin = new MarginInfo {
                Top = 0f, Left = 0f, Right = 0f, Bottom = 0f
            };

            table.Margin = margin;
            double pageWidth   = pdfDoc.Pages[1].PageInfo.Width;
            int    columnWidth = ((int)pageWidth) / 2;

            table.ColumnWidths = columnWidth + " " + columnWidth;
            Row row1  = new Row();
            var cell1 = new Cell();

            cell1.ColSpan = 2;

            TextFragment text1 = new TextFragment("!!!!!!!! This is a sample footer overwritten");

            text1.Margin.Bottom      = 2;
            text1.Margin.Top         = 2;
            text1.Margin.Right       = 2;
            text1.Margin.Left        = 2;
            text1.TextState.Font     = FontRepository.FindFont("Verdana");
            text1.TextState.FontSize = 12;
            cell1.Paragraphs.Add(text1);
            row1.Cells.Add(cell1);
            table.Rows.Add(row1);

            Row   row2   = new Row();
            Cells cells2 = new Cells();

            //add text
            cells2.Add("Row 2");

            //add logo
            Aspose.Pdf.Image img = new Aspose.Pdf.Image();
            img.File = myDir + "Panda.png";
            // img2.File = myDir + "images.png";
            img.FixWidth  = 78;
            img.FixHeight = 31;
            Cell cell2 = row2.Cells.Add();

            cell2.Paragraphs.Add(img);
            cells2.Add(cell2);
            row2.Cells = cells2;
            table.Rows.Add(row2);


            Table tableHeader = new Table();

            tableHeader.Border = new BorderInfo(BorderSide.All, 0.1F);
            var margin1 = new MarginInfo {
                Top = 0f, Left = 0f, Right = 0f, Bottom = 0f
            };

            tableHeader.Margin = margin1;
            double pageWidth1   = pdfDoc.Pages[1].PageInfo.Width;
            int    columnWidth1 = ((int)pageWidth) / 2;

            tableHeader.ColumnWidths = columnWidth + " " + columnWidth;
            Row row3  = new Row();
            var cell3 = new Cell();

            cell1.ColSpan = 2;

            TextFragment text2 = new TextFragment(" This is a sample Header overwritten....!");

            text2.Margin.Bottom      = 2;
            text2.Margin.Top         = 2;
            text2.Margin.Right       = 2;
            text2.Margin.Left        = 2;
            text2.TextState.Font     = FontRepository.FindFont("Verdana");
            text2.TextState.FontSize = 12;
            cell3.Paragraphs.Add(text2);
            row3.Cells.Add(cell3);
            tableHeader.Rows.Add(row3);

            Row   row4   = new Row();
            Cells cells4 = new Cells();

            //add text
            cells4.Add("Row 1");

            //add logo
            Aspose.Pdf.Image img2 = new Aspose.Pdf.Image();
            //img.File = myDir + "Panda.png";
            img2.File      = myDir + "images.png";
            img2.FixWidth  = 78;
            img2.FixHeight = 31;
            Cell cells5 = row4.Cells.Add();

            cells5.Paragraphs.Add(img2);
            cells4.Add(cells5);
            row4.Cells = cells4;
            tableHeader.Rows.Add(row4);

            // creating a header
            HeaderFooter header       = new HeaderFooter();
            var          marginheader = new MarginInfo {
                Top = 0f, Left = 10f, Right = 10f, Bottom = 0f
            };

            header.Margin = marginheader;
            header.Paragraphs.Add(tableHeader);

            // creating a footer
            HeaderFooter footer       = new HeaderFooter();
            var          marginFooter = new MarginInfo {
                Top = 0f, Left = 10f, Right = 10f, Bottom = 0f
            };

            footer.Margin = marginFooter;
            footer.Paragraphs.Add(table);

            for (int i = 1; i <= pdfDoc.Pages.Count; i++)
            {
                pdfDoc.Pages[i].Header = header;
                pdfDoc.Pages[i].Footer = footer;
                pdfDoc.ProcessParagraphs();
            }

            pdfDoc.Save(outFile);
        }
Example #19
0
        internal void HandleAccountInfo(JToken token, ConfigurationState config)
        {
            var itemsCount = token?.Count();

            if (token == null || itemsCount < 2)
            {
                Log.Warn($"Invalid message format, too low items");
                return;
            }

            var secondItem = token[1];

            if (secondItem.Type != JTokenType.String)
            {
                Log.Warn(L("Invalid message format, second param is not string"));
                return;
            }

            var msgType = (string)secondItem;

            if (msgType == "hb")
            {
                // heartbeat, ignore
                return;
            }

            if (itemsCount < 3)
            {
                Log.Warn(L("Invalid message format, too low items"));
                return;
            }

            // ********************
            // ADD HANDLERS BELOW
            // ********************

            switch (msgType)
            {
            case "ws":
                Wallet.Handle(token, _streams.WalletSubject, _streams.WalletsSubject);
                break;

            case "wu":
                Wallet.Handle(token, _streams.WalletSubject);
                break;

            case "os":
                Order.Handle(token, _streams.OrdersSubject);
                break;

            case "on":
                Order.Handle(token, _streams.OrderCreatedSubject);
                break;

            case "ou":
                Order.Handle(token, _streams.OrderUpdatedSubject);
                break;

            case "oc":
                Order.Handle(token, _streams.OrderCanceledSubject);
                break;

            case "te":
                PrivateTrade.Handle(token, config, _streams.PrivateTradeSubject, TradeType.Executed);
                break;

            case "tu":
                PrivateTrade.Handle(token, config, _streams.PrivateTradeSubject, TradeType.UpdateExecution);
                break;

            case "ps":
                Position.Handle(token, config, _streams.PositionsSubject);
                break;

            case "pn":
                Position.Handle(token, config, _streams.PositionCreatedSubject);
                break;

            case "pu":
                Position.Handle(token, config, _streams.PositionUpdatedSubject);
                break;

            case "pc":
                Position.Handle(token, config, _streams.PositionCanceledSubject);
                break;

            case "n":
                Notification.Handle(token, _streams.NotificationSubject);
                break;

            case "bu":
                BalanceInfo.Handle(token, _streams.BalanceInfoSubject);
                break;

            case "miu":
                MarginInfo.Handle(token, _streams.MarginInfoSubject);
                break;
                //default:
                //    Log.Warning($"Missing private handler for '{msgType}'. Data: {token}");
                //    break;
            }
        }
        private static void CreateSectionOneExample001(PdfBuilder pdfBuilder, MarginInfo parentPadding)
        {
            const string detailsColumnWidths = "140 310";
            const bool   boolValue           = true;

            // Create Outer Table
            var exampleOuterTable = pdfBuilder.CreateOuterTable(
                detailsColumnWidths,
                Resources.ArialFont,
                PdfBuilder.DefaultHeadingTwoFontSize,
                parentPadding,
                keepContentTogether: true);

            // Create outer table heading
            pdfBuilder.CreateOuterTableRowHeading(
                exampleOuterTable,
                "Example Heading");

            // insert blank row
            pdfBuilder.BlankRow(exampleOuterTable);

            // Create details
            var exampleLabelTextBox01 = exampleOuterTable.Rows.Add();

            pdfBuilder.CreateOuterTableRowCells(
                exampleLabelTextBox01,
                "Example 01 (label-textbox)",
                "Description of example 01",
                padding: PdfBuilder.DefaultSubHeadingBottomPadding);

            var exampleLabelTextBox02 = exampleOuterTable.Rows.Add();

            pdfBuilder.CreateOuterTableRowCells(
                exampleLabelTextBox02,
                "Example 02 (label-textbox)",
                "Description of example 02",
                padding: PdfBuilder.DefaultSubHeadingBottomPadding);

            var exampleLabelTextBox03 = exampleOuterTable.Rows.Add();

            pdfBuilder.CreateOuterTableRowCells(
                exampleLabelTextBox03,
                "Example 03 (label-textbox)",
                "Description of example 03",
                padding: PdfBuilder.DefaultSubHeadingBottomPadding);

            var exampleLabelTextBox04 = exampleOuterTable.Rows.Add();

            pdfBuilder.CreateOuterTableRowCells(
                exampleLabelTextBox04,
                "Example 04 (label-textbox)",
                "Description of example 04",
                padding: PdfBuilder.DefaultSubHeadingBottomPadding);

            var exampleLabelTextBox05 = exampleOuterTable.Rows.Add();

            pdfBuilder.CreateOuterTableRowCells(
                exampleLabelTextBox05,
                "Example 05 (label-textbox)",
                "Description of example 05",
                padding: PdfBuilder.DefaultSubHeadingBottomPadding);

            var capitalOnlyRow = exampleOuterTable.Rows.Add();

            pdfBuilder.CreateOuterTableRowCells(
                capitalOnlyRow,
                "Example Name 06 (from bool as yes/no value)",
                pdfBuilder.CreateYesNoValue(boolValue),
                padding: PdfBuilder.DefaultSubHeadingBottomPadding);

            // project description
            pdfBuilder.CreateTextAreaCell(
                exampleOuterTable.ColumnWidths,
                "Example 07 (textarea)",
                "Description of example 07",
                Resources.TextAreaColumnWidths);
            pdfBuilder.BlankRow();
        }
        private static void CreateSectionFiveExample001(PdfBuilder pdfBuilder, MarginInfo parentPadding)
        {
            var secionFiveExampleTable = pdfBuilder.CreateOuterTable(
                    "140 310",
                    Resources.ArialFont,
                    PdfBuilder.DefaultHeadingTwoFontSize,
                    parentPadding,
                    keepContentTogether: true);

            // create table row heading
            pdfBuilder.CreateOuterTableRowHeading(
                secionFiveExampleTable,
                "Example Section 5 Heading");

            pdfBuilder.BlankRow(secionFiveExampleTable);

            // Create dates
            var exampleItem01Row = secionFiveExampleTable.Rows.Add();
            pdfBuilder.CreateOuterTableRowCells(
                exampleItem01Row,
                "Example item 01",
                DateTime.Now.ToShortDateString(),
                padding: PdfBuilder.DefaultSubHeadingBottomPadding);

            var exampleItem02Row = secionFiveExampleTable.Rows.Add();
            pdfBuilder.CreateOuterTableRowCells(
                exampleItem02Row,
                "Example item 02",
                "example info",
                padding: PdfBuilder.DefaultSubHeadingBottomPadding);

            var exampleItem03Row = secionFiveExampleTable.Rows.Add();
            pdfBuilder.CreateOuterTableRowCells(
                exampleItem03Row,
                "Example item 03",
                "example info",
                padding: PdfBuilder.DefaultSubHeadingBottomPadding);

            var exampleItem04Row = secionFiveExampleTable.Rows.Add();
            pdfBuilder.CreateOuterTableRowCells(
                exampleItem04Row,
                "Example item 04",
                "example info",
                padding: PdfBuilder.DefaultSubHeadingBottomPadding);

            pdfBuilder.BlankRow(secionFiveExampleTable);

            // create an overly complex arrangement of data and values to demonstrate the flexibility of the aspose pdf builder.
            var orderedNumbers = new[] { "0001", "0002", "0003" };
            var examplePairsAsGroup = new List<KeyValuePair<string, decimal>>
            {
                new KeyValuePair<string, decimal>(orderedNumbers[0], 10000), 
                new KeyValuePair<string, decimal>(orderedNumbers[0], 10000), 
                new KeyValuePair<string, decimal>(orderedNumbers[0], 10000), 
                new KeyValuePair<string, decimal>(orderedNumbers[1], 20000), 
                new KeyValuePair<string, decimal>(orderedNumbers[1], 20000), 
                new KeyValuePair<string, decimal>(orderedNumbers[1], 20000), 
                new KeyValuePair<string, decimal>(orderedNumbers[2], 30000),
                new KeyValuePair<string, decimal>(orderedNumbers[2], 30000),
                new KeyValuePair<string, decimal>(orderedNumbers[2], 30000)
            }.OrderBy(x => x.Key)
            .GroupBy(x => x.Key)
            .ToArray();

            // calculate totals - terrible example...
            var orderedNumbers0001 = examplePairsAsGroup.SelectMany(x => x).Where(x => x.Key == orderedNumbers[0]).ToArray();
            var orderedNumbers0002 = examplePairsAsGroup.SelectMany(x => x).Where(x => x.Key == orderedNumbers[1]).ToArray();
            var orderedNumbers0003 = examplePairsAsGroup.SelectMany(x => x).Where(x => x.Key == orderedNumbers[2]).ToArray();
            var exampleTotalsAsGroup = new List<KeyValuePair<string, decimal>>
            {
                new KeyValuePair<string, decimal>(orderedNumbers[0], orderedNumbers0001[0].Value + orderedNumbers0002[0].Value + orderedNumbers0003[0].Value), 
                new KeyValuePair<string, decimal>(orderedNumbers[1], orderedNumbers0001[1].Value + orderedNumbers0002[1].Value + orderedNumbers0003[1].Value), 
                new KeyValuePair<string, decimal>(orderedNumbers[2], orderedNumbers0001[2].Value + orderedNumbers0002[2].Value + orderedNumbers0003[2].Value)
            }.OrderBy(x => x.Key)
            .GroupBy(x => x.Key)
            .ToArray();

            var useWidths = "53 80 79 79 80 79"; // remember - a user can specify less or more columns and pass them into CreateInnerTable.
            // Create an inner table
            var exampleInnerTable = pdfBuilder.CreateInnerTable(useWidths, secionFiveExampleTable);

            // Create Header Inner Table row
            var exampleInnerHeaderRow = pdfBuilder.CreateInnerTableRow(exampleInnerTable, parentPadding);

            // Create Header Cell Titles
            var titles = new List<HeaderCell> { new HeaderCell { Content = "Side Content Name" } };
            var additionalNames = new [] { "example 01", "example 02", "example 03" }.GroupBy(x => x).ToArray();
            titles.AddRange(additionalNames.Select(name => new HeaderCell { Content = "ex name " + name.Key }));
            titles.Add(new HeaderCell { Content = "Total" });
            pdfBuilder.CreateInnerTableHeaderCells(exampleInnerHeaderRow, titles.ToArray());

            // Display example pairs by their ordered numbers
            foreach (var epag in examplePairsAsGroup)
            {
                var cellContentByFy = new List<DisplayCell> { new DisplayCell { Content = epag.Key, IsDate = true } };
                cellContentByFy.AddRange(epag.Select(x => new DisplayCell { Content = x.Value.ToString("C"), IsCurrency = true }).ToArray());
                cellContentByFy.Add(new DisplayCell { Content = epag.Sum(x => x.Value).ToString("C"), IsCurrency = true });

                var itemRow = pdfBuilder.CreateInnerTableRow(exampleInnerTable, parentPadding);
                pdfBuilder.CreateInnerTableItemCells(
                    itemRow,
                    cellContent: cellContentByFy.ToArray());
            }

            // Display Totals
            var cellContentTotals = new List<DisplayCell> { new DisplayCell { Content = "Totals", IsHeader = true } };
            cellContentTotals.AddRange(exampleTotalsAsGroup.Select(x => new DisplayCell { Content = x.Sum(sum => sum.Value).ToString("C"), IsTotal = true, IsCurrency = true }).ToArray());
            cellContentTotals.Add(new DisplayCell { Content = exampleTotalsAsGroup.Sum(sum => sum.Sum(x => x.Value)).ToString("C"), IsTotal = true, IsCurrency = true });
            var projectCostCentreTotalRow = pdfBuilder.CreateInnerTableRow(exampleInnerTable, PdfBuilder.DefaultOuterPadding);
            pdfBuilder.CreateInnerTableItemCells(
                    projectCostCentreTotalRow,
                    cellContent: cellContentTotals.ToArray());
            
            pdfBuilder.BlankRow();
        }
Example #22
0
        private void createNode(HNode node, TextState parentTextState)
        {
            TextState nodeTextState = new TextState();

            nodeTextState.ApplyChangesFrom(parentTextState);

            if (node is HNodeTag)
            {
                PUtil.TextStateUtil.TextState_ModifyFromHStyles((node as HNodeTag).Styles, nodeTextState);
            }

            // Block element
            if ((node is HNodeTag) && HUtil.TagUtil.IsBlockTag((node as HNodeTag).TagType))
            {
                addTextFragmentOnPage();
                createTextFragmentByTagType((node as HNodeTag).TagType);
            }
            // Inline element or Text element
            else if (
                (node is HNodeTag) && HUtil.TagUtil.IsInlineTag((node as HNodeTag).TagType)
                ||
                (node is HNodeText)
                )
            {
                if ((node is HNodeText) && (node as HNodeText).ParentNode != null && ((node as HNodeText).ParentNode is HNodeTag) && (((node as HNodeText).ParentNode as HNodeTag)).TagType == HTagType.button)
                {
                    //
                }
                else
                {
                    // Create TextSegment for element
                    TextSegment textSegment = getTextSegment(node, nodeTextState);

                    // New Line, <BR />
                    if (pdfNewLine != null)
                    {
                        double marginTop    = 0;
                        double marginBottom = 0;
                        if (pdfTextFragment != null)
                        {
                            marginBottom = pdfTextFragment.Margin.Bottom;
                            pdfTextFragment.Margin.Bottom = 0;
                        }

                        addTextFragmentOnPage();
                        createTextFragmentByTagType(HTagType.div);

                        if (pdfTextFragment != null)
                        {
                            pdfTextFragment.Margin.Top    = marginTop;
                            pdfTextFragment.Margin.Bottom = marginBottom;
                        }

                        pdfNewLine = null;
                    }
                    // Image
                    else if (pdfImage != null)
                    {
                        double     imageHeight = pdfImage.FixHeight;
                        MarginInfo margin      = new MarginInfo(0, 12, 0, 12);
                        if (pdfTextFragment == null || pdfTextFragment.Segments.Count == 0 || (pdfTextFragment.Segments.Count == 1 && pdfTextFragment.Segments[1].Text == String.Empty))
                        {
                        }
                        else
                        {
                            pdfTextFragment.Margin.Top += imageHeight;
                            margin = new MarginInfo(0, pdfTextFragment.Margin.Bottom, 0, -1 * imageHeight);
                        }

                        addTextFragmentOnPage(false);

                        pdfImage.IsInLineParagraph = true;
                        pdfImage.Margin            = margin;
                        inlineParagraphMargin      = margin;


                        if (hyperlinkNode != null)
                        {
                            Aspose.Pdf.WebHyperlink pdfHyperlink = new WebHyperlink(hyperlinkNode.GetAttribute("href", "#"));
                            pdfImage.Hyperlink = pdfHyperlink;
                        }

                        pdfPage.Paragraphs.Add(pdfImage);

                        if (node.NextNode == null)
                        {
                            updateCurrentPage();
                        }

                        pdfImage = null;
                    }
                    // Form Field Element
                    else if (pdfFormField != null)
                    {
                        //
                        //
                        //

                        double     inputHeight = pdfFormField.Height;
                        MarginInfo margin      = new MarginInfo(0, 12, 0, 12);
                        if (pdfTextFragment == null || pdfTextFragment.Segments.Count == 0 || (pdfTextFragment.Segments.Count == 1 && pdfTextFragment.Segments[1].Text == String.Empty))
                        {
                        }
                        else
                        {
                            double textFragmentHeight = pdfTextFragment.Rectangle.Height;

                            margin = pdfTextFragment.Margin;

                            pdfTextFragment.Margin.Bottom = textFragmentHeight - inputHeight;
                            pdfTextFragment.Margin.Top   += Math.Max(0, (inputHeight - textFragmentHeight));

                            pdfTextFragment.Margin.Top += inputHeight;
                        }


                        addTextFragmentOnPage(false);

                        pdfFormField.IsInLineParagraph = true;
                        pdfFormField.Margin            = margin;
                        inlineParagraphMargin          = new MarginInfo(pdfFormField.Width, margin.Bottom, margin.Right, margin.Top);


                        pdfPage.Paragraphs.Add(pdfFormField);

                        if (node.NextNode == null)
                        {
                            updateCurrentPage();
                        }

                        pdfFormField = null;
                    }
                    // TextFragment for InLineParagraph mode
                    else if (pdfTextFragment == null)
                    {
                        HTagType tagTypeForTextFragment           = HTagType.div;
                        bool     isInLineParagraphForTextFragment = false;


                        bool flagPreviousImage = false;
                        bool flagPreviousInput = false;

                        if (node.PrevNode != null && (node.PrevNode is HNodeTag) && (node.PrevNode as HNodeTag).TagType == HTagType.img)
                        {
                            // prev image element
                            if (node.ParentNode != null && (node.ParentNode is HNodeTag) && HUtil.TagUtil.IsBlockTag((node.ParentNode as HNodeTag).TagType))
                            {
                                tagTypeForTextFragment = (node.ParentNode as HNodeTag).TagType;
                            }

                            isInLineParagraphForTextFragment = true;
                            flagPreviousImage = true;
                        }
                        else if (node.PrevNode != null && (node.PrevNode is HNodeTag) && (node.PrevNode as HNodeTag).TagType == HTagType.input)
                        {
                            // prev input element
                            if (node.ParentNode != null && (node.ParentNode is HNodeTag) && HUtil.TagUtil.IsBlockTag((node.ParentNode as HNodeTag).TagType))
                            {
                                tagTypeForTextFragment = (node.ParentNode as HNodeTag).TagType;
                            }

                            isInLineParagraphForTextFragment = true;
                            flagPreviousInput = true;
                        }
                        else
                        {
                        }

                        createTextFragmentByTagType(tagTypeForTextFragment);
                        pdfTextFragment.IsInLineParagraph = isInLineParagraphForTextFragment;


                        if ((flagPreviousImage || flagPreviousInput) && inlineParagraphMargin != null)
                        {
                            pdfTextFragment.Margin.Top    = -1 * pdfTextFragment.Rectangle.Height - inlineParagraphMargin.Bottom;
                            pdfTextFragment.Margin.Bottom = inlineParagraphMargin.Bottom;

                            pdfTextFragment.Margin.Left = inlineParagraphMargin.Left;

                            inlineParagraphMargin = null;
                        }
                    }



                    if (textSegment != null && pdfTextFragment != null)
                    //if (textSegment != null)
                    {
                        pdfTextFragment.Segments.Add(textSegment);
                    }
                }
            }

            //
            // Create Nodes recursively with consider the hyperlink
            //
            if ((node is HNodeTag) && (node as HNodeTag).TagType == HTagType.a)
            {
                hyperlinkNode = (node as HNodeTag);
            }

            if (node is HNodeContainer)
            {
                foreach (HNode childNode in (node as HNodeContainer).ChildNodes)
                {
                    createNode(childNode, nodeTextState);
                }
            }

            if ((node is HNodeTag) && (node as HNodeTag).TagType == HTagType.a)
            {
                hyperlinkNode = null;
            }
            //
            //
            //


            //
            // Add Text Fragment on Page (if need)
            //
            if ((node is HNodeTag) && HUtil.TagUtil.IsBlockTag((node as HNodeTag).TagType))
            {
                addTextFragmentOnPage();
            }
            //
            //
            //
        }