Exemple #1
0
        internal async Task <BEncodedDictionary> CreateAsync(string name, List <TorrentFile> files, CancellationToken token)
        {
            if (!InfoDict.ContainsKey(PieceLengthKey))
            {
                PieceLength = RecommendedPieceSize(files);
            }

            BEncodedDictionary torrent = BEncodedValue.Clone(Metadata);
            var info = (BEncodedDictionary)torrent["info"];

            info["name"] = (BEncodedString)name;
            AddCommonStuff(torrent);

            info["pieces"] = (BEncodedString) await CalcPiecesHash(files, token);

            if (files.Count == 1 && files[0].Path == name)
            {
                CreateSingleFileTorrent(torrent, files);
            }
            else
            {
                CreateMultiFileTorrent(torrent, files);
            }

            return(torrent);
        }
Exemple #2
0
 internal static void AddDefaultExtraInfo(InfoDict infoDict, IInfoExtractor ie, string url)
 {
     if (Uri.TryCreate(url, UriKind.Absolute, out Uri result))
     {
         var dict = new Dictionary <string, object>()
         {
             { "extractor", ie.GetType().Name },
             { "extractor_key", ie.Name },
             { "webpage_url", url },
             { "webpage_url_basename", result.AbsolutePath }
         };
         infoDict.AddExtraInfo(dict, false);
     }
     else
     {
         var dict = new Dictionary <string, object>()
         {
             { "extractor", ie.GetType().Name },
             { "extractor_key", ie.Name },
             { "webpage_url", url },
             { "webpage_url_basename", url }
         };
         infoDict.AddExtraInfo(dict, false);
     }
 }
        public BEncodedValue GetCustomSecure(BEncodedString key)
        {
            CheckCanEditSecure();
            BEncodedValue value;

            if (InfoDict.TryGetValue(key, out value))
            {
                return(value);
            }
            return(null);
        }
Exemple #4
0
        /// <summary>
        /// Take the result of the ie (may be modified) and resolve all unresolved
        /// references (URLs, playlist items).
        /// It will also download the videos if 'download'.
        /// </summary>
        /// <returns>Returns the resolved ie_result.</returns>
        public async Task <InfoDict> ProcessIEResult(InfoDict ie_result, bool download = true, Dictionary <string, object> extra_info = null)
        {
            if (ie_result.GetType() == typeof(ContentUrl) ||
                ie_result.GetType() == typeof(TransparentUrl))
            {
                ContentUrl url = (ContentUrl)ie_result;
                url.Url = Util.SanitizeUrl(url.Url);
                if (Options.ExtractFlat != null)
                {
                    if ((Options.ExtractFlat == "in_playlist" && extra_info != null && extra_info.ContainsKey("playlist")) ||
                        (Options.ExtractFlat.ToUpper() == "TRUE"))
                    {
                        if (Options.ForceUrl && url.Url != null)
                        {
                            LogInfo(url.Url);
                        }
                        return(ie_result);
                    }
                }
            }

            if (ie_result is Video video)
            {
                video.AddExtraInfo(extra_info, false);
                return(await ProcessVideoResult(video, download).ConfigureAwait(false));
            }
            else if (ie_result is ContentUrl curl)
            {
                return(await ExtractInfoAsync(curl.Url, download, curl.IEKey, extra_info).ConfigureAwait(false));
            }
            else if (ie_result is TransparentUrl turl)
            {
                var info = await ExtractInfoAsync(turl.Url, false, turl.IEKey, extra_info, false).ConfigureAwait(false);

                if (info == null)
                {
                    return(info);
                }

                // *force properties*

                //if (info.Type == "url")
                //{
                //    info.Type = "url-transparent";
                //}
                return(await ProcessIEResult(info, download, extra_info).ConfigureAwait(false));
            }
            else if (ie_result is Playlist playlist)
            {
                return(await ProcessPlaylistResult(playlist, download).ConfigureAwait(false));
            }
            return(null);
        }
        public override InfoDict Extract(string url)
        {
            var state = GILState(true);

            try
            {
                ytdl.LogDebug("Extracting info from url...");
                dynamic info_dict = (extractorInstance as dynamic).extract(url);
                ytdl.LogDebug("Extracted: " + info_dict.get("title"));
                InfoDict ie_result = PyInfoDict.FromPythonDict(info_dict);
                //state.Dispose();


                return(ie_result);
            }
            catch (PythonException p)
            {
                state.Dispose();
                if (p.PythonTypeName == "ExtractorError")
                {
                    ytdl.LogError("Extractor error occurred: " + p.Message);
                    throw new ExtractorException(p.Message, p);
                }
                else if (p.PythonTypeName == "GeoRestrictionError")
                {
                    ytdl.LogError("Geo restriction error occurred");
                    throw new GeoRestrictionException(p.Message, p);
                }
                else if (p.PythonTypeName == "MaxDownloadsReachedError")
                {
                    ytdl.LogError("Max downloads reached");
                    throw new MaxDownloadsReachedException(p.Message, p);
                }
                else
                {
                    throw p;
                }
            }
            catch (Exception e)
            {
                state.Dispose();
                throw e;
            }
        }
Exemple #6
0
        public static async Task Test()
        {
            YouTubeDL ytdl = new YouTubeDL();
            await ytdl.CheckDownloadYTDLPython(false);

            ytdl.AddPythonExtractors();
            ytdl.Options.Format = "bestvideo+m4a/best";
            //ytdl.Options.ExtractFlat = "in_playlist";
            //ytdl.Options.MergeOutputFormat = "mp4";
            //ytdl.Options.Format = "bestaudio";
            //ytdl.Options.Verbose = true;
            //InfoDict dict = await ytdl.GetSearchResults("far out - overdrive", 10);
            //InfoDict dict = await ytdl.ExtractInfoAsync("https://www.youtube.com/playlist?list=PL8SwD_foum9yWCuNn1IyqkZI7EMmnzxcr", download: false);
            InfoDict dict = await ytdl.ExtractInfoAsync("https://www.youtube.com/watch?v=X1jMMFOqxEw"); //https://www.youtube.com/watch?v=oP8TAcUc17w");

            if (dict is Video video)
            {
                Console.WriteLine("YoutubeDL for .NET Extracted Video " + video.Id + ": " + video.Title);
            }
            if (dict is Playlist playlist)
            {
                Console.WriteLine("YoutubeDL for .NET Extracted Playlist " + playlist.Id + ": " + playlist.Title);
                foreach (ContentUrl d in playlist.Entries)
                {
                    //Console.WriteLine(d.GetType().Name + ":");
                    foreach (var prop in d.AdditionalProperties)
                    {
                        //Console.WriteLine(prop.Key + " = " + prop.Value);
                    }
                }

                //await ytdl.ProcessIEResult(playlist.Entries[0], true);
            }

            //InfoDict dict2 = ytdl.ExtractInfo("https://www.youtube.com/watch?v=X1jMMFOqxEw");
        }
 public void RemoveCustomSecure(BEncodedString key)
 {
     CheckCanEditSecure();
     Check.Key(key);
     InfoDict.Remove(key);
 }
Exemple #8
0
        // update the view
        public void preview(object sender, EventArgs e)
        {
            Sales_Order createSalesOrder = (Sales_Order)((Button)sender).FindForm();

            try
            {
                //start creating the PDF

                //Create a Catalog Dictionary
                CatalogDict catalogDict = new CatalogDict();

                //Create a Page Tree Dictionary
                PageTreeDict pageTreeDict = new PageTreeDict();

                //Create a Font Dictionary - Only the standard fonts Time, Helvetica and courier etc can be created by this method.
                //See Adobe doco for more info on other fonts
                FontDict TimesRoman  = new FontDict();
                FontDict TimesItalic = new FontDict();
                FontDict TimesBold   = new FontDict();
                FontDict Courier     = new FontDict();

                //Create the info Dictionary
                InfoDict infoDict = new InfoDict();

                //Create the font called Times Roman
                TimesRoman.CreateFontDict("T1", "Times-Roman");

                //Create the font called Times Italic
                TimesItalic.CreateFontDict("T2", "Times-Italic");

                //Create the font called Times Bold
                TimesBold.CreateFontDict("T3", "Times-Bold");

                //Create the font called Courier
                Courier.CreateFontDict("T4", "Courier");

                //Set the info Dictionary. xxx will be the invoice number
                infoDict.SetInfo("Sales Order xxx", "System Generated", "My Company Name");

                //Create a utility object
                Utility pdfUtility = new Utility();

                //Open a file specifying the file name as the output pdf file
                String FilePath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory) + "\\Resources\\SalesOrder.pdf";

                FileStream file = new FileStream(FilePath, FileMode.Create);
                int        size = 0;
                file.Write(pdfUtility.GetHeader("1.5", out size), 0, size);
                file.Close();

                //Finished the first step



                //Create a Page Dictionary , this represents a visible page
                PageDict    page    = new PageDict();
                ContentDict content = new ContentDict();

                //The page size object will hold all the page size information
                //also holds the dictionary objects for font, images etc.
                //A4 595,842
                //Letter 612,792
                PageSize pSize = new PageSize(612, 792); //A4 paper portrait in 1/72" measurements
                pSize.SetMargins(10, 10, 10, 10);

                //create the page main details
                page.CreatePage(pageTreeDict.objectNum, pSize);

                //add a page
                pageTreeDict.AddPage(page.objectNum);

                //add the fonts to this page
                page.AddResource(TimesRoman, content.objectNum);
                page.AddResource(TimesItalic, content.objectNum);
                page.AddResource(TimesBold, content.objectNum);
                page.AddResource(Courier, content.objectNum);

                //Create a Text And Table Object that presents the text elements in the page
                TextAndTables textAndtable = new TextAndTables(pSize);

                //create the reference to an image and the data that represents it
                String    ImagePath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory) + "\\Resources\\logo.jpg"; //file path to image source
                ImageDict I1        = new ImageDict();                                                                         //new image dictionary object
                I1.CreateImageDict("I1", ImagePath);                                                                           //create the object which describes the image
                page.AddImageResource(I1.PDFImageName, I1, content.objectNum);                                                 //create a reference where the PDF can identify which object
                //describes the image when we want to draw it on the page

                /*
                 * draw the image to page (add the instruction to the content stream which says draw the image called I1 starting
                 * at X = 269, Y = 20 and with an ACTUAL image size on the page of w = 144 and h = 100)
                 */
                PageImages pi = new PageImages();
                content.SetStream(pi.ShowImage("I1", 400, 680, 155, 85));   //tell the PDF we want to draw an image called 'I1', where and what size

                String[] sAd = new String[6];
                sAd = new ServiceAddress().get(createSalesOrder.getServiceAddressId()).Split(',');

                String[] client = new String[9];
                client = new Client().get(new ClientContract().getClient(createSalesOrder.getServiceAddressId())).Split(',');

                //Add text to the page
                textAndtable.AddText(50, 100, "Work Order ID: " + createSalesOrder.getId(), 10, "T3", Align.LeftAlign);
                //textAndtable.AddText(50, 60, "Total: " + txtTotal.Text, 10, "T3", Align.LeftAlign);

                textAndtable.AddText(50, 150, "General", 10, "T3", Align.LeftAlign);
                //textAndtable.AddText(50, 160, "Label: ", 10, "T3", Align.LeftAlign);
                textAndtable.AddText(50, 170, "Client: " + client[0], 10, "T3", Align.LeftAlign);
                textAndtable.AddText(50, 180, "Phone: " + client[3], 10, "T1", Align.LeftAlign);
                textAndtable.AddText(50, 190, "Booked By: ", 10, "T1", Align.LeftAlign);

                textAndtable.AddText(300, 150, "Place and Time", 10, "T3", Align.LeftAlign);
                textAndtable.AddText(300, 160, "Service Address: ", 10, "T1", Align.LeftAlign);
                textAndtable.AddText(370, 160, sAd[0], 10, "T1", Align.LeftAlign);
                textAndtable.AddText(370, 170, sAd[3] + ", " + sAd[4] + ", " + sAd[5] + " " + sAd[1], 10, "T1", Align.LeftAlign);
                textAndtable.AddText(300, 180, "On-site Contact: " + sAd[2], 10, "T1", Align.LeftAlign);
                textAndtable.AddText(300, 190, "Start: ", 10, "T1", Align.LeftAlign);
                textAndtable.AddText(300, 200, "End: ", 10, "T1", Align.LeftAlign);
                textAndtable.AddText(300, 210, "Duration: ", 10, "T1", Align.LeftAlign);

                textAndtable.AddText(300, 230, "Special Instructions", 10, "T3", Align.LeftAlign);
                textAndtable.AddText(300, 240, "Call Ahead Required", 10, "T1", Align.LeftAlign);
                textAndtable.AddText(300, 250, "Crews Assigned", 10, "T3", Align.LeftAlign);
                textAndtable.AddText(300, 260, "None Assigned", 10, "T1", Align.LeftAlign);

                //Add table to the page
                Align[] alignC = new Align[4];
                alignC[0] = Align.CenterAlign;
                alignC[1] = Align.CenterAlign;
                alignC[2] = Align.CenterAlign;
                alignC[3] = Align.CenterAlign;

                Align[] alignR = new Align[4];
                alignR[0] = Align.LeftAlign;
                alignR[1] = Align.LeftAlign;
                alignR[2] = Align.LeftAlign;
                alignR[3] = Align.LeftAlign;

                //Specify the color for the cell and the line
                ColorSpec cellColor = new ColorSpec(196, 34, 34);
                ColorSpec lineColor = new ColorSpec(1, 1, 1);

                //Fill in the parameters for the table
                TableParams table = new TableParams(4, 235, 90, 75, 75);
                table.yPos      = 550;
                table.xPos      = 50;
                table.rowHeight = 15;

                //Set the parameters of this table
                textAndtable.SetParams(table, cellColor, Align.CenterAlign, 3);
                //After drawing table and text add them to the page
                content.SetStream(textAndtable.EndTable(lineColor, true));

                Align[] alignC2 = new Align[7];
                alignC2[0] = Align.CenterAlign;
                alignC2[1] = Align.CenterAlign;
                alignC2[2] = Align.CenterAlign;
                alignC2[3] = Align.CenterAlign;
                alignC2[4] = Align.CenterAlign;
                alignC2[5] = Align.CenterAlign;
                alignC2[6] = Align.CenterAlign;


                Align[] alignR2 = new Align[7];
                alignR2[0] = Align.LeftAlign;
                alignR2[1] = Align.LeftAlign;
                alignR2[2] = Align.LeftAlign;
                alignR2[3] = Align.LeftAlign;
                alignR2[4] = Align.RightAlign;
                alignR2[5] = Align.RightAlign;
                alignR2[6] = Align.RightAlign;

                TextAndTables textAndtable3 = new TextAndTables(pSize);
                //Specify the color for the cell and the line
                ColorSpec   cell2  = new ColorSpec(128, 128, 128);
                ColorSpec   line2  = new ColorSpec(1, 1, 1);
                TableParams table3 = new TableParams(7, 15, 100, 160, 40, 40, 60, 60);
                table3.yPos      = 510;
                table3.xPos      = 50;
                table3.rowHeight = 15;
                textAndtable3.SetParams(table3, cell2, Align.CenterAlign, 3);
                textAndtable3.AddRow(false, 8, "T3", alignC2, true, "#", "Item", "Description", "Hours", "Qty", "Price", "Line Total");
                content.SetStream(textAndtable3.EndTable(line2, true));


                TextAndTables textAndtable4 = new TextAndTables(pSize);
                //Specify the color for the cell and the line
                ColorSpec   cell3  = new ColorSpec(255, 255, 255);
                ColorSpec   line3  = new ColorSpec(1, 1, 1);
                TableParams table4 = new TableParams(7, 15, 100, 160, 40, 40, 60, 60);
                table4.yPos      = 495;
                table4.xPos      = 50;
                table4.rowHeight = 15;
                textAndtable4.SetParams(table4, cell3, Align.CenterAlign, 3);
                DataGridView dgvSalesOrder = createSalesOrder.getOrderItems();
                for (int i = 0; i < dgvSalesOrder.Rows.Count - 1; i++)
                {
                    textAndtable4.AddRow(false, 8, "T3", alignR2, false, dgvSalesOrder.Rows[i].Cells[0].Value.ToString(),
                                         dgvSalesOrder.Rows[i].Cells[1].FormattedValue.ToString(), dgvSalesOrder.Rows[i].Cells[2].Value.ToString(),
                                         (dgvSalesOrder.Rows[i].Cells[3].Value == null || dgvSalesOrder.Rows[i].Cells[3].Value.ToString() == "") ? "-" : dgvSalesOrder.Rows[i].Cells[3].Value.ToString(),
                                         (dgvSalesOrder.Rows[i].Cells[4].Value == null || dgvSalesOrder.Rows[i].Cells[4].Value.ToString() == "") ? "-" : dgvSalesOrder.Rows[i].Cells[4].Value.ToString(),
                                         dgvSalesOrder.Rows[i].Cells[5].Value.ToString(), dgvSalesOrder.Rows[i].Cells[6].Value.ToString());
                }
                content.SetStream(textAndtable4.EndTable(line3, true));



                textAndtable.AddText(400, 650, "Subtotal: ", 10, "T1", Align.LeftAlign);
                textAndtable.AddText(400, 665, "HST(" + (tax * 100) + "%): ", 10, "T1", Align.LeftAlign);
                textAndtable.AddText(400, 680, "Total: ", 10, "T1", Align.LeftAlign);

                TextAndTables textAndtable5 = new TextAndTables(pSize);
                Align[]       align         = new Align[1];
                align[0] = Align.RightAlign;
                //Specify the color for the cell and the line
                TableParams table5 = new TableParams(1, 60);
                table5.yPos      = 152;
                table5.xPos      = 100;
                table5.rowHeight = 15;
                textAndtable5.SetParams(table5, cell3, Align.RightAlign, 3);
                textAndtable5.AddRow(false, 10, "T3", align, false, createSalesOrder.getSubtotal());
                textAndtable5.AddRow(false, 10, "T3", align, false, createSalesOrder.getHST());
                content.SetStream(textAndtable5.EndTable(line3, true));

                TextAndTables textAndtable6 = new TextAndTables(pSize);
                //Specify the color for the cell and the line
                TableParams table6 = new TableParams(1, 60);
                table6.yPos      = 122;
                table6.xPos      = 100;
                table6.rowHeight = 15;
                textAndtable6.SetParams(table6, cell2, Align.RightAlign, 3);
                textAndtable6.AddRow(false, 10, "T3", align, true, "$" + createSalesOrder.getTotal());
                content.SetStream(textAndtable6.EndTable(line2, true));

                content.SetStream(textAndtable.EndText());

                //All done - send the information to the PDF file

                size = 0;
                file = new FileStream(FilePath, FileMode.Append);
                file.Write(page.GetPageDict(file.Length, out size), 0, size);
                file.Write(content.GetContentDict(file.Length, out size), 0, size);
                file.Close();

                file = new FileStream(FilePath, FileMode.Append);
                file.Write(catalogDict.GetCatalogDict(pageTreeDict.objectNum, file.Length, out size), 0, size);
                file.Write(pageTreeDict.GetPageTree(file.Length, out size), 0, size);
                file.Write(TimesRoman.GetFontDict(file.Length, out size), 0, size);
                file.Write(TimesItalic.GetFontDict(file.Length, out size), 0, size);
                file.Write(TimesBold.GetFontDict(file.Length, out size), 0, size);
                file.Write(Courier.GetFontDict(file.Length, out size), 0, size);

                //write image dict
                file.Write(I1.GetImageDict(file.Length, out size), 0, size);

                file.Write(infoDict.GetInfoDict(file.Length, out size), 0, size);
                file.Write(pdfUtility.CreateXrefTable(file.Length, out size), 0, size);
                file.Write(pdfUtility.GetTrailer(catalogDict.objectNum, infoDict.objectNum, out size), 0, size);
                file.Close();

                //Messages.Visible = true;
                Preview testDialog = new Preview(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory) + "\\Resources\\SalesOrder.pdf");
                testDialog.ShowDialog();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Could not display the document because " + ex.ToString());
            }
        }
Exemple #9
0
        static void Main(string[] args)
        {
            //Create a Catalog Dictionary
            CatalogDict catalogDict = new CatalogDict();

            //Create a Page Tree Dictionary
            PageTreeDict pageTreeDict = new PageTreeDict();

            //Create a Font Dictionary
            FontDict TimesRoman  = new FontDict();
            FontDict TimesItalic = new FontDict();

            //Create the info Dictionary
            InfoDict infoDict = new InfoDict();

            //Create the font called Times Roman
            TimesRoman.CreateFontDict("T1", "Times-Roman");

            //Create the font called Times Italic
            TimesItalic.CreateFontDict("T2", "Times-Italic");

            //Set the info Dictionary.
            infoDict.SetInfo("title", "author", "company");

            //Create a utility object
            Utility pdfUtility = new Utility();

            //Open a file specifying the file name as the output pdffile
            FileStream file = new FileStream(@"D:\text.pdf", FileMode.Create);

            file.Write(pdfUtility.GetHeader("1.5", out int size), 0, size);
            file.Close();
            //Now we finished doing the first step

            /*************************************************************/
            //Create a Page Dictionary , this represents a visible page
            PageDict    page    = new PageDict();
            ContentDict content = new ContentDict();

            //The page size object will hold all the page size information
            PageSize pSize = new PageSize(612, 792);

            pSize.SetMargins(10, 10, 10, 10);
            page.CreatePage(pageTreeDict.objectNum, pSize);
            pageTreeDict.AddPage(page.objectNum);
            page.AddResource(TimesRoman, content.objectNum);

            //Create a Text And Table Object that present the elements in the page
            TextAndTables textAndtable = new TextAndTables(pSize);

            //Add text to the page
            textAndtable.AddText(20, 10, "Testing", 10, "T1", Align.CenterAlign);

            //Create the array for alignment value.
            //This is specified for text in each column
            //of the table, here we have two columns
            Align[] align = new Align[2];
            align[0] = Align.LeftAlign;
            align[1] = Align.LeftAlign;

            //Specify the color for the cell and the line
            ColorSpec cellColor = new ColorSpec(100, 100, 100);
            ColorSpec lineColor = new ColorSpec(98, 200, 200);

            //Fill in the parameters for the table
            TableParams table = new TableParams(2, 200, 200);

            table.yPos      = 700;
            table.xPos      = 100;
            table.rowHeight = 20;

            //Set the parameters of this table
            textAndtable.SetParams(table, cellColor, Align.CenterAlign, 3);
            textAndtable.AddRow(false, 10, "T1", align, "First Column", "Second Column");
            textAndtable.AddRow(false, 10, "T1", align, "Second Row", "Second Row");

            //Repeat till we require the number of rows.
            //After drawing table and text add them to the page
            content.SetStream(textAndtable.EndTable(lineColor));
            content.SetStream(textAndtable.EndText());
            size = 0;
            file = new FileStream(@"D:\text.pdf", FileMode.Append);
            file.Write(page.GetPageDict(file.Length, out size), 0, size);
            file.Write(content.GetContentDict(file.Length, out size), 0, size);
            file.Close();
            /**********************************3***************************/
            //Write everything file size=0;
            file = new FileStream(@"D:\text.pdf", FileMode.Append);
            file.Write(catalogDict.GetCatalogDict(pageTreeDict.objectNum,
                                                  file.Length, out size), 0, size);
            file.Write(pageTreeDict.GetPageTree(file.Length, out size), 0, size);
            file.Write(TimesRoman.GetFontDict(file.Length, out size), 0, size);
            file.Write(TimesItalic.GetFontDict(file.Length, out size), 0, size);
            file.Write(infoDict.GetInfoDict(file.Length, out size), 0, size);
            file.Write(pdfUtility.CreateXrefTable(file.Length, out size), 0, size);
            file.Write(pdfUtility.GetTrailer(catalogDict.objectNum,
                                             infoDict.objectNum, out size), 0, size);
            file.Close();

            Console.ReadKey();
        }
Exemple #10
0
        private void generateStatement()
        {
            try
            {
                //start creating the PDF

                //Create a Catalog Dictionary
                CatalogDict catalogDict = new CatalogDict();

                //Create a Page Tree Dictionary
                PageTreeDict pageTreeDict = new PageTreeDict();

                //Create a Font Dictionary - Only the standard fonts Time, Helvetica and courier etc can be created by this method.
                //See Adobe doco for more info on other fonts
                FontDict TimesRoman  = new FontDict();
                FontDict TimesItalic = new FontDict();
                FontDict TimesBold   = new FontDict();
                FontDict Courier     = new FontDict();

                //Create the info Dictionary
                InfoDict infoDict = new InfoDict();
                Invoice  invoice  = new Invoice();
                //Create the font called Times Roman
                TimesRoman.CreateFontDict("T1", "Times-Roman");

                //Create the font called Times Italic
                TimesItalic.CreateFontDict("T2", "Times-Italic");

                //Create the font called Times Bold
                TimesBold.CreateFontDict("T3", "Times-Bold");

                //Create the font called Courier
                Courier.CreateFontDict("T4", "Times-Roman");

                //Set the info Dictionary. xxx will be the invoice number
                infoDict.SetInfo("Statement of " + cbClients.Text, "System Generated", "Fire-Alert");

                //Create a utility object
                Utility pdfUtility = new Utility();
                String  FilePath   = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory) + "\\Resources\\Statement_" + cbClients.SelectedValue + ".pdf";

                //Open a file specifying the file name as the output pdf file
                //String FilePath = @"C:\Users\Hassan\Desktop\Preview.pdf";

                FileStream file = new FileStream(FilePath, FileMode.Create);
                int        size = 0;
                file.Write(pdfUtility.GetHeader("1.5", out size), 0, size);
                file.Close();

                //Finished the first step



                //Create a Page Dictionary , this represents a visible page
                PageDict    page    = new PageDict();
                ContentDict content = new ContentDict();

                //The page size object will hold all the page size information
                //also holds the dictionary objects for font, images etc.
                //A4 595,842
                //Letter 612,792
                PageSize pSize = new PageSize(612, 792); //A4 paper portrait in 1/72" measurements
                pSize.SetMargins(10, 10, 10, 10);

                //create the page main details
                page.CreatePage(pageTreeDict.objectNum, pSize);

                //add a page
                pageTreeDict.AddPage(page.objectNum);

                //add the fonts to this page
                page.AddResource(TimesRoman, content.objectNum);
                page.AddResource(TimesItalic, content.objectNum);
                page.AddResource(TimesBold, content.objectNum);
                page.AddResource(Courier, content.objectNum);

                //Create a Text And Table Object that presents the text elements in the page
                TextAndTables textAndtable = new TextAndTables(pSize);


                //create the reference to an image and the data that represents it
                String    ImagePath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory) + "\\Resources\\logo.jpg"; //file path to image source
                ImageDict I1        = new ImageDict();                                                                         //new image dictionary object
                I1.CreateImageDict("I1", ImagePath);                                                                           //create the object which describes the image
                page.AddImageResource(I1.PDFImageName, I1, content.objectNum);                                                 //create a reference where the PDF can identify which object
                //describes the image when we want to draw it on the page

                /*
                 * draw the image to page (add the instruction to the content stream which says draw the image called I1 starting
                 * at X = 269, Y = 20 and with an ACTUAL image size on the page of w = 144 and h = 100)
                 */
                PageImages pi = new PageImages();
                content.SetStream(pi.ShowImage("I1", 450, 690, 155, 85));   //tell the PDF we want to draw an image called 'I1', where and what size



                String   clientInfo = new Client().get(cbClients.SelectedValue.ToString());
                String[] client     = new String[9];
                client = clientInfo.Split(',');

                String   franchiseeInfo = new Franchisee().get(new ClientContract().getFranchiseeOfClient(cbClients.SelectedValue.ToString()));
                String[] franchisee     = new String[6];
                franchisee = franchiseeInfo.Split(',');

                if (franchisee.Length < 6)
                {
                    franchisee = new String[6] {
                        "", "", "", "", "", ""
                    }
                }
                ;

                String   userInfo = new Users().get(userid.ToString());
                String[] user     = new String[4];
                user = userInfo.Split(',');

                //Add text to the page
                textAndtable.AddText(260, 50, "STATEMENT", 20, "T3", Align.LeftAlign);
                textAndtable.AddText(50, 80, franchisee[5], 16, "T3", Align.LeftAlign);
                textAndtable.AddText(50, 90, franchisee[0], 10, "T3", Align.LeftAlign);
                textAndtable.AddText(50, 100, franchisee[2] + ", " + franchisee[3] + ", " + franchisee[4] + " " + franchisee[1], 10, "T3", Align.LeftAlign);
                textAndtable.AddText(50, 110, user[2], 10, "T3", Align.LeftAlign);
                // textAndtable.AddText(50, 60, "Total: " + txtTotal.Text, 10, "T3", Align.LeftAlign);


                textAndtable.AddText(50, 190, client[0], 10, "T3", Align.LeftAlign);
                textAndtable.AddText(50, 205, client[5], 10, "T4", Align.LeftAlign);
                textAndtable.AddText(50, 215, client[1], 10, "T4", Align.LeftAlign);
                textAndtable.AddText(50, 225, client[6] + ", " + client[7] + " " + client[2], 10, "T4", Align.LeftAlign);
                textAndtable.AddText(50, 235, client[8], 10, "T4", Align.LeftAlign);

                textAndtable.AddText(430, 150, "PLEASE RETURN THIS PORTION WITH", 8, "T4", Align.LeftAlign);
                textAndtable.AddText(430, 160, "YOUR PAYMENT", 8, "T4", Align.LeftAlign);
                textAndtable.AddText(400, 175, client[0], 10, "T3", Align.LeftAlign);
                textAndtable.AddText(430, 210, "IF PAYING BY INVOICE CHECK", 8, "T4", Align.LeftAlign);
                textAndtable.AddText(430, 220, "INDIVIDUAL INVOICES PAID", 8, "T4", Align.LeftAlign);
                textAndtable.AddText(435, 240, "AMOUNT REMITTED __________", 8, "T4", Align.LeftAlign);

                Align[] alignC = new Align[1];
                alignC[0] = Align.CenterAlign;

                //Specify the color for the cell and the line
                ColorSpec cellColor = new ColorSpec(255, 255, 255);
                ColorSpec lineColor = new ColorSpec(1, 1, 1);

                //Fill in the parameters for the table
                TableParams table = new TableParams(1, 100);
                table.yPos      = 700;
                table.xPos      = 50;
                table.rowHeight = 15;

                //Set the parameters of this table
                textAndtable.SetParams(table, cellColor, Align.RightAlign, 3);
                textAndtable.AddRow(false, 10, "T3", alignC, false, "Statement Date");
                textAndtable.AddRow(false, 10, "T4", alignC, false, DateTime.Today.ToShortDateString());

                //After drawing table and text add them to the page
                content.SetStream(textAndtable.EndTable(lineColor, true));

                table.yPos = 630;
                table.xPos = 0;
                //Set the parameters of this table
                textAndtable.SetParams(table, cellColor, Align.CenterAlign, 3);
                textAndtable.AddRow(false, 10, "T3", alignC, false, "Statement Date");
                textAndtable.AddRow(false, 10, "T4", alignC, false, DateTime.Today.ToShortDateString());

                //After drawing table and text add them to the page
                content.SetStream(textAndtable.EndTable(lineColor, true));

                textAndtable.AddText(50, 275, "Page:    1", 10, "T4", Align.LeftAlign);
                Align[] alignC1 = new Align[5];
                alignC1[0] = Align.CenterAlign;
                alignC1[1] = Align.CenterAlign;
                alignC1[2] = Align.CenterAlign;
                alignC1[3] = Align.CenterAlign;
                alignC1[4] = Align.CenterAlign;

                Align[] alignC2 = new Align[5];
                alignC2[0] = Align.LeftAlign;
                alignC2[1] = Align.LeftAlign;
                alignC2[2] = Align.RightAlign;
                alignC2[3] = Align.RightAlign;
                alignC2[4] = Align.CenterAlign;

                //Fill in the parameters for the table
                TableParams table2 = new TableParams(5, 150, 90, 90, 90, 40);
                table2.yPos      = 510;
                table2.xPos      = 37;
                table2.rowHeight = 15;

                //Set the parameters of this table
                textAndtable.SetParams(table2, cellColor, Align.LeftAlign, 3);
                // MessageBox.Show("\u221A");
                textAndtable.AddRow(false, 10, "T3", alignC1, false, "Statement Date", "Invoice No.", "Balance", "Total Due", "");
                String[] rows          = new Invoice().getOutstandingInvoices(cbClients.SelectedValue.ToString());
                double   total         = 0;
                double   interestTotal = 0;
                double   interest      = 0;
                double   below30       = 0;
                double   between3160   = 0;
                double   over60        = 0;
                DateTime interestDate  = DateTime.Today.Date.AddDays(-30);
                for (int i = 0; i < rows.Length; i++)
                {
                    String[] cells = new String[3];
                    cells  = rows[i].Split(',');
                    total += Convert.ToDouble(cells[2]);
                    if (Convert.ToDateTime(cells[0]) < interestDate)
                    {
                        interestTotal += Convert.ToDouble(cells[2]);
                    }
                    if (Convert.ToDateTime(cells[0]) > interestDate)
                    {
                        below30 += Convert.ToDouble(cells[2]);
                    }
                    if (Convert.ToDateTime(cells[0]) < DateTime.Today.Date.AddDays(-30) && Convert.ToDateTime(cells[0]) >= DateTime.Today.Date.AddDays(-60))
                    {
                        between3160 += Convert.ToDouble(cells[2]);
                    }
                    if (Convert.ToDateTime(cells[0]) < DateTime.Today.Date.AddDays(-60))
                    {
                        over60 += Convert.ToDouble(cells[2]);
                    }
                    Console.WriteLine(cells[0] + " " + cells[1]);
                    textAndtable.AddRow(false, 10, "T4", alignC2, false, cells[0], cells[1], "$" + cells[2], "$" + total.ToString(), "");
                }
                interest = interestTotal * 0.02;
                total   += interest;
                below30 += interest;
                textAndtable.AddRow(false, 10, "T4", alignC2, false, "2% interest on balance over 30 days", "", "$" + (interest).ToString(), "$" + total.ToString(), "");

                //After drawing table and text add them to the page
                content.SetStream(textAndtable.EndTable(lineColor, true));

                Align[] alignC3 = new Align[5];
                alignC3[0] = Align.LeftAlign;
                alignC3[1] = Align.RightAlign;
                alignC3[2] = Align.RightAlign;
                alignC3[3] = Align.RightAlign;
                alignC3[4] = Align.CenterAlign;

                //Fill in the parameters for the table  120,100,100,100,40 = 460
                TableParams table3 = new TableParams(5, 100, 90, 90, 90, 90);
                table3.yPos      = 100;
                table3.xPos      = 37;
                table3.rowHeight = 15;

                //Set the parameters of this table
                textAndtable.SetParams(table3, cellColor, Align.LeftAlign, 3);
                // MessageBox.Show("\u221A");
                textAndtable.AddRow(false, 10, "T3", alignC3, false, "Age", "Current ", "31-60 ", "Over 60 ", "Total");
                textAndtable.AddRow(false, 10, "T3", alignC3, false, "Amount", below30.ToString(), between3160.ToString(), over60.ToString(), total.ToString());
                content.SetStream(textAndtable.EndTable(lineColor, true));

                content.SetStream(textAndtable.EndText());


                //All done - send the information to the PDF file

                size = 0;
                file = new FileStream(FilePath, FileMode.Append);
                file.Write(page.GetPageDict(file.Length, out size), 0, size);
                file.Write(content.GetContentDict(file.Length, out size), 0, size);
                file.Close();

                file = new FileStream(FilePath, FileMode.Append);
                file.Write(catalogDict.GetCatalogDict(pageTreeDict.objectNum, file.Length, out size), 0, size);
                file.Write(pageTreeDict.GetPageTree(file.Length, out size), 0, size);
                file.Write(TimesRoman.GetFontDict(file.Length, out size), 0, size);
                file.Write(TimesItalic.GetFontDict(file.Length, out size), 0, size);
                file.Write(TimesBold.GetFontDict(file.Length, out size), 0, size);
                file.Write(Courier.GetFontDict(file.Length, out size), 0, size);

                //write image dict
                file.Write(I1.GetImageDict(file.Length, out size), 0, size);

                file.Write(infoDict.GetInfoDict(file.Length, out size), 0, size);
                file.Write(pdfUtility.CreateXrefTable(file.Length, out size), 0, size);
                file.Write(pdfUtility.GetTrailer(catalogDict.objectNum, infoDict.objectNum, out size), 0, size);
                file.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Could not display the document because " + ex.ToString());
            }
        }
Exemple #11
0
        // update the view
        public void Preview(String address, String clientInfo, String franchiseeInfo)
        {
            try
            {
                //start creating the PDF

                //Create a Catalog Dictionary
                CatalogDict catalogDict = new CatalogDict();

                //Create a Page Tree Dictionary
                PageTreeDict pageTreeDict = new PageTreeDict();

                //Create a Font Dictionary - Only the standard fonts Time, Helvetica and courier etc can be created by this method.
                //See Adobe doco for more info on other fonts
                FontDict TimesRoman  = new FontDict();
                FontDict TimesItalic = new FontDict();
                FontDict TimesBold   = new FontDict();
                FontDict Courier     = new FontDict();

                //Create the info Dictionary
                InfoDict infoDict = new InfoDict();
                Invoice  invoice  = new Invoice();
                //Create the font called Times Roman
                TimesRoman.CreateFontDict("T1", "Times-Roman");

                //Create the font called Times Italic
                TimesItalic.CreateFontDict("T2", "Times-Italic");

                //Create the font called Times Bold
                TimesBold.CreateFontDict("T3", "Times-Bold");

                //Create the font called Courier
                Courier.CreateFontDict("T4", "Courier");

                //Set the info Dictionary. xxx will be the invoice number
                infoDict.SetInfo("Invoice " + invoice.getID(), "System Generated", "Fire-Alert");

                //Create a utility object
                Utility pdfUtility = new Utility();
                String  FilePath   = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory) + "\\Resources\\Invoice.pdf";

                //Open a file specifying the file name as the output pdf file

                FileStream file = new FileStream(FilePath, FileMode.Create);
                int        size = 0;
                file.Write(pdfUtility.GetHeader("1.5", out size), 0, size);
                file.Close();

                //Finished the first step
                //Create a Page Dictionary , this represents a visible page
                PageDict    page    = new PageDict();
                ContentDict content = new ContentDict();

                //The page size object will hold all the page size information
                //also holds the dictionary objects for font, images etc.
                //A4 595,842
                //Letter 612,792
                PageSize pSize = new PageSize(612, 792); //A4 paper portrait in 1/72" measurements
                pSize.SetMargins(10, 10, 10, 10);

                //create the page main details
                page.CreatePage(pageTreeDict.objectNum, pSize);

                //add a page
                pageTreeDict.AddPage(page.objectNum);

                //add the fonts to this page
                page.AddResource(TimesRoman, content.objectNum);
                page.AddResource(TimesItalic, content.objectNum);
                page.AddResource(TimesBold, content.objectNum);
                page.AddResource(Courier, content.objectNum);

                //Create a Text And Table Object that presents the text elements in the page
                TextAndTables textAndtable = new TextAndTables(pSize);

                //create the reference to an image and the data that represents it
                String    ImagePath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory) + "\\Resources\\logo.jpg"; //file path to image source
                ImageDict I1        = new ImageDict();                                                                         //new image dictionary object
                I1.CreateImageDict("I1", ImagePath);                                                                           //create the object which describes the image
                page.AddImageResource(I1.PDFImageName, I1, content.objectNum);                                                 //create a reference where the PDF can identify which object
                //describes the image when we want to draw it on the page

                /*
                 * draw the image to page (add the instruction to the content stream which says draw the image called I1 starting
                 * at X = 269, Y = 20 and with an ACTUAL image size on the page of w = 144 and h = 100)
                 */
                PageImages pi = new PageImages();
                content.SetStream(pi.ShowImage("I1", 400, 680, 155, 85));   //tell the PDF we want to draw an image called 'I1', where and what size

                String[] sAd = new String[6];
                sAd = address.Split(',');

                String[] client = new String[9];
                client = clientInfo.Split(',');


                String[] franchisee = new String[6];
                franchisee = franchiseeInfo.Split(',');

                String   userInfo = new Users().get(userid.ToString());
                String[] user     = new String[4];
                user = userInfo.Split(',');

                //Add text to the page
                textAndtable.AddText(50, 50, "Invoice: " + invoice.getID(), 10, "T3", Align.LeftAlign);
                textAndtable.AddText(50, 60, "Total: " + txtTotal.Text, 10, "T3", Align.LeftAlign);


                textAndtable.AddText(50, 100, "Bill To: " + client[0], 10, "T3", Align.LeftAlign);
                textAndtable.AddText(50, 110, client[4], 10, "T1", Align.LeftAlign);
                textAndtable.AddText(50, 120, client[6] + ", " + client[7] + ", " + client[8] + " " + client[2], 10, "T1", Align.LeftAlign);
                textAndtable.AddText(50, 130, "Primary Contact: " + client[5], 10, "T1", Align.LeftAlign);
                textAndtable.AddText(50, 140, "Ph: " + client[3], 10, "T1", Align.LeftAlign);


                textAndtable.AddText(300, 100, "Forward Payment To: ", 10, "T3", Align.LeftAlign);
                textAndtable.AddText(300, 110, franchisee[5], 10, "T3", Align.LeftAlign);
                textAndtable.AddText(300, 120, franchisee[0], 10, "T1", Align.LeftAlign);
                textAndtable.AddText(300, 130, franchisee[2] + ", " + franchisee[3] + ", " + franchisee[4] + " " + franchisee[1], 10, "T1", Align.LeftAlign);
                textAndtable.AddText(300, 140, "Contact: " + user[0] + " " + user[1], 10, "T1", Align.LeftAlign);
                textAndtable.AddText(300, 150, "Ph: " + user[2], 10, "T1", Align.LeftAlign);
                textAndtable.AddText(300, 160, "Email: " + user[3], 10, "T1", Align.LeftAlign);
                textAndtable.AddText(300, 170, "Web: http://www.fire-alert.ca", 10, "T1", Align.LeftAlign);

                textAndtable.AddText(50, 150, "WO, ID: " + txtSalesOrder.SelectedValue.ToString(), 10, "T3", Align.LeftAlign);
                textAndtable.AddText(50, 160, "Service Address: ", 10, "T3", Align.LeftAlign);
                textAndtable.AddText(50, 170, sAd[0], 10, "T1", Align.LeftAlign);
                // textAndtable.AddText(50, 180, sAd[1], 10, "T1", Align.LeftAlign);
                textAndtable.AddText(50, 180, sAd[3] + ", " + sAd[4] + ", " + sAd[5] + " " + sAd[1], 10, "T1", Align.LeftAlign);
                textAndtable.AddText(50, 190, "On-site Contact: ", 10, "T3", Align.LeftAlign);
                textAndtable.AddText(50, 200, sAd[2], 10, "T1", Align.LeftAlign);
                textAndtable.AddText(50, 210, "Date of Service: ", 10, "T1", Align.LeftAlign);


                //Add table to the page
                Align[] alignC = new Align[4];
                alignC[0] = Align.CenterAlign;
                alignC[1] = Align.CenterAlign;
                alignC[2] = Align.CenterAlign;
                alignC[3] = Align.CenterAlign;

                Align[] alignR = new Align[4];
                alignR[0] = Align.LeftAlign;
                alignR[1] = Align.LeftAlign;
                alignR[2] = Align.LeftAlign;
                alignR[3] = Align.LeftAlign;

                //Specify the color for the cell and the line
                ColorSpec cellColor = new ColorSpec(196, 34, 34);
                ColorSpec lineColor = new ColorSpec(1, 1, 1);

                //Fill in the parameters for the table
                TableParams table = new TableParams(4, 235, 90, 75, 75);
                table.yPos      = 550;
                table.xPos      = 50;
                table.rowHeight = 15;

                //Set the parameters of this table
                textAndtable.SetParams(table, cellColor, Align.CenterAlign, 3);
                textAndtable.AddRow(false, 8, "T3", alignC, true, "Terms", "Purchase Order", "Date Issued", "Due Date");
                //After drawing table and text add them to the page
                content.SetStream(textAndtable.EndTable(lineColor, true));

                TextAndTables textAndtable2 = new TextAndTables(pSize);
                //Specify the color for the cell and the line
                ColorSpec   cell1  = new ColorSpec(255, 255, 255);
                ColorSpec   line1  = new ColorSpec(1, 1, 1);
                TableParams table2 = new TableParams(4, 235, 90, 75, 75);
                table2.yPos      = 535;
                table2.xPos      = 50;
                table2.rowHeight = 15;
                textAndtable2.SetParams(table2, cell1, Align.CenterAlign, 3);
                textAndtable2.AddRow(false, 8, "T3", alignR, false, "Net" + txtTerm.Text, txtSalesOrder.SelectedValue.ToString(),
                                     Issued.Value.ToShortDateString(), Issued.Value.AddDays(Convert.ToDouble(txtTerm.Text)).ToShortDateString());
                content.SetStream(textAndtable2.EndTable(line1, true));

                Align[] alignC2 = new Align[7];
                alignC2[0] = Align.CenterAlign;
                alignC2[1] = Align.CenterAlign;
                alignC2[2] = Align.CenterAlign;
                alignC2[3] = Align.CenterAlign;
                alignC2[4] = Align.CenterAlign;
                alignC2[5] = Align.CenterAlign;
                alignC2[6] = Align.CenterAlign;


                Align[] alignR2 = new Align[7];
                alignR2[0] = Align.LeftAlign;
                alignR2[1] = Align.LeftAlign;
                alignR2[2] = Align.LeftAlign;
                alignR2[3] = Align.LeftAlign;
                alignR2[4] = Align.RightAlign;
                alignR2[5] = Align.RightAlign;
                alignR2[6] = Align.RightAlign;

                TextAndTables textAndtable3 = new TextAndTables(pSize);
                //Specify the color for the cell and the line
                ColorSpec   cell2  = new ColorSpec(196, 34, 34);
                ColorSpec   line2  = new ColorSpec(1, 1, 1);
                TableParams table3 = new TableParams(7, 15, 100, 160, 40, 40, 60, 60);
                table3.yPos      = 510;
                table3.xPos      = 50;
                table3.rowHeight = 15;
                textAndtable3.SetParams(table3, cell2, Align.CenterAlign, 3);
                textAndtable3.AddRow(false, 8, "T3", alignC2, true, "#", "Item", "Description", "Hours", "Qty", "Price", "Line Total");
                content.SetStream(textAndtable3.EndTable(line2, true));


                TextAndTables textAndtable4 = new TextAndTables(pSize);
                //Specify the color for the cell and the line
                ColorSpec   cell3  = new ColorSpec(255, 255, 255);
                ColorSpec   line3  = new ColorSpec(1, 1, 1);
                TableParams table4 = new TableParams(7, 15, 100, 160, 40, 40, 60, 60);
                table4.yPos      = 495;
                table4.xPos      = 50;
                table4.rowHeight = 15;
                textAndtable4.SetParams(table4, cell3, Align.CenterAlign, 3);
                for (int i = 0; i < dataGridView1.Rows.Count; i++)
                {
                    textAndtable4.AddRow(false, 8, "T3", alignR2, false, dataGridView1.Rows[i].Cells[0].Value.ToString(),
                                         dataGridView1.Rows[i].Cells[1].Value.ToString(), dataGridView1.Rows[i].Cells[2].Value.ToString(),
                                         dataGridView1.Rows[i].Cells[3].Value.ToString(), dataGridView1.Rows[i].Cells[4].Value.ToString(),
                                         dataGridView1.Rows[i].Cells[5].Value.ToString(), dataGridView1.Rows[i].Cells[6].Value.ToString());
                }
                content.SetStream(textAndtable4.EndTable(line3, true));



                textAndtable.AddText(400, 650, "Subtotal ", 10, "T1", Align.LeftAlign);
                textAndtable.AddText(400, 665, "HST ", 10, "T1", Align.LeftAlign);
                textAndtable.AddText(400, 680, "Total ", 10, "T1", Align.LeftAlign);
                textAndtable.AddText(400, 695, "Payment Made ", 10, "T1", Align.LeftAlign);
                textAndtable.AddText(400, 710, "Balance Due ", 10, "T1", Align.LeftAlign);


                TextAndTables textAndtable5 = new TextAndTables(pSize);
                Align[]       align         = new Align[1];
                align[0] = Align.RightAlign;
                //Specify the color for the cell and the line
                TableParams table5 = new TableParams(1, 60);
                table5.yPos      = 152;
                table5.xPos      = 100;
                table5.rowHeight = 15;
                textAndtable5.SetParams(table5, cell3, Align.RightAlign, 3);
                textAndtable5.AddRow(false, 10, "T3", align, false, txtSub.Text);
                textAndtable5.AddRow(false, 10, "T3", align, false, txtTax.Text);
                content.SetStream(textAndtable5.EndTable(line3, true));

                TextAndTables textAndtable6 = new TextAndTables(pSize);
                //Specify the color for the cell and the line
                TableParams table6 = new TableParams(1, 60);
                table6.yPos      = 122;
                table6.xPos      = 100;
                table6.rowHeight = 15;
                textAndtable6.SetParams(table6, cell2, Align.RightAlign, 3);
                textAndtable6.AddRow(false, 10, "T3", align, true, txtTotal.Text);

                if (txtAmount.Text == "")
                {
                    txtAmount.Text = "$0.00";
                }
                textAndtable6.AddRow(false, 10, "T3", align, true, "$" + String.Format("{0:0.00}", Math.Round(Convert.ToDouble(txtAmount.Text.Replace("$", "")))));
                textAndtable6.AddRow(false, 10, "T3", align, true, "$" + String.Format("{0:0.00}", Math.Round(Convert.ToDouble(txtTotal.Text.Replace("$", "")) -
                                                                                                              Convert.ToDouble(txtAmount.Text.Replace("$", "")), 2)));
                content.SetStream(textAndtable6.EndTable(line2, true));


                content.SetStream(textAndtable.EndText());


                //All done - send the information to the PDF file

                size = 0;
                file = new FileStream(FilePath, FileMode.Append);
                file.Write(page.GetPageDict(file.Length, out size), 0, size);
                file.Write(content.GetContentDict(file.Length, out size), 0, size);
                file.Close();

                file = new FileStream(FilePath, FileMode.Append);
                file.Write(catalogDict.GetCatalogDict(pageTreeDict.objectNum, file.Length, out size), 0, size);
                file.Write(pageTreeDict.GetPageTree(file.Length, out size), 0, size);
                file.Write(TimesRoman.GetFontDict(file.Length, out size), 0, size);
                file.Write(TimesItalic.GetFontDict(file.Length, out size), 0, size);
                file.Write(TimesBold.GetFontDict(file.Length, out size), 0, size);
                file.Write(Courier.GetFontDict(file.Length, out size), 0, size);

                //write image dict
                file.Write(I1.GetImageDict(file.Length, out size), 0, size);

                file.Write(infoDict.GetInfoDict(file.Length, out size), 0, size);
                file.Write(pdfUtility.CreateXrefTable(file.Length, out size), 0, size);
                file.Write(pdfUtility.GetTrailer(catalogDict.objectNum, infoDict.objectNum, out size), 0, size);
                file.Close();

                //Messages.Visible = true;
                Preview testDialog = new Preview(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory) + "\\Resources\\Invoice.pdf");
                testDialog.ShowDialog(this);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Could not display the document with the incorrect Information");
            }
        }
Exemple #12
0
        public async Task <InfoDict> ProcessPlaylistResult(Playlist ie_result, bool download = true)
        {
            string playlist = ie_result.Title;

            if (playlist == null)
            {
                playlist = ie_result.Id;
            }

            LogInfo("[download] Downloading playlist: " + playlist);

            int playliststart = Options.PlaylistStart - 1;
            int?playlistend   = Options.PlaylistEnd;

            int[] playlistitems = Options.PlaylistItems;

            List <InfoDict> ie_entries = ie_result.Entries;
            List <InfoDict> entries;

            if (playlistitems != null && playlistitems.Length != 0)
            {
                entries = new List <InfoDict>();
                foreach (int itemindex in playlistitems)
                {
                    InfoDict entry = ie_entries[itemindex];
                    entries.Add(entry);
                }
            }
            else if (playlistend != null)
            {
                entries = ie_entries.GetRange(playliststart, (int)playlistend);
            }
            else
            {
                entries = ie_entries.Skip(playliststart).ToList();
            }

            if (Options.PlaylistRandom)
            {
                Util.Shuffle(entries);
            }
            else if (Options.PlaylistReverse)
            {
                entries.Reverse();
            }

            ie_result.Entries = entries;
            List <Task <InfoDict> > playlist_results = new List <Task <InfoDict> >();

            for (int i = 0; i < entries.Count; i++)
            {
                LogInfo("Downloading video " + (i + 1) + " of " + entries.Count, "download");

                // *x_forward_for*

                // *match entry*
                string reason = null;
                if (reason != null)
                {
                    LogInfo(reason, "download");
                    continue;
                }

                var extra = new Dictionary <string, object>()
                {
                    //{ "n_entries", entries.Count },
                    { "playlist", ie_result },
                    //{ "playlist_id", ie_result["id"] },
                    //{ "playlist_title", ie_result["title"] },
                    //{ "playlist_uploader", ie_result["uploader"] },
                    //{ "playlist_uploader_id", ie_result["uploader_id"] },
                    { "playlist_index", i + playliststart },
                    { "extractor", ie_result.Extractor },
                    { "webpage_url", ie_result.WebpageUrl },
                    { "webpage_url_basename", new Uri(ie_result.WebpageUrl).AbsolutePath },
                    { "extractor_key", ie_result.ExtractorKey }
                };

                var entry_result = ProcessIEResult(entries[i], download, extra);
                playlist_results.Add(entry_result);
            }
            ie_result.Entries = (await Task.WhenAll(playlist_results)).ToList();
            LogInfo("Finished downloading playlist: " + playlist, "download");
            return(ie_result);
        }
Exemple #13
0
        public async Task <InfoDict> ExtractInfoAsync(
            string url, bool download = true, string ie_key             = null,
            Dictionary <string, object> extra_info = null, bool process = true,
            bool force_generic_extractor           = false)
        {
            if (ie_key == null && force_generic_extractor)
            {
                ie_key = "Generic";
            }

            List <IInfoExtractor> ies;

            if (ie_key != null)
            {
                ies = new List <IInfoExtractor> {
                    GetInfoExtractorInstance(ie_key)
                };
            }
            else
            {
                ies = this.ie_instances;
            }

            foreach (IInfoExtractor extractor in ies)
            {
                if (extractor == null || !extractor.Suitable(url))
                {
                    continue;
                }

                if (!extractor.Working)
                {
                    LogWarning("The program functionality for this site has been marked as broken, and will probably not work.");
                }

                extractor.OnLog += Log;
                extractor.Initialize();

                try
                {
                    InfoDict ie_result = extractor.Extract(url);

                    AddDefaultExtraInfo(ie_result, extractor, url);

                    if (process)
                    {
                        ie_result = await ProcessIEResult(ie_result, download, extra_info);
                    }
                    return(ie_result);
                }
                catch (GeoRestrictionException)
                {
                }
                catch (ExtractorException)
                {
                }
                catch (MaxDownloadsReachedException)
                {
                }
                return(null);
            }

            return(null);

            //LogInfo("native extractors not suitable, switching to python");

            // no native extractor is suitable
            // now we try the python extractors

            /*
             * Assembly a = Assembly.Load(new AssemblyName("YoutubeDL.Python"));
             * if (a == null) return null;
             * var type = a.GetType("YoutubeDL.Python.YoutubeDLPython");
             * if (type == null) return null;
             * MethodInfo i = type.GetMethod("PythonExtractInfo", BindingFlags.Public | BindingFlags.Static);
             * if (i == null) return null;
             *
             * try
             * {
             *  return await ((Task<InfoDict>)i.Invoke(null, new object[] { this, url, download, ie_key, extra_info, process, force_generic_extractor })).ConfigureAwait(false);
             * }
             * catch (InvalidOperationException)
             * {
             *  // python is not installed
             *  return null;
             * }*/
        }
Exemple #14
0
 public IDictionary <string, int> GetDictionary(InfoDict index)
 {
     return(infos[index]);
 }