Ejemplo n.º 1
0
        public void writePDF()
        {
            PdfDocument document = new PdfDocument(PaperType.A4, false, UnitOfMeasure.cm);

            // Step 3: Add new empty page
            PdfPage Page = new PdfPage(document);

            // Step 4: Add contents object to the page object
            PdfContents Contents = new PdfContents(Page);

            // Step 5: add graphics and text contents to the contents object
            TextBox Box = new TextBox(10, 5);

            // add text to the text box

            PdfFont font = new PdfFont(document, "Arial", FontStyle.Bold, true);

            Box.AddText(font, 12.0,
                        "This area is an example of displaying text that is too long to fit within a " +
                        "fixed width area. The text is displayed justified to right edge. You define a " +
                        "text box with the required width and first line indent. You add text to this " +
                        "box. The box will divide the text into lines. Each line is made of segments " +
                        "of text. For each segment, you define font, font size, drawing style and color. " +
                        "After loading all the text, the program will draw the formatted text.\n");
            Double PosY = 1.4;

            Contents.DrawText(0.0, ref PosY, 0.0, 0, 0.015, 0.05, true, Box);

            // Step 6: create pdf file
            // argument: PDF file name
            string FileName = @"D:\MyPDFFile.pdf";

            document.CreateFile(FileName);
        }
Ejemplo n.º 2
0
        public void Test
        (
            Boolean Debug,
            String InputFileName
        )
        {
            // create document
            using (Document = new PdfDocument(PaperType.Letter, false, UnitOfMeasure.Inch, InputFileName))
            {
                // define font
                ArialFont = PdfFont.CreatePdfFont(Document, "Arial", FontStyle.Bold);

                FontSize   = 24;
                Ascent     = ArialFont.AscentPlusLeading(FontSize);
                Descent    = ArialFont.DescentPlusLeading(FontSize);
                FontHeight = ArialFont.LineSpacing(FontSize);

                OnePage(3, 5);
                OnePage(4, 4);
                OnePage(4, 6);
                OnePage(5, 7);

                // create pdf file
                Document.CreateFile();

                // start default PDF reader and display the file
                Process Proc = new Process();
                Proc.StartInfo = new ProcessStartInfo(InputFileName);
                Proc.Start();
            }
            return;
        }
Ejemplo n.º 3
0
        //public void buildTestPdf()
        //{
        //    appendTopHeader();
        //    appendSectionBreak();
        //    appendSubHeader("Person Being Assessed");
        //    appendItem("Last Name", "Chan");
        //    appendItem("First Name", "Sophie");
        //    outputToFile("C:\\Users\\rbogard\\Downloads\\test.pdf");
        //}

        public void outputToFile()
        {
            doc.CreateFile();
            //Process Proc = new Process();
            //Proc.StartInfo = new ProcessStartInfo(path);
            //Proc.Start();
        }
Ejemplo n.º 4
0
        ////////////////////////////////////////////////////////////////////
        // Create print example
        ////////////////////////////////////////////////////////////////////

        public void Test
        (
            Boolean Debug,
            String FileName
        )
        {
            // Step 1: Create empty document
            // Arguments: page width: 8.5”, page height: 11”, Unit of measure: inches
            // Return value: PdfDocument main class
            Document = new PdfDocument(PaperType.Letter, false, UnitOfMeasure.Inch, FileName);

            // Debug property
            // By default it is set to false. Use it for debugging only.
            // If this flag is set, PDF objects will not be compressed, font and images will be replaced
            // by text place holder. You can view the file with a text editor but you cannot open it with PDF reader.
            Document.Debug = Debug;

            // create default font for printing
            DefaultFont = new Font("Arial", 10.0F, FontStyle.Regular);

            // start page number
            PageNo = 1;

            // create PrintPdfDocument
            PdfImageControl ImageControl = new PdfImageControl();

            ImageControl.Resolution = 300.0;
            ImageControl.SaveAs     = SaveImageAs.BWImage;
            PdfPrintDocument Print = new PdfPrintDocument(Document, ImageControl);

            // the method that will print one page at a time to PrintDocument
            Print.PrintPage += PrintPage;

            // set margins
            Print.SetMargins(1.0, 1.0, 1.0, 1.0);

            // crop the page image result to reduce PDF file size
            Print.PageCropRect = new RectangleF(0.95F, 0.95F, 6.6F, 9.1F);

            // initiate the printing process (calling the PrintPage method)
            // after the document is printed, add each page an an image to PDF file.
            Print.AddPagesToPdfDocument();

            // dispose of the PrintDocument object
            Print.Dispose();

            // create the PDF file
            Document.CreateFile();

            // start default PDF reader and display the file
            Process Proc = new Process();

            Proc.StartInfo = new ProcessStartInfo(FileName);
            Proc.Start();

            // exit
            return;
        }
Ejemplo n.º 5
0
        ////////////////////////////////////////////////////////////////////
        // Create article's example test PDF document
        ////////////////////////////////////////////////////////////////////

        public void Test
        (
            Boolean Debug,
            String FileName
        )
        {
            // Step 1: Create empty document
            // Arguments: page width: 8.5”, page height: 11”, Unit of measure: inches
            // Return value: PdfDocument main class
            Document = new PdfDocument(PaperType.Letter, false, UnitOfMeasure.Inch, FileName);

            // for encryption test
//		Document.SetEncryption(Permission.All & ~Permission.Print);

            // Debug property
            // By default it is set to false. Use it for debugging only.
            // If this flag is set, PDF objects will not be compressed, font and images will be replaced
            // by text place holder. You can view the file with a text editor but you cannot open it with PDF reader.
            Document.Debug = Debug;

            // Step 2: create resources
            // define font resources
            DefineFontResources();

            // define tiling pattern resources
            DefineTilingPatternResource();

            // Step 3: Add new page
            Page = new PdfPage(Document);

            // Step 4:Add contents to page
            Contents = new PdfContents(Page);

            // Step 5: add graphices and text contents to the contents object
            DrawFrameAndBackgroundWaterMark();
            DrawTwoLinesOfHeading();
            DrawHappyFace();
            DrawBarcode();
            DrawBrickPattern();
            DrawImage();
            DrawHeart();
            DrawChart();
            DrawTextBox();
            DrawBookOrderForm();

            // Step 6: create pdf file
            // argument: PDF file name
            Document.CreateFile();     //FileName);

            // start default PDF reader and display the file
            Process Proc = new Process();

            Proc.StartInfo = new ProcessStartInfo(FileName);
            Proc.Start();

            // exit
            return;
        }
Ejemplo n.º 6
0
        public void GetInvoice()
        {
            var info = PdfInfo.CreatePdfInfo(MPdfDocument);

            info.Title("Faktura");
            info.Author("TZ");
            info.Keywords("keyword");
            info.Subject("Temat");


            PdfContents = new PdfContents(_page);

            IdFaktury(_mInvoiceData.InvoiceNumber);

            double lastPosition = 26;

            CreateTable(_mInvoiceData.HeaderLeft, 1.3, 10, 8, lastPosition, lastPosition - 3, false,
                        ContentAlignment.MiddleLeft);

            lastPosition = CreateTable(_mInvoiceData.HeaderRight, 10.3, 16, 8, lastPosition, lastPosition - 1.5, false,
                                       ContentAlignment.MiddleLeft);

            lastPosition = CreateTable(_mInvoiceData.GetSprzeNaby, 1.3, 30, 8, lastPosition - 1.4, lastPosition - 6.2,
                                       true, ContentAlignment.MiddleLeft);

            var widthRow = ArialNormal.TextWidth(8, _mInvoiceData.NrBankowyLeftRight) + 0.25;

            lastPosition = CreateTable(_mInvoiceData.NrBankowy, 1.3, 1.3 + widthRow, 8, lastPosition - 1,
                                       lastPosition - 6.2, false, ContentAlignment.MiddleLeft);

            lastPosition = TabelaDaneFaktura(1.3, lastPosition - 1, lastPosition - 11, 19.7, 9,
                                             _mInvoiceData.DataServices);

            RazemWTym(12.03, lastPosition - 0.018, lastPosition - 11, 9);

            lastPosition = Summary(12.03, lastPosition - 0.018, lastPosition - 11, 19.7, 9,
                                   _mInvoiceData.SummaryServiceValues);

            widthRow = ArialNormal.TextWidth(8, _mInvoiceData.ZapDoZapLeftRight) + 0.25;
            CreateTable(_mInvoiceData.ZapDoZap, 1.3, 1.3 + widthRow, 8, lastPosition - 1, lastPosition - 10, false,
                        ContentAlignment.MiddleLeft);

            widthRow     = ArialNormal.TextWidth(12, _mInvoiceData.SummaryLeftRight);
            lastPosition = CreateTable(_mInvoiceData.Summary, 19.7 - widthRow, 19.7, 12, lastPosition - 1,
                                       lastPosition - 10, false, ContentAlignment.MiddleRight);

            widthRow     = ArialNormal.TextWidth(8, _mInvoiceData.SummaryTextLeftRight);
            lastPosition = CreateTable(_mInvoiceData.SummaryText, 19.7 - widthRow, 19.7, 8, lastPosition,
                                       lastPosition - 10, false, ContentAlignment.MiddleRight);

            RamkiEnd(1.3, lastPosition - 1.4, lastPosition - 5, 9, 7, DictionaryMain.LabelPodpisWystawiania);

            RamkiEnd(12, lastPosition - 1.4, lastPosition - 5, 19.7, 7, DictionaryMain.LabelPodpisOdbierania);

            MPdfDocument.CreateFile();
        }
Ejemplo n.º 7
0
        public byte[] Create()
        {
            double fontSize = 12;
            double height   = 11.69;
            double width    = 8.27;

            PdfDocument.CreateFile();

            return(PdfStream.ToArray());
        }
Ejemplo n.º 8
0
        ////////////////////////////////////////////////////////////////////
        // Create chart example
        ////////////////////////////////////////////////////////////////////

        public void Test
        (
            bool Debug,
            string FileName
        )
        {
            // Step 1: Create empty document
            // Arguments: page width: 8.5”, page height: 11”, Unit of measure: inches
            // Return value: PdfDocument main class
            Document = new PdfDocument(PaperType.Letter, false, UnitOfMeasure.Inch, FileName);

            // Debug property
            // By default it is set to false. Use it for debugging only.
            // If this flag is set, PDF objects will not be compressed, font and images will be replaced
            // by text place holder. You can view the file with a text editor but you cannot open it with PDF reader.
            Document.Debug = Debug;

            // Step 3: Add new page
            Page = new PdfPage(Document);

            // Step 4: Add contents to page
            Contents = new PdfContents(Page);

            // Step 5: draw charts
            DrawPieChart();
            DrawColumnChart();

            // Step 3: Add new page
            Page = new PdfPage(Document);

            // Step 4: Add contents to page
            Contents = new PdfContents(Page);

            // Step 5: draw charts
            DrawStockChart();
            DrawPyramidChart();

            // Step 6: create pdf file
            // argument: PDF file name
            Document.CreateFile();

            // start default PDF reader and display the file
            Process Proc = new Process();

            Proc.StartInfo = new ProcessStartInfo(FileName);
            Proc.Start();

            // exit
            return;
        }
Ejemplo n.º 9
0
        // Create “article example” test PDF document
        public static void CreatePDF(String FileName)
        {
            // Step 1: Create empty document
            // Arguments: page width: 8.5”, page height: 11”, Unit of measure: inches
            // Return value: PdfDocument main class
            // create main class
            PdfDocument zDocument = new PdfDocument(PaperType.Letter, false, UnitOfMeasure.Inch, FileName);
            PdfPage     zPage     = new PdfPage(zDocument);

            DrawTextBox(zDocument, zPage);

            // Step 6: create pdf file
            // argument: PDF file name
            zDocument.CreateFile();
        }
        ////////////////////////////////////////////////////////////////////
        // Create article's example test PDF document
        ////////////////////////////////////////////////////////////////////

        public static void GenerateWelcomeLetterSimple(String FileName, CustomerInformation customer, List <Account> accountList, BranchInfo branch, bool inclEmail, Boolean Debug = false)
        {
            // Create an empty pdf document in A4 and measured in cm
            bool landscape = false;

            document = new PdfDocument(PaperType.A4, landscape, UnitOfMeasure.cm, FileName);

            // Set debug tag
            document.Debug = Debug;

            // Write Pdf info
            PdfInfo Info = PdfInfo.CreatePdfInfo(document);

            Info.Title("Welcome Letter - Bank of China");
            Info.Author("Bank of China " + branch.GetAddress()[0]);
            Info.Keywords("Account, Bank of China, Remittance");
            Info.Subject("Remittance information for Bank of China accounts");

            // define font resources
            DefineFontResources();

            // Add first page, also the only page for simple welcome letter
            Page = new PdfPage(document);

            // Add contents to page
            Contents = new PdfContents(Page);

            // Add graphices and text contents to the contents object
            DrawTitle();
            if (customer.HasAddress())
            {
                DrawCustomerNameAddress(customer);
            }
            DrawBranchNameAddress(branch, inclEmail);
            DrawLetterGreeting(customer);
            DrawBankInformation(customer);
            DrawAccountInformationForm(accountList);
            DrawLetterBody();
            DrawGroupContact();

            // Create pdf file
            document.CreateFile();

            // exit
            return;
        }
Ejemplo n.º 11
0
        ////////////////////////////////////////////////////////////////////
        // Create data table examples PDF document
        ////////////////////////////////////////////////////////////////////

        public void Test
        (
            Boolean Debug,
            String FileName
        )
        {
            // Create empty document
            // Arguments: page width: 8.5”, page height: 11”, Unit of measure: inches
            // Return value: PdfDocument main class
            Document = new PdfDocument(PaperType.Letter, false, UnitOfMeasure.Inch, FileName);

            // Debug property
            // By default it is set to false. Use it for debugging only.
            // If this flag is set, PDF objects will not be compressed, font and images will be replaced
            // by text place holder. You can view the file with a text editor but you cannot open it with PDF reader.
            Document.Debug = Debug;

            // define font resource
            NormalFont     = PdfFont.CreatePdfFont(Document, "Arial", FontStyle.Regular, true);
            TableTitleFont = PdfFont.CreatePdfFont(Document, "Times New Roman", FontStyle.Bold, true);

            // book list table
            CreateBookList();

            // stock price table
            CreateStockTable();

            // textbox overflow example
            TestOverflow();

            // argument: PDF file name
            Document.CreateFile();

            // start default PDF reader and display the file
            Process Proc = new Process();

            Proc.StartInfo = new ProcessStartInfo(FileName);
            Proc.Start();

            // exit
            return;
        }
Ejemplo n.º 12
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (folderDiag.SelectedPath != null && folderDiag.SelectedPath != "")
            {
                textBox1.Text = "Adding pages";
                Image[] pages = System.IO.Directory.GetFiles(folderDiag.SelectedPath)
                                .Select(file => System.Drawing.Image.FromFile(file))
                                .ToArray();
                string      title = titleBox.Text == "Title" ? "untitled" : titleBox.Text;
                PdfDocument book  = new PdfDocument(title + ".pdf");
                PdfPage     page;
                PdfContents contents;
                PdfImage    pic;

                foreach (Image i in pages)
                {
                    double height = i.Height;
                    double width  = i.Width;

                    page     = new PdfPage(book, width, height);
                    contents = new PdfContents(page);
                    contents.SaveGraphicsState();
                    pic = new PdfImage(book, i);
                    contents.DrawImage(pic, 0, 0, width, height);
                    contents.RestoreGraphicsState();
                    contents.CommitToPdfFile(true);
                }
                book.CreateFile();
                textBox1.Text = "Book created";
                pages         = null;
                book          = null;
                page          = null;
                contents      = null;
                pic           = null;
            }
            else
            {
                textBox1.Text = "No directory selected";
            }
        }
Ejemplo n.º 13
0
        /*
         * public void ReadJson(String jsonfile)
         * {
         *  using (StreamReader r = new StreamReader(jsonfile))
         *  {
         *      string json = r.ReadToEnd();
         *
         *      PdfPassJson = JsonConvert.DeserializeObject<PassJson>(json);
         *      Console.WriteLine(PdfPassJson.EventTicket.HeaderFields[0].Key);
         *
         *  }
         *  return;
         * }
         */
        public void Test
        (
            Boolean Debug,
            String FileName
        )
        {
            Console.WriteLine("Start");
            // Step 1: Create empty document
            // Arguments: page width: 8.5”, page height: 11”, Unit of measure: inches
            // Return value: PdfDocument main class
            Document = new PdfDocument(PaperType.Letter, false, UnitOfMeasure.Inch, FileName);

            // for encryption test
            //		Document.SetEncryption(null, null, Permission.All & ~Permission.Print, EncryptionType.Aes128);

            // Debug property
            // By default it is set to false. Use it for debugging only.
            // If this flag is set, PDF objects will not be compressed, font and images will be replaced
            // by text place holder. You can view the file with a text editor but you cannot open it with PDF reader.
            Document.Debug = Debug;

            PdfInfo Info = PdfInfo.CreatePdfInfo(Document);

            Info.Title("TicketPassCard");
            Info.Author("blueskaie");
            Info.Keywords("PDF, .NET, C#, Library, Document Creator");
            Info.Subject("PDF File Writer C# Class Library (Version 1.14.1)");

            // Step 2: create resources
            // define font resources
            DefineFontResources();

            // define tiling pattern resources
            DefineTilingPatternResource();

            // Step 3: Add new page
            Page = new PdfPage(Document);

            // Step 4:Add contents to page
            Contents = new PdfContents(Page);

            // Step 5: add graphices and text contents to the contents object
            DrawFrameAndBackgroundWaterMark();

            DrawLogImage();
            //DrawTime();
            DrawStrip();
            DrawAuxiliaryFields();
            DrawBarcode();

            // Step 6: create pdf file
            Document.CreateFile();

            // start default PDF reader and display the file
            Process Proc = new Process();

            Proc.StartInfo = new ProcessStartInfo(FileName);
            Proc.Start();
            Console.WriteLine("end");
            Console.ReadLine();
            // exit
            return;
        }
Ejemplo n.º 14
0
        ////////////////////////////////////////////////////////////////////
        // Create article's example test PDF document
        ////////////////////////////////////////////////////////////////////

        public void Test
        (
            Boolean Debug,
            String FileName
        )
        {
            // Step 1: Create empty document
            // Arguments: page width: 8.5”, page height: 11”, Unit of measure: inches
            // Return value: PdfDocument main class
            // Document = new PdfDocument(PaperType.A4, false, UnitOfMeasure.Inch, FileName);
            Document = new PdfDocument(PaperType.A4, false, UnitOfMeasure.Point, FileName);

            // for encryption test
//		Document.SetEncryption(null, null, Permission.All & ~Permission.Print, EncryptionType.Aes128);

            // Debug property
            // By default it is set to false. Use it for debugging only.
            // If this flag is set, PDF objects will not be compressed, font and images will be replaced
            // by text place holder. You can view the file with a text editor but you cannot open it with PDF reader.
            Document.Debug = Debug;

            //PdfInfo Info = PdfInfo.CreatePdfInfo(Document);
            //Info.Title("Article Example");
            //Info.Author("Uzi Granot Granotech Limited");
            //Info.Keywords("PDF, .NET, C#, Library, Document Creator");
            //Info.Subject("PDF File Writer C# Class Library (Version 1.14.1)");

            //// Step 2: create resources
            //// define font resources
            DefineFontResources();

            //// define tiling pattern resources
            //DefineTilingPatternResource();

            // Step 3: Add new page
            Page = new PdfPage(Document);

            // Step 4:Add contents to page
            Contents = new PdfContents(Page);

            // Step 5: add graphices and text contents to the contents object
            //DrawFrameAndBackgroundWaterMark();
            DrawTwoLinesOfHeading();
            //DrawHappyFace();
            //DrawBarcode();
            //DrawBrickPattern();
            //DrawImage(2.6f,5.0f);
            //float x = 2.6f + 3.125f;
            //float y = 5.0f + 2.42f;
            //DrawImage(x, y);
            //x = 2.6f;
            //y = 3f;
            //DrawImage(x, y);
            //DrawHeart();
            //DrawChart();
            //DrawTextBox();
            //DrawBookOrderForm();

            // Step 6: create pdf file
            Document.CreateFile();

            // start default PDF reader and display the file
            Process Proc = new Process();

            Proc.StartInfo = new ProcessStartInfo(FileName);
            Proc.Start();

            // exit
            return;
        }
Ejemplo n.º 15
0
        public void Test
        (
            bool Debug,
            string InputFileName
        )
        {
            // create document
            using (Document = new PdfDocument(PaperType.Letter, false, UnitOfMeasure.Inch, InputFileName))
            {
                // set document page mode to open the layers panel
                Document.InitialDocDisplay = InitialDocDisplay.UseLayers;

                // define font
                ArialFont = PdfFont.CreatePdfFont(Document, "Arial", FontStyle.Bold);

                // open layer control object (in PDF terms optional content object)
                PdfLayers Layers = new PdfLayers(Document, "PDF layers group");

                // set layer panel to incluse all layers including ones that are not visible
                Layers.ListMode = ListMode.AllPages;

                // Add new page
                PdfPage Page = new PdfPage(Document);

                // Add contents to page
                PdfContents Contents = new PdfContents(Page);

                // heading
                Contents.DrawText(ArialFont, 24, 4.25, 10, TextJustify.Center, "PDF File Writer Layer Test/Demo");

                // define layers
                PdfLayer DrawingTest    = new PdfLayer(Layers, "Drawing Test");
                PdfLayer Rectangle      = new PdfLayer(Layers, "Rectangle");
                PdfLayer HorLines       = new PdfLayer(Layers, "Horizontal Lines");
                PdfLayer VertLines      = new PdfLayer(Layers, "Vertical Lines");
                PdfLayer QRCodeLayer    = new PdfLayer(Layers, "QRCode barcode");
                PdfLayer Pdf417Layer    = new PdfLayer(Layers, "PDF417 barcode");
                PdfLayer NoBarcodeLayer = new PdfLayer(Layers, "No barcode");

                // combine three layers into one group of radio buttons
                QRCodeLayer.RadioButton    = "Barcode";
                Pdf417Layer.RadioButton    = "Barcode";
                NoBarcodeLayer.RadioButton = "Barcode";

                // set the order of layers in the layer pane
                Layers.DisplayOrder(DrawingTest);
                Layers.DisplayOrder(Rectangle);
                Layers.DisplayOrder(HorLines);
                Layers.DisplayOrder(VertLines);
                Layers.DisplayOrderStartGroup("Barcode group");
                Layers.DisplayOrder(QRCodeLayer);
                Layers.DisplayOrder(Pdf417Layer);
                Layers.DisplayOrder(NoBarcodeLayer);
                Layers.DisplayOrderEndGroup();

                // start a group layer
                Contents.LayerStart(DrawingTest);

                // sticky note annotation
                PdfAnnotation StickyNote = Page.AddStickyNote(2.0, 9.0, "My sticky note", StickyNoteIcon.Note);
                StickyNote.LayerControl = DrawingTest;

                // draw a single layer
                Contents.LayerStart(Rectangle);
                Contents.DrawText(ArialFont, 14, 1.0, 8.0, TextJustify.Left, "Draw rectangle");
                Contents.LayerEnd();

                // draw a single layer
                Contents.LayerStart(HorLines);
                Contents.DrawText(ArialFont, 14, 1.0, 7.5, TextJustify.Left, "Draw horizontal lines");
                Contents.LayerEnd();

                // draw a single layer
                Contents.LayerStart(VertLines);
                Contents.DrawText(ArialFont, 14, 1.0, 7.0, TextJustify.Left, "Draw vertical lines");
                Contents.LayerEnd();

                double Left   = 4.0;
                double Right  = 7.0;
                double Top    = 9.0;
                double Bottom = 6.0;

                // draw a single layer
                Contents.LayerStart(Rectangle);
                Contents.SaveGraphicsState();
                Contents.SetLineWidth(0.1);
                Contents.SetColorStroking(Color.Black);
                Contents.SetColorNonStroking(Color.LightBlue);
                Contents.DrawRectangle(Left, Bottom, 3.0, 3.0, PaintOp.CloseFillStroke);
                Contents.RestoreGraphicsState();
                Contents.LayerEnd();

                // save graphics state
                Contents.SaveGraphicsState();

                // draw a single layer
                Contents.SetLineWidth(0.02);
                Contents.LayerStart(HorLines);
                for (int Row = 1; Row < 6; Row++)
                {
                    Contents.DrawLine(Left, Bottom + 0.5 * Row, Right, Bottom + 0.5 * Row);
                }
                Contents.LayerEnd();

                // draw a single layer
                Contents.LayerStart(VertLines);
                for (int Col = 1; Col < 6; Col++)
                {
                    Contents.DrawLine(Left + 0.5 * Col, Bottom, Left + 0.5 * Col, Top);
                }
                Contents.LayerEnd();

                // restore graphics state
                Contents.RestoreGraphicsState();

                // terminate a group of layers
                Contents.LayerEnd();

                // define QRCode barcode
                QREncoder QREncoder = new QREncoder();
                QREncoder.ErrorCorrection = ErrorCorrection.M;
                QREncoder.Encode(QRCodeArticle);
                PdfImage QRImage = new PdfImage(Document);
                QRImage.LoadImage(QREncoder);

                // define PDF417 barcode
                Pdf417Encoder Pdf417Encoder = new Pdf417Encoder();
                Pdf417Encoder.ErrorCorrection = ErrorCorrectionLevel.AutoMedium;
                Pdf417Encoder.Encode(Pdf417Article);
                PdfImage Pdf417Image = new PdfImage(Document);
                Pdf417Image.LoadImage(Pdf417Encoder);

                // draw a single layer
                Contents.LayerStart(QRCodeLayer);
                Contents.DrawText(ArialFont, 14, 1.0, 2.5, TextJustify.Left, "QRCode Barcode");
                Contents.DrawImage(QRImage, 3.7, 2.5 - 1.75, 3.5);
                Contents.LayerEnd();

                // draw a single layer
                Contents.LayerStart(Pdf417Layer);
                Contents.DrawText(ArialFont, 14, 1.0, 2.5, TextJustify.Left, "PDF417 Barcode");
                Contents.DrawImage(Pdf417Image, 3.7, 2.5 - 1.75 * Pdf417Encoder.ImageHeight / Pdf417Encoder.ImageWidth, 3.5);
                Contents.LayerEnd();

                // draw a single layer
                Contents.LayerStart(NoBarcodeLayer);
                Contents.DrawText(ArialFont, 14, 1.0, 3.0, TextJustify.Left, "Display no barcode");
                Contents.LayerEnd();

                // create pdf file
                Document.CreateFile();

                // start default PDF reader and display the file
                Process Proc = new Process();
                Proc.StartInfo = new ProcessStartInfo(InputFileName);
                Proc.Start();
            }
            return;
        }
Ejemplo n.º 16
0
        public GenerujPolaWDokumencie(string FileName, SingleFakturaProperty singleFaktura)
        {
            IHelperData   mHelperData   = new HelperData(singleFaktura);
            IDaneNaglowek mDaneNaglowka = new DaneNaglowek(singleFaktura.Work.Naglowek);

            PdfDocument = new PdfDocument(PaperType.A4, false, UnitOfMeasure.cm, FileName)
            {
                Debug = false
            };

            _arialBold   = PdfFont.CreatePdfFont(PdfDocument, ArialFontName, FontStyle.Bold);
            _arialNormal = PdfFont.CreatePdfFont(PdfDocument, ArialFontName, FontStyle.Regular);

            var Info = PdfInfo.CreatePdfInfo(PdfDocument);

            Info.Title("Faktura");
            Info.Author("TZ");
            Info.Keywords("keyword");
            Info.Subject("Temat");

            _page       = new PdfPage(PdfDocument);
            PdfContents = new PdfContents(_page);

            IdFaktury(singleFaktura.Work.Naglowek.NumerFaktury);

            double lastPosition = 26;

            CreateTable(mDaneNaglowka.GetNaglowekL(), 1.3, 10, 8, lastPosition, lastPosition - 3, false,
                        ContentAlignment.MiddleLeft);

            lastPosition = CreateTable(mDaneNaglowka.GetNaglowekR(), 10.3, 16, 8, lastPosition, lastPosition - 1.5,
                                       false, ContentAlignment.MiddleLeft);

            lastPosition = CreateTable(mHelperData.GetSprzeNaby(), 1.3, 30, 8, lastPosition - 1.4, lastPosition - 6.2,
                                       true, ContentAlignment.MiddleLeft);

            var widthRow =
                _arialNormal.TextWidth(8, mHelperData.NrBankowy()[0].Lewa + mHelperData.NrBankowy()[0].Prawa) + 0.25;

            lastPosition = CreateTable(mHelperData.NrBankowy(), 1.3, 1.3 + widthRow, 8, lastPosition - 1,
                                       lastPosition - 6.2, false, ContentAlignment.MiddleLeft);

            lastPosition = TabelaDaneFaktura(1.3, lastPosition - 1, lastPosition - 11, 19.7, 9,
                                             singleFaktura.GetListDt());

            RazemWTym(12.03, lastPosition - 0.018, lastPosition - 11, 9);

            lastPosition = Summary(12.03, lastPosition - 0.018, lastPosition - 11, 19.7, 9, singleFaktura.GetSum());

            widthRow = _arialNormal.TextWidth(8,
                                              mHelperData.GetZapDoZap()[1].Lewa + mHelperData.GetZapDoZap()[1].Prawa) + 0.25;
            CreateTable(mHelperData.GetZapDoZap(), 1.3, 1.3 + widthRow, 8, lastPosition - 1, lastPosition - 10, false,
                        ContentAlignment.MiddleLeft);

            widthRow     = _arialNormal.TextWidth(12, mHelperData.Razem()[0].Lewa + mHelperData.Razem()[0].Prawa);
            lastPosition = CreateTable(mHelperData.Razem(), 19.7 - widthRow, 19.7, 12, lastPosition - 1,
                                       lastPosition - 10, false, ContentAlignment.MiddleRight);

            widthRow     = _arialNormal.TextWidth(8, mHelperData.RazemSlownie().Lewa + mHelperData.RazemSlownie().Prawa);
            lastPosition = CreateTable(new List <DaneTabela> {
                mHelperData.RazemSlownie()
            }, 19.7 - widthRow, 19.7, 8,
                                       lastPosition, lastPosition - 10, false, ContentAlignment.MiddleRight);

            RamkiEnd(1.3, lastPosition - 1.4, lastPosition - 5, 9, 7, DictionaryMain.LabelPodpisWystawiania);

            RamkiEnd(12, lastPosition - 1.4, lastPosition - 5, 19.7, 7, DictionaryMain.LabelPodpisOdbierania);

            PdfDocument.CreateFile();
        }
Ejemplo n.º 17
0
        ////////////////////////////////////////////////////////////////////
        // Create charting examples PDF document
        ////////////////////////////////////////////////////////////////////

        public void Test
        (
            Boolean Debug,
            String FileName
        )
        {
            // Step 1: Create empty document
            // Arguments: page width: 8.5”, page height: 11”, Unit of measure: inches
            // Return value: PdfDocument main class
            Document = new PdfDocument(PaperType.Letter, false, UnitOfMeasure.Inch, FileName);

            // Debug property
            // By default it is set to false. Use it for debugging only.
            // If this flag is set, PDF objects will not be compressed, font and images will be replaced
            // by text place holder. You can view the file with a text editor but you cannot open it with PDF reader.
            Document.Debug = Debug;

            // for encryption test
//		Document.SetEncryption("Password", Permission.All & ~Permission.Print);

            ArialNormal = new PdfFont(Document, "Arial", FontStyle.Regular, true);
            Comic       = new PdfFont(Document, "Comic Sans MS", FontStyle.Bold, true);

            // Step 3: Add new page
            Page = new PdfPage(Document);

            // Step 4:Add contents to page
            PdfContents Contents = new PdfContents(Page);

            // save graphics state
            Contents.SaveGraphicsState();

            // Draw frame around the page
            // Set line width to 0.02"
            Contents.SetLineWidth(0.02);

            // set frame color dark blue
            Contents.SetColorStroking(Color.DarkBlue);
            Contents.SetColorNonStroking(Color.FromArgb(240, 250, 250));

            // rectangle position: x=1.0", y=1.0", width=6.5", height=9.0"
            Contents.DrawRectangle(1.0, 1.0, 6.5, 9.0, PaintOp.CloseFillStroke);
            Contents.DrawLine(1.0, 8.5, 7.5, 8.5);
            Contents.DrawLine(1.0, 6.0, 7.5, 6.0);
            Contents.DrawLine(1.0, 3.5, 7.5, 3.5);

            // page heading
            Contents.DrawText(Comic, 40.0, 4.25, 9.25, TextJustify.Center, 0.02, Color.FromArgb(128, 0, 255), Color.FromArgb(255, 0, 128), "PDF FILE WRITER");

            // change nonstroking (fill) color to purple
            Contents.SetColorNonStroking(Color.Purple);

            // Draw second line of heading text
            // arguments: Handwriting font, Font size 30 point, Position X=4.25", Y=9.0"
            // Text Justify: Center (text center will be at X position)
            Contents.DrawText(Comic, 30.0, 4.25, 8.75, TextJustify.Center, "Media Example");

            // create embedded media file
            Example1();
            Example2();

            // restore graphics sate (non stroking color will be restored to default)
            Contents.RestoreGraphicsState();

            // create the PDF file
            Document.CreateFile();

            // start default PDF reader and display the file
            Process Proc = new Process();

            Proc.StartInfo = new ProcessStartInfo(FileName);
            Proc.Start();

            // exit
            return;
        }
Ejemplo n.º 18
0
        public void CreateReport(SumReportLastLoad sumReport)
        {
            _sumReport = sumReport;
            foreach (SumReportRecord record in _sumReport.Records)
            {
                rows.Add(true);
                if (record.Napomena.Equals(String.Empty) == false)
                {
                    numOfRemarks++;
                    rows.Add(false);
                }
            }
            //LastInputOutputSavedData.GetData();


            // create document (letter size, portrait, inches)

            //string FileName = Constants.PATHOFSUMREPORT;
            string   FileName = Properties.Settings.Default.PATHOFSUMREPORT + _sumReport.Records[0].BrzbIzvestaja + ".pdf";
            FileInfo finfo    = new FileInfo(FileName);


            bool isInUse = false;

            if (finfo.Exists == true)
            {
                isInUse = IsFileinUse(finfo);
                if (isInUse == true)
                {
                    System.Windows.Forms.MessageBox.Show(" FAJL SA PUTANJOM" + System.Environment.NewLine + FileName + System.Environment.NewLine + "JE OTVOREN!" + System.Environment.NewLine + "Zatvorite fajl pa probajte ponovo prikazati zbirni izveštaj!");
                    return;
                }
                finfo.Delete();
            }


            Document = new PdfDocument(PageWidth, PageHeight, UnitOfMeasure.Inch);



            // set encryption
            //Document.SetEncryption("password", Permission.All & ~Permission.Print);

            // define font resource
            ArialNormal     = new PdfFont(Document, "Arial", System.Drawing.FontStyle.Regular, true);
            ArialBold       = new PdfFont(Document, "Arial", System.Drawing.FontStyle.Bold, true);
            ArialItalic     = new PdfFont(Document, "Arial", System.Drawing.FontStyle.Italic, true);
            ArialBoldItalic = new PdfFont(Document, "Arial", System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic, true);
            TimesNormal     = new PdfFont(Document, "Times New Roman", System.Drawing.FontStyle.Regular, true);
            TimesBold       = new PdfFont(Document, "Times New Roman", System.Drawing.FontStyle.Bold, true);
            TimesItalic     = new PdfFont(Document, "Times New Roman", System.Drawing.FontStyle.Italic, true);
            TimesBoldItalic = new PdfFont(Document, "Times New Roman", System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic, true);
            LucidaNormal    = new PdfFont(Document, "Lucida Console", System.Drawing.FontStyle.Regular, true);
            Comic           = new PdfFont(Document, "Comic Sans MS", System.Drawing.FontStyle.Regular, true);
            //Symbol = new PdfFont(Document, "Wingdings", System.Drawing.FontStyle.Regular, true);


            NoteY1 = NoteY0 + ArialNormal.LineSpacing(NoteSize);
            NoteY2 = NoteY1 + ArialNormal.LineSpacing(NoteSize);

            // print euro sign instead of cent sign
            //ArialNormal.CharSubstitution(0x20ac, 0x20ac, 161);
            //ArialNormal.CharSubstitution(9679, 9679, 162);
            //ArialNormal.CharSubstitution(1488, 1514, 177);		// hebrew
            //ArialNormal.CharSubstitution(1040, 1045, 204);		// russian
            //ArialNormal.CharSubstitution(945, 950, 210);		// greek
            ArialNormal.CharSubstitution(353, 353, 210);   //š
            ArialNormal.CharSubstitution(273, 273, 211);   //đ
            ArialNormal.CharSubstitution(269, 269, 212);   //č
            ArialNormal.CharSubstitution(263, 263, 213);   //ć
            ArialNormal.CharSubstitution(382, 382, 214);   //ž
            ArialNormal.CharSubstitution(352, 352, 215);   //Š
            ArialNormal.CharSubstitution(272, 272, 216);   //Đ
            ArialNormal.CharSubstitution(268, 268, 217);   //Č
            ArialNormal.CharSubstitution(262, 262, 218);   //Ć
            ArialNormal.CharSubstitution(381, 381, 219);   //ž
            ArialNormal.CharSubstitution(8320, 8320, 220); //nula u indeksu

            ArialBold.CharSubstitution(353, 353, 210);     //š
            ArialBold.CharSubstitution(273, 273, 211);     //đ
            ArialBold.CharSubstitution(269, 269, 212);     //č
            ArialBold.CharSubstitution(263, 263, 213);     //ć
            ArialBold.CharSubstitution(382, 382, 214);     //ž
            ArialBold.CharSubstitution(352, 352, 215);     //Š
            ArialBold.CharSubstitution(272, 272, 216);     //Đ
            ArialBold.CharSubstitution(268, 268, 217);     //Č
            ArialBold.CharSubstitution(262, 262, 218);     //Ć
            ArialBold.CharSubstitution(381, 381, 219);     //ž

            //// create page base contents
            CreateBaseContents();

            CreatePagesContents();

            //// pages
            //if (makeFromLastSample == true)
            //{
            //    CreatePage1Contents();
            //}
            //else
            //{
            //    CreatePage1Contents(makeFromLastSample, xmlName);
            //}
            ////CreatePage2Contents();


            // create pdf file
            Document.CreateFile(FileName);

            // start default PDF reader and display the file
            Process Proc = new Process();

            Proc.StartInfo = new ProcessStartInfo(FileName);
            Proc.Start();

            // exit
            return;
        }
Ejemplo n.º 19
0
        public void Test
        (
            Boolean Debug,
            String InputFileName
        )
        {
            // fish artwork from your favorite wpf or svg editing software (AI, Blend, Expression Design)
            // for hand writing minipath strings please see SVG or WPF reference on it (for example, https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Paths)
            string FishPathText = "M 73.302,96.9831C 88.1275,96.9831 100.146,109.002 100.146,123.827C 100.146,138.653 88.1275,150.671 73.302,150.671" +
                                  "C 58.4764,150.671 46.458,138.653 46.458,123.827C 46.458,109.002 58.4764,96.9831 73.302,96.9831 Z M 80.3771,118.625" +
                                  "C 87.8473,118.625 93.9031,124.681 93.9031,132.151C 93.9031,139.621 87.8473,145.677 80.3771,145.677C 72.9068,145.677 66.851,139.621 66.851,132.151" +
                                  "C 66.851,124.681 72.9069,118.625 80.3771,118.625 Z M 124.936,229.489L 124.936,230.05C 142.757,230.05 157.205,187.542 157.205,135.105" +
                                  "C 157.205,82.6682 142.757,40.1597 124.936,40.1597L 124.936,40.7208C 140.016,40.7208 152.241,82.9781 152.241,135.105" +
                                  "C 152.241,187.232 140.016,229.489 124.936,229.489 Z M 155.904,33.5723C 168.593,40.8964 181.282,48.2205 184.749,59.0803" +
                                  "C 188.216,69.9401 182.461,84.3356 176.705,98.7312C 187.217,82.7698 197.73,66.8085 194.263,55.9487C 190.796,45.0889 173.35,39.3306 155.904,33.5723 Z " +
                                  "M 221.06,47.217C 231.336,54.9565 241.612,62.6958 243.473,72.5309C 245.334,82.366 238.779,94.2968 232.224,106.228" +
                                  "C 243.092,93.4406 253.96,80.6536 252.099,70.8185C 250.238,60.9834 235.649,54.1002 221.06,47.217 Z M 190.088,103.489" +
                                  "C 200.631,113.663 211.175,123.836 211.914,135.212C 212.654,146.588 203.591,159.166 194.527,171.744C 208.585,158.796 222.643,145.848 221.903,134.472" +
                                  "C 221.163,123.096 205.625,113.293 190.088,103.489 Z M 227.222,175.988C 233.667,185.231 240.112,194.474 238.981,203.168" +
                                  "C 237.849,211.862 229.142,220.007 220.434,228.153C 232.965,220.47 245.497,212.787 246.628,204.093C 247.759,195.399 237.49,185.693 227.222,175.988 Z " +
                                  "M 176.183,170.829C 182.085,184.24 187.987,197.65 184.36,208.457C 180.734,219.265 167.58,227.47 154.426,235.675C 172.342,229.02 190.258,222.366 193.884,211.558" +
                                  "C 197.511,200.75 186.847,185.79 176.183,170.829 Z M 253.24,114.388C 261.541,123.744 269.842,133.1 269.72,142.831" +
                                  "C 269.598,152.561 261.052,162.667 252.506,172.773C 265.327,162.683 278.148,152.592 278.27,142.861C 278.392,133.13 265.816,123.759 253.24,114.388 Z " +
                                  "M 19.3722,114.348C 33.8527,95.7363 61.0659,59.7511 97.8151,40.6822C 117.532,30.4513 139.994,25.0899 164.816,24.6372" +
                                  "C 165.876,24.1644 167.083,23.6525 168.454,23.0983C 181.841,17.6879 210.836,8.25439 232.2,4.09256C 253.564,-0.0693054 267.298,1.04053 273.749,4.99429" +
                                  "C 280.2,8.94803 279.368,15.7458 278.743,24.4856C 278.119,33.2255 277.703,43.9076 276.94,49.1099C 276.927,49.2001 276.913,49.2887 276.9,49.3756" +
                                  "C 318.05,66.1908 360.168,89.8268 395.044,112.964C 408.876,122.14 421.569,131.238 433.26,140.058C 439.423,134.13 445.322,128.267 450.904,122.587" +
                                  "C 478.22,94.7909 497.963,71.3744 513.5,56.0696C 529.037,40.7648 540.368,33.5717 541.331,39.3597C 542.295,45.1478 532.891,63.9171 528.998,87.7075" +
                                  "C 525.105,111.498 526.722,140.309 533.661,167.068C 540.599,193.827 552.858,218.532 549.803,224.507C 546.748,230.482 528.378,217.727 502.239,196.166" +
                                  "C 483.768,180.932 461.418,161.301 433.26,140.058C 409.264,163.142 381.252,187.219 352.261,205.363C 315.824,228.167 277.841,241.6 230.108,245.486" +
                                  "C 182.376,249.372 124.895,243.713 84.9205,225.782C 44.946,207.851 22.4781,177.648 11.4752,160.545C 0.472214,143.443 0.934143,139.44 2.03903,136.819" +
                                  "C 3.14392,134.199 4.89172,132.96 19.3722,114.348 Z ";

            // water artwork
            string WavePathOriginal = "M 0.000854492,723.999L 1106,723.999L 1106,616.629C 1025.42,656.405 941.978,687.324 846.084,679.721C 721.562,669.847 576.045,595.015 425.822,588.779" +
                                      "C 286.673,583.003 143.486,636.082 0.000854492,693.5L 0.000854492,723.999 Z M 423.35,26.0787C 573.573,32.3146 719.09,107.146 843.612,117.02C 940.487,124.701 1024.65,93.0672 1106,52.7042" +
                                      "L 1106,-1.90735e-005L 0.000854492,-1.90735e-005L 0.000854492,129.811C 142.658,72.7739 285,20.3355 423.35,26.0787 Z M 6.10352e-005,545.976C 143.485,488.558 286.672,435.478 425.822,441.255" +
                                      "C 576.045,447.491 721.562,522.322 846.084,532.196C 941.978,539.8 1025.42,508.88 1106,469.104L 1106,200.228C 1024.65,240.592 940.486,272.226 843.611,264.544" +
                                      "C 719.089,254.671 573.572,179.839 423.349,173.603C 284.999,167.86 142.657,220.298 6.10352e-005,277.335L 6.10352e-005,545.976 Z";

/*
 *              string ItalianFish = "M73,302;96,9831C88,1275;96,9831 100,146;109,002 100,146;123,827 100,146;138,653 88,1275;150,671 73,302;150,671 58,4764;150,671 46,458;138,653 46,458;123,827 46,458;109,002 58,4764;96,9831 73,302;96,9831z M80,3771;118,625C87,8473;118,625 93,9031;124,681 93,9031;132,151 93,9031;139,621 87,8473;145,677 80,3771;145,677 72,9068;145,677 66,851;139,621 66,851;132,151 66,851;124,681 72,9069;118,625 80,3771;118,625z M124,936;229,489L124,936;230,05C142,757;230,05 157,205;187,542 157,205;135,105 157,205;82,6682 142,757;40,1597 124,936;40,1597L124,936;40,7208C140,016;40,7208 152,241;82,9781 152,241;135,105 152,241;187,232 140,016;229,489 124,936;229,489z M155,904;33,5723C168,593;40,8964 181,282;48,2205 184,749;59,0803 188,216;69,9401 182,461;84,3356 176,705;98,7312 187,217;82,7698 197,73;66,8085 194,263;55,9487 190,796;45,0889 173,35;39,3306 155,904;33,5723z M221,06;47,217C231,336;54,9565 241,612;62,6958 243,473;72,5309 245,334;82,366 238,779;94,2968 232,224;106,228 243,092;93,4406 253,96;80,6536 252,099;70,8185 250,238;60,9834 235,649;54,1002 221,06;47,217z M190,088;103,489C200,631;113,663 211,175;123,836 211,914;135,212 212,654;146,588 203,591;159,166 194,527;171,744 208,585;158,796 222,643;145,848 221,903;134,472 221,163;123,096 205,625;113,293 190,088;103,489z M227,222;175,988C233,667;185,231 240,112;194,474 238,981;203,168 237,849;211,862 229,142;220,007 220,434;228,153 232,965;220,47 245,497;212,787 246,628;204,093 247,759;195,399 237,49;185,693 227,222;175,988z M176,183;170,829C182,085;184,24 187,987;197,65 184,36;208,457 180,734;219,265 167,58;227,47 154,426;235,675 172,342;229,02 190,258;222,366 193,884;211,558 197,511;200,75 186,847;185,79 176,183;170,829z M253,24;114,388C261,541;123,744 269,842;133,1 269,72;142,831 269,598;152,561 261,052;162,667 252,506;172,773 265,327;162,683 278,148;152,592 278,27;142,861 278,392;133,13 265,816;123,759 253,24;114,388z M19,3722;114,348C33,8527;95,7363 61,0659;59,7511 97,8151;40,6822 117,532;30,4513 139,994;25,0899 164,816;24,6372 165,876;24,1644 167,083;23,6525 168,454;23,0983 181,841;17,6879 210,836;8,25439 232,2;4,09256 253,564;-0,0693054 267,298;1,04053 273,749;4,99429 280,2;8,94803 279,368;15,7458 278,743;24,4856 278,119;33,2255 277,703;43,9076 276,94;49,1099 276,927;49,2001 276,913;49,2887 276,9;49,3756 318,05;66,1908 360,168;89,8268 395,044;112,964 408,876;122,14 421,569;131,238 433,26;140,058 439,423;134,13 445,322;128,267 450,904;122,587 478,22;94,7909 497,963;71,3744 513,5;56,0696 529,037;40,7648 540,368;33,5717 541,331;39,3597 542,295;45,1478 532,891;63,9171 528,998;87,7075 525,105;111,498 526,722;140,309 533,661;167,068 540,599;193,827 552,858;218,532 549,803;224,507 546,748;230,482 528,378;217,727 502,239;196,166 483,768;180,932 461,418;161,301 433,26;140,058 409,264;163,142 381,252;187,219 352,261;205,363 315,824;228,167 277,841;241,6 230,108;245,486 182,376;249,372 124,895;243,713 84,9205;225,782 44,946;207,851 22,4781;177,648 " +
 *                      "11,4752;160,545 0,472214;143,443 0,934143;139,44 2,03903;136,819 3,14392;134,199 4,89172;132,96 19,3722;114,348z";
 *
 *              string ItalianWave = "M0,000854492;723,999L1106;723,999 1106;616,629C1025,42;656,405 941,978;687,324 846,084;679,721 721,562;669,847 576,045;595,015 425,822;588,779 286,673;583,003 143,486;636,082 0,000854492;693,5L0,000854492;723,999z M423,35;26,0787C573,573;32,3146 719,09;107,146 843,612;117,02 940,487;124,701 1024,65;93,0672 1106;52,7042L1106;-1,90735E-05 0,000854492;-1,90735E-05 0,000854492;129,811C142,658;72,7739;285;20,3355;423,35;26,0787z M6,10352E-05;545,976C143,485;488,558 286,672;435,478 425,822;441,255 576,045;447,491 721,562;522,322 846,084;532,196 941,978;539,8 1025,42;508,88 1106;469,104L1106;200,228C1024,65;240,592 940,486;272,226 843,611;264,544 719,089;254,671 573,572;179,839 423,349;173,603 284,999;167,86 142,657;220,298 6,10352E-05;277,335L6,10352E-05;545,976z";
 *      // water artwork
 *      string WavePathText = "M 0,724L 1106,724L 1106,617C 1025,656 942,687 846,680C 722,670 576,595 426,589C 287,583 143,636 0,694L 0,724 Z " +
 *                      "M 423,26C 574,32 719,107 844,117C 940,125 1025,93 1106,53L 1106,0L 0,0L 0,130C 143,73 285,20 423,26 Z " +
 *                      "M 0,546C 143,489 287,435 426,441C 576,447 722,522 846,532C 942,540 1025,509 1106,469L 1106,200C 1025,241 940,272 844,265" +
 *                      "C 719,255 574,180 423,174C 285,168 143,220 0,277L 0,546 Z";
 *              string MyWavePathText = "M 0 0 L 1000 0 L 1000 100 C 550 550 550 -300 0 250 Z" +
 *                                              "M 0 550 C 550 0 550 850 1000 400 L 1000 850 C 550 1300 550 450 0 1000 Z" +
 *                                              "M 0 1400 L 0 1300 C 550 750 550 1600 1000 1150 L 1000 1400 Z";
 */

            // create document
            using (PdfDocument Document = new PdfDocument(PaperType.Letter, false, UnitOfMeasure.Inch, InputFileName))
            {
                // define font
                PdfFont ArialNormal = PdfFont.CreatePdfFont(Document, "Arial", FontStyle.Regular);

                // Add new page
                PdfPage Page = new PdfPage(Document);

                // Add contents to page
                PdfContents Contents = new PdfContents(Page);

                // translate origin
                Contents.SaveGraphicsState();

                // test draw
//			string TestDraw1 = "M 0 0 L 1000 0";
                string TestDraw1 = "M 0 0 L 100 200 L 200 0 Z M 0 200 L 100 0 L 200 200 Z";
//			string TestDraw1 = "M 0 0 A 400 400 0 0 0 100 200 A 400 400 0 0 0 200 0 A 400 400 0 0 0 0 0 Z" +
//				"M 0 250 A 400 400 0 0 1 100 -50 A 400 400 0 0 1 250 250 A 400 400 0 0 1 0 250 Z";
                //string TestDraw1 = "M 0 0 L 100 200 L 200 0";
                DrawWPFPath TestPath1 = new DrawWPFPath(TestDraw1, YAxisDirection.Up);
                TestPath1.SetBrush(Color.DarkMagenta);
                SysMedia.Pen Pen = new SysMedia.Pen(new SysMedia.SolidColorBrush(SysMedia.Colors.DarkBlue), 2);
                Pen.StartLineCap = SysMedia.PenLineCap.Flat;
                Pen.LineJoin     = SysMedia.PenLineJoin.Bevel;
                Pen.DashStyle    = new SysMedia.DashStyle(new double[] { 1.0 }, 0.0);
                TestPath1.SetPen(Pen);
                Contents.DrawWPFPath(TestPath1, 1.0, 4.0, 5.0, 3.0);

                string      TestDraw2 = "M 0 0 L 200 200 A 200 200 0 1 0 0 0 Z";
                DrawWPFPath TestPath2 = new DrawWPFPath(TestDraw2, YAxisDirection.Up);
//			string TestDraw = "M 0 200 L 200 0 A 200 200 0 1 1 0 200";
//			DrawWPFPath TestPath = new DrawWPFPath(TestDraw, YAxisDirection.Down);
                TestPath2.SetPenWidth(0.05);
                TestPath2.SetPen(Color.Chocolate);
                Contents.DrawWPFPath(TestPath2, 4.25, 4.0, 3.0, 3.0, ContentAlignment.BottomLeft);

                // load fish path
                DrawWPFPath FishPath = new DrawWPFPath(FishPathText, YAxisDirection.Down);

                // set pen for both fish
                FishPath.SetPen(Color.FromArgb(255, 255, 80, 0));
                FishPath.SetPenWidth(0.02);

//			PdfTilingPattern BrickPattern = PdfTilingPattern.SetBrickPattern(Document, 0.25, Color.LightYellow, Color.SandyBrown);
//			FishPath.SetBrush(BrickPattern);

                // draw small fish
                FishPath.SetBrush(Color.FromArgb(255, 67, 211, 216));
                Contents.DrawWPFPath(FishPath, 2.5, 5.75, 4.5, 3.0, ContentAlignment.TopRight);

                // big fish drawing area
                Color[]          BigFishBrushColor = new Color[] { Color.FromArgb(0xff, 0xff, 0x50, 0), Color.FromArgb(0xff, 0x27, 0xda, 0xff) };
                PdfRadialShading RadialShading     = new PdfRadialShading(Document, new PdfShadingFunction(Document, BigFishBrushColor));
                RadialShading.SetGradientDirection(0.15, 0.5, 0.0, 0.25, 0.5, 1.3, MappingMode.Relative);
                FishPath.SetBrush(RadialShading, 1.0);
                Contents.DrawWPFPath(FishPath, 1.5, 2.0, 5.5, 5.5, ContentAlignment.BottomLeft);

                // load wave
                DrawWPFPath WavePath = new DrawWPFPath(WavePathOriginal, YAxisDirection.Up);

                // draw wave
                Color[]         WaveBrushColor = new Color[] { Color.Cyan, Color.DarkBlue };
                PdfAxialShading AxialShading   = new PdfAxialShading(Document, new PdfShadingFunction(Document, WaveBrushColor));
                AxialShading.SetAxisDirection(0.0, 1.0, 1.0, 0.0, MappingMode.Relative);
                WavePath.SetBrush(AxialShading, 0.55);
                Contents.DrawWPFPath(WavePath, 1.0, 1.0, 6.5, 9.0);

                // restore graphics state
                Contents.RestoreGraphicsState();

                // create pdf file
                Document.CreateFile();

                // start default PDF reader and display the file
                Process Proc = new Process();
                Proc.StartInfo = new ProcessStartInfo(InputFileName);
                Proc.Start();
            }

            return;
        }
Ejemplo n.º 20
0
        public FileInfo CreateOfferDocument(Offer offer, bool asOrder = false, bool withPreview = true)
        {
            ResetVars();
            myOffer = offer;
            PdfDocument  doc;
            PdfPage      page;
            PdfContents  content;
            PdfImage     img;
            double       lineSpacing;
            double       descent;
            const double fontSize = 10.0;
            bool         isOffer  = (this.myOffer.Bestellkennzeichen | asOrder);

            string fullName = Path.Combine(CatalistRegistry.Application.OfferFilePath, offer.OfferId + ".pdf");

            doc       = new PdfDocument(PaperType.A4, false, UnitOfMeasure.mm, fullName);
            doc.Debug = false;
            page      = new PdfPage(doc);
            content   = new PdfContents(page);
            content.SetLineWidth(0.03);

            fontDefault    = new PdfFont(doc, "Calibri", System.Drawing.FontStyle.Regular, true);
            myFontBold     = new PdfFont(doc, "Calibri", System.Drawing.FontStyle.Bold, true);
            fontFooter     = new PdfFont(doc, "Calibri Light", System.Drawing.FontStyle.Regular, true);
            fontFooterBold = new PdfFont(doc, "Calibri Light", System.Drawing.FontStyle.Bold, true);
            fontPriceTotal = new PdfFont(doc, "Calibri Light", System.Drawing.FontStyle.Bold, true);

            lineSpacing = fontDefault.LineSpacing(fontSize);
            descent     = fontDefault.Descent(fontSize);

            // Header
            string imagePath = Path.Combine(CatalistRegistry.Application.PicturePath, "briefkopf.png");

            img = new PdfImage(doc, imagePath);
            content.DrawImage(img, 5, pageHeight - 27.9 - 5, 199.6, 27.4);
            content.DrawLine(xLeftMargin - 5, pageHeight - 27.9 - 5 - 2, xRightMargin + 5, pageHeight - 27.9 - 5 - 2);

            string absender = @"Cut & Print Media GmbH & Co. KG · Osterheide 9 · 49124 Georgsmarienhütte";

            content.DrawText(fontDefault, fontSize - 4, 18, pageHeight - 49.5, absender);
            content.DrawLine(18, pageHeight - 50.5, 84.5, pageHeight - 50.5, 0.1);
            content.DrawText(fontDefault, fontSize + 2, 18, pageHeight - 55, offer.Customer.CompanyName1);
            content.DrawText(fontDefault, fontSize + 2, 18, pageHeight - 65, offer.Customer.Street);
            string zipCity = string.Format("{0} {1}", offer.Customer.ZipCode, offer.Customer.City);

            content.DrawText(fontDefault, fontSize + 2, 18, pageHeight - 71, zipCity);

            string vorgang = isOffer ? "Bestellung" : "Angebot";

            content.DrawText(fontDefault, fontSize + 2, xVLine3 + 5, pageHeight - 55, "Kunden-Nr.:");
            content.DrawText(fontDefault, fontSize + 2, xVLine5 - 13, pageHeight - 55, offer.CustomerId.Substring(0, 5));
            content.DrawText(fontDefault, fontSize + 2, xVLine3 + 5, pageHeight - 60, vorgang + " Nr.:");
            content.DrawText(fontDefault, fontSize + 2, xVLine5 - 13, pageHeight - 60, offer.OfferId);
            content.DrawText(fontDefault, fontSize + 2, xVLine3 + 5, pageHeight - 65, "Datum:");
            content.DrawText(fontDefault, fontSize + 2, xVLine5 - 13, pageHeight - 65, offer.ChangeDate.ToShortDateString());
            content.DrawText(fontDefault, fontSize + 2, xVLine3 + 5, pageHeight - 70, "Bearbeitet von:");
            content.DrawText(fontDefault, fontSize + 2, xVLine5 - 13, pageHeight - 70, offer.ChangeUser);

            content.DrawText(myFontBold, fontSize + 2, 10, pageHeight - 96.5, vorgang + " " + offer.OfferId);

            var table = new PdfTable(page, content, fontDefault, 9);

            table.TableStartEvent += tab_TableStartEvent;
            table.TableEndEvent   += tab_TableEndEvent;
            table.TableArea        = new PdfRectangle(10D, 35D, 200D, pageHeight - 40);
            table.RowTopPosition   = pageHeight - 100D;           // 10cm vom oberen Rand
            table.SetColumnWidth(9D, 34D, 86D, 13D, 19D, 19D);
            table.HeaderOnEachPage = true;

            table.Header[colPos].Style           = table.HeaderStyle;
            table.Header[colPos].Style.Alignment = System.Drawing.ContentAlignment.MiddleRight;
            table.Header[colPos].Value           = "Pos.";

            table.Header[colArtNr].Value  = "Artikel-Nr.";
            table.Header[colArtBez].Value = "Artikelbezeichnung";

            table.Header[colMenge].Style           = table.HeaderStyle;
            table.Header[colMenge].Style.Alignment = System.Drawing.ContentAlignment.MiddleRight;
            table.Header[colMenge].Value           = "Menge";

            table.Header[colPreis].Style           = table.HeaderStyle;
            table.Header[colPreis].Style.Alignment = System.Drawing.ContentAlignment.MiddleRight;
            table.Header[colPreis].Value           = "Einzelpreis";

            table.Header[colGesamt].Style           = table.HeaderStyle;
            table.Header[colGesamt].Style.Alignment = System.Drawing.ContentAlignment.MiddleRight;
            table.Header[colGesamt].Value           = "Gesamtpreis";

            table.DefaultHeaderStyle.Font          = myFontBold;
            table.DefaultHeaderStyle.Alignment     = System.Drawing.ContentAlignment.TopLeft;
            table.DefaultHeaderStyle.MultiLineText = false;

            table.DefaultCellStyle.Font      = fontDefault;
            table.DefaultCellStyle.FontSize  = 9;
            table.DefaultCellStyle.Alignment = System.Drawing.ContentAlignment.TopLeft;

            table.Cell[colPos].Style           = table.CellStyle;
            table.Cell[colPos].Style.Alignment = System.Drawing.ContentAlignment.TopRight;

            table.Cell[colArtNr].Style = table.CellStyle;
            table.Cell[colArtNr].Style.TextBoxTextJustify = TextBoxJustify.Left;

            table.Cell[colArtBez].Style = table.CellStyle;
            table.Cell[colArtBez].Style.TextBoxTextJustify = TextBoxJustify.Left;

            table.Cell[colMenge].Style           = table.CellStyle;
            table.Cell[colMenge].Style.Format    = "#,##0";
            table.Cell[colMenge].Style.Alignment = System.Drawing.ContentAlignment.TopRight;

            table.Cell[colPreis].Style           = table.CellStyle;
            table.Cell[colPreis].Style.Format    = "#,##0.00";
            table.Cell[colPreis].Style.Alignment = System.Drawing.ContentAlignment.TopRight;

            table.Cell[colGesamt].Style = table.CellStyle;
            table.Cell[colGesamt].Style.ForegroundColor = System.Drawing.Color.DarkRed;
            table.Cell[colGesamt].Style.Format          = "#,##0.00";
            table.Cell[colGesamt].Style.Alignment       = System.Drawing.ContentAlignment.TopRight;

            int dCount = offer.OfferDetails.Count;

            for (int i = 0; i < dCount; i++)
            {
                lastRow |= i == dCount - 1;

                table.Cell[colPos].Value   = offer.OfferDetails[i].Position;
                table.Cell[colArtNr].Value = offer.OfferDetails[i].Artikelnummer;
                TextBox txtBezeichnung = table.Cell[colArtBez].CreateTextBox();
                txtBezeichnung.AddText(myFontBold, 9, offer.OfferDetails[i].Artikelname);
                if (!isOffer)
                {
                    txtBezeichnung.AddText(fontDefault, 9, string.Format("\n\n{0}", offer.OfferDetails[i].Artikeltext.Replace("\t", " ")));
                }
                table.Cell[colMenge].Value = string.Format("{0:#,##0} {1}", offer.OfferDetails[i].Menge, offer.OfferDetails[i].Einheit);

                if (!isOffer)
                {
                    table.Cell[colPreis].Value  = offer.OfferDetails[i].Kundenpreis;
                    table.Cell[colGesamt].Value = offer.OfferDetails[i].Zeilensumme;
                    zwischenSumme += offer.OfferDetails[i].Zeilensumme;
                }
                else
                {
                    table.Cell[colPreis].Value  = "-";
                    table.Cell[colGesamt].Value = "-";
                }
                table.DrawRow(offer.OfferDetails[i].NeueSeite);
            }
            table.Close();

            try
            {
                doc.CreateFile();
                if (File.Exists(fullName) && withPreview)
                {
                    // Datei in das lokale TEMP Verzeichnis kopieren
                    var    temp            = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                    string prefix          = asOrder ? "B" : "A";
                    var    tempFilename    = string.Format("{0}{1}.pdf", prefix, DateTime.Now.ToString("yyyy-MM-dd_hh.mm.ss"));
                    var    tempFileAndPath = Path.Combine(temp, tempFilename);
                    File.Copy(fullName, tempFileAndPath);
                    var proc = new Process();
                    proc.StartInfo = new ProcessStartInfo(tempFileAndPath);
                    proc.Start();
                }

                return(new FileInfo(fullName));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }