コード例 #1
0
        private void SamplePage2(PdfDocument document)
        {
            PdfPage   page = document.AddPage();
            XGraphics gfx  = XGraphics.FromPdfPage(page);

            gfx.MUH = PdfFontEncoding.Unicode;

            Document doc = new Document();

            MigraDoc.Rendering.DocumentRenderer docRender = new MigraDoc.Rendering.DocumentRenderer(doc);

            docRender.PrepareDocument();

            XRect A4Rect = new XRect(0, 0, XUnit.FromCentimeter(21).Point, XUnit.FromCentimeter(29.7).Point);

            int pageCount = docRender.FormattedDocument.PageCount;

            for (int idx = 0; idx < pageCount; idx++)
            {
                XRect rect = GetRect(idx);
                XGraphicsContainer container = gfx.BeginContainer(rect, A4Rect, XGraphicsUnit.Point);

                gfx.DrawRectangle(XPens.LightGray, A4Rect);

                docRender.RenderPage(gfx, idx + 1);

                gfx.EndContainer(container);
            }
        }
コード例 #2
0
        internal static byte[] GenerateApplicationPdf(Application application)
        {
            //Create pdf document
            PdfDocument pdf = new PdfDocument();
            PdfPage page = pdf.AddPage();
            //Create pdf content
            Document doc = CreateDocument("Application", string.Format("{1}, {0}",application.Person.Name, application.Person.Surname));
            PopulateDocument(ref doc, application);
            //Create renderer for content
            DocumentRenderer renderer = new DocumentRenderer(doc);
            renderer.PrepareDocument();
            XRect A4 = new XRect(0, 0, XUnit.FromCentimeter(21).Point, XUnit.FromCentimeter(29.7).Point);
            XGraphics gfx = XGraphics.FromPdfPage(page);

            int pages = renderer.FormattedDocument.PageCount;
            for(int i = 0; i < pages; i++)
            {
                var container = gfx.BeginContainer(A4, A4, XGraphicsUnit.Point);
                gfx.DrawRectangle(XPens.LightGray, A4);
                renderer.RenderPage(gfx, (i + 1));
                gfx.EndContainer(container);
            }

            using (MemoryStream ms = new MemoryStream())
            {
                pdf.Save(ms, true);
                return ms.ToArray();
            }
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: dankennedy/MigraDoc
        /// <summary>
        /// Renders a whole MigraDoc document scaled to a single PDF page.
        /// </summary>
        static void SamplePage2(PdfDocument document)
        {
            PdfPage page = document.AddPage();
              XGraphics gfx = XGraphics.FromPdfPage(page);
              // HACK²
              gfx.MUH = PdfFontEncoding.Unicode;
              gfx.MFEH = PdfFontEmbedding.Default;

              // Create document from HalloMigraDoc sample
              Document doc = HelloMigraDoc.Documents.CreateDocument();

              // Create a renderer and prepare (=layout) the document
              MigraDoc.Rendering.DocumentRenderer docRenderer = new DocumentRenderer(doc);
              docRenderer.PrepareDocument();

              // For clarity we use point as unit of measure in this sample.
              // A4 is the standard letter size in Germany (21cm x 29.7cm).
              XRect A4Rect = new XRect(0, 0, A4Width, A4Height);

              int pageCount = docRenderer.FormattedDocument.PageCount;
              for (int idx = 0; idx < pageCount; idx++)
              {
            XRect rect = GetRect(idx);

            // Use BeginContainer / EndContainer for simplicity only. You can naturaly use you own transformations.
            XGraphicsContainer container = gfx.BeginContainer(rect, A4Rect, XGraphicsUnit.Point);

            // Draw page border for better visual representation
            gfx.DrawRectangle(XPens.LightGray, A4Rect);

            // Render the page. Note that page numbers start with 1.
            docRenderer.RenderPage(gfx, idx + 1);

            // Note: The outline and the hyperlinks (table of content) does not work in the produced PDF document.

            // Pop the previous graphical state
            gfx.EndContainer(container);
              }
        }
コード例 #4
0
ファイル: MainWindow.xaml.cs プロジェクト: loker7/Faktury2020
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            Books books = new Books();

            PdfDocument document = new PdfDocument(); // Create a new PDF document

            document.Info.Title  = "Created with PDFsharp";
            document.Info.Author = "Faktury2020";
            PdfPage         page    = document.AddPage();                           // Create an empty page
            XGraphics       gfx     = XGraphics.FromPdfPage(page);                  // Get an XGraphics object for drawing
            XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode); // Set font encoding to unicode
            //albo mogę ew. spróbować jeśli przestanie działać:
            //gfx.MUH = PdfFontEncoding.Unicode;
            //gfx.MFEH = PdfFontEmbedding.Default;
            XFont font = new XFont("Times New Roman", 12, XFontStyle.Regular, options); //Then you'll create a font:



            Document doc = new Document(); //tu startuje migradoc, po kolei: dokument, sekcja i paragraf..
            Section  sec = doc.AddSection();

            //def tableMiejsceiDataWystawienia TUTAJ
            Table tableMiejsceiDataWystawienia = new Table();

            tableMiejsceiDataWystawienia.Borders.Width = 0.0;

            Column columnMiejsceiDataWystawienia = tableMiejsceiDataWystawienia.AddColumn(Unit.FromCentimeter(5));

            columnMiejsceiDataWystawienia.Format.Alignment = ParagraphAlignment.Left;
            Column columnMiejsceiDataWystawienia2 = tableMiejsceiDataWystawienia.AddColumn(Unit.FromCentimeter(12));

            columnMiejsceiDataWystawienia2.Format.Alignment = ParagraphAlignment.Right;


            Row  rowMiejsceiDataWystawienia  = tableMiejsceiDataWystawienia.AddRow();
            Cell cellMiejsceiDataWystawienia = rowMiejsceiDataWystawienia.Cells[0];

            cellMiejsceiDataWystawienia = rowMiejsceiDataWystawienia.Cells[0];
            cellMiejsceiDataWystawienia.AddParagraph("Katowice");
            // rowKontoBankowe.Format.Alignment = ParagraphAlignment.Right;


            cellMiejsceiDataWystawienia = rowMiejsceiDataWystawienia.Cells[1];
            cellMiejsceiDataWystawienia.AddParagraph("Wystawiono dnia: 16-03-2020");

            doc.LastSection.Add(tableMiejsceiDataWystawienia);

            //Paragraph miasto = sec.AddParagraph();
            //miasto.AddText("Katowice");
            //miasto.Format.Alignment = ParagraphAlignment.Left;

            //Paragraph dataWystawienia = sec.AddParagraph();
            //dataWystawienia.AddText("Wystawiono dnia: 16-03-2020");
            //dataWystawienia.Format.Alignment = ParagraphAlignment.Right;

            sec.AddParagraph();

            Paragraph numerFaktury = sec.AddParagraph();

            numerFaktury.AddText("Faktura proforma 1-TEST-2-2020");
            numerFaktury.Format.Font.Bold = true;
            numerFaktury.Format.Alignment = ParagraphAlignment.Center;

            sec.AddParagraph();

            Paragraph dataSprzedazy = sec.AddParagraph();

            dataSprzedazy.AddText("Data sprzedaży: 2-2020");
            dataSprzedazy.Format.Font.Bold = true;
            dataSprzedazy.Format.Alignment = ParagraphAlignment.Right;

            Paragraph sposobZaplaty = sec.AddParagraph();

            sposobZaplaty.AddText("Forma płatności: GOTÓWKA");
            sposobZaplaty.Format.Font.Bold = true;
            sposobZaplaty.Format.Alignment = ParagraphAlignment.Right;

            Paragraph terminPlatnosci = sec.AddParagraph();

            terminPlatnosci.AddText("Termin płatności: 01-04-2020");
            terminPlatnosci.Format.Font.Bold = true;
            terminPlatnosci.Format.Alignment = ParagraphAlignment.Right;

            //def table sprzedawca-nabywca(SN) and its parts
            Table tableSN = new Table();

            tableSN.Borders.Width = 0.0;
            Column columnSN = tableSN.AddColumn(Unit.FromCentimeter(9));

            columnSN.Format.Alignment = ParagraphAlignment.Left;
            _ = tableSN.AddColumn(Unit.FromCentimeter(9));
            columnSN.Format.Alignment = ParagraphAlignment.Left;
            Row  rowSN  = tableSN.AddRow();
            Cell cellSN = rowSN.Cells[0];

            cellSN = rowSN.Cells[0];
            cellSN.AddParagraph("Sprzedawca");
            cellSN.Format.Font.Bold = true;
            cellSN = rowSN.Cells[1];
            cellSN.AddParagraph("Nabywca");
            cellSN.Format.Font.Bold = true;

            Row  rowEmpty  = tableSN.AddRow();
            Cell cellEmpty = rowEmpty.Cells[0];

            cellEmpty = rowEmpty.Cells[0];
            // cellEmpty.AddParagraph(""); //to jest niepotrzebne = i tak jest pusta linia
            cellEmpty = rowEmpty.Cells[1];
            // cellEmpty.AddParagraph(""); //to jest niepotrzebne = i tak jest pusta linia

            Row  rowNazwaSprzedawcyiNabywcy  = tableSN.AddRow();
            Cell cellNazwaSprzedawcyiNabywcy = rowEmpty.Cells[0];

            cellNazwaSprzedawcyiNabywcy = rowNazwaSprzedawcyiNabywcy.Cells[0];
            cellNazwaSprzedawcyiNabywcy.AddParagraph("xSolutions Sp. z o.o.");
            cellNazwaSprzedawcyiNabywcy.Format.Font.Bold = true;
            cellNazwaSprzedawcyiNabywcy = rowNazwaSprzedawcyiNabywcy.Cells[1];
            cellNazwaSprzedawcyiNabywcy.AddParagraph("Aldona Nieznana");
            cellNazwaSprzedawcyiNabywcy.Format.Font.Bold = true;

            Row  rowUlicaSprzedawcyiNabywcy  = tableSN.AddRow();
            Cell cellUlicaSprzedawcyiNabywcy = rowEmpty.Cells[0];

            cellUlicaSprzedawcyiNabywcy = rowUlicaSprzedawcyiNabywcy.Cells[0];
            cellUlicaSprzedawcyiNabywcy.AddParagraph("ul. Mickiewicza 29");
            cellUlicaSprzedawcyiNabywcy = rowUlicaSprzedawcyiNabywcy.Cells[1];
            cellUlicaSprzedawcyiNabywcy.AddParagraph("ul Nieznana 20");

            Row  rowMiastoiKodSprzedawcyiNabywcy  = tableSN.AddRow();
            Cell cellMiastoiKodSprzedawcyiNabywcy = rowEmpty.Cells[0];

            cellMiastoiKodSprzedawcyiNabywcy = rowUlicaSprzedawcyiNabywcy.Cells[0];
            cellMiastoiKodSprzedawcyiNabywcy.AddParagraph("40-085 Katowice");
            cellMiastoiKodSprzedawcyiNabywcy = rowUlicaSprzedawcyiNabywcy.Cells[1];
            cellMiastoiKodSprzedawcyiNabywcy.AddParagraph("41-200 Sosnowiec");

            Row rowEmpty2 = tableSN.AddRow();
            // Cell cellEmpty2 = rowEmpty2.Cells[0];
            //cellEmpty2 = rowEmpty2.Cells[0];

            //cellEmpty2 = rowEmpty2.Cells[1];


            Row  rowNIPSprzedawcyiNabywcy  = tableSN.AddRow();
            Cell cellNIPSprzedawcyiNabywcy = rowEmpty.Cells[0];

            cellNIPSprzedawcyiNabywcy = rowNIPSprzedawcyiNabywcy.Cells[0];
            cellNIPSprzedawcyiNabywcy.AddParagraph("NIP 634-293-59-61");
            cellNIPSprzedawcyiNabywcy.Format.Font.Bold = true;
            cellNIPSprzedawcyiNabywcy = rowNIPSprzedawcyiNabywcy.Cells[1];
            cellNIPSprzedawcyiNabywcy.AddParagraph("NIP 000-000-00-00");
            cellNIPSprzedawcyiNabywcy.Format.Font.Bold = true;

            Row rowEmpty3 = tableSN.AddRow();

            //def table bank i konto bankowe
            Table tableBankiKontoBankowe = new Table();

            tableBankiKontoBankowe.Borders.Width = 0.0;
            Column columnBankiKontoBankowe1 = tableBankiKontoBankowe.AddColumn(Unit.FromCentimeter(5));

            columnBankiKontoBankowe1.Format.Alignment = ParagraphAlignment.Right;
            Column columnBankiKontoBankowe2 = tableBankiKontoBankowe.AddColumn(Unit.FromCentimeter(9));

            columnBankiKontoBankowe2.Format.Alignment = ParagraphAlignment.Left;
            Row  rowBankiKontoBankowe  = tableBankiKontoBankowe.AddRow();
            Cell cellBankiKontoBankowe = rowBankiKontoBankowe.Cells[0];

            cellBankiKontoBankowe = rowBankiKontoBankowe.Cells[0];
            cellBankiKontoBankowe.AddParagraph("Bank: ");
            cellBankiKontoBankowe.Format.Font.Bold = true;
            cellBankiKontoBankowe = rowBankiKontoBankowe.Cells[1];
            cellBankiKontoBankowe.AddParagraph("Nest Bank");
            cellBankiKontoBankowe.Format.Font.Bold = true;

            //def konto bankowe
            Row  rowKontoBankowe  = tableBankiKontoBankowe.AddRow();
            Cell cellKontoBankowe = rowKontoBankowe.Cells[0];

            cellKontoBankowe = rowKontoBankowe.Cells[0];
            cellKontoBankowe.AddParagraph("Konto: ");
            // rowKontoBankowe.Format.Alignment = ParagraphAlignment.Right;
            cellKontoBankowe.Format.Font.Bold = true;

            cellKontoBankowe = rowKontoBankowe.Cells[1];
            cellKontoBankowe.AddParagraph("44 2530 0008 2064 1044 1937 0001");
            cellKontoBankowe.Format.Font.Bold = true;

            Row rowEmpty4 = tableBankiKontoBankowe.AddRow();

            // chcę, aby 'POZYCJE FAKTURY' było napisane nie w obramowaniu a nad tabelą, robię więc manewr polegający na przedłużeniu niewidocznej tabeli
            Row  rowPozycjeFaktury  = tableBankiKontoBankowe.AddRow();
            Cell cellPozycjeFaktury = rowPozycjeFaktury.Cells[1];

            cellPozycjeFaktury = rowPozycjeFaktury.Cells[1];
            cellPozycjeFaktury.AddParagraph("POZYCJE FAKTURY");
            cellPozycjeFaktury.Format.Font.Bold = true;
            rowPozycjeFaktury.Format.Alignment  = ParagraphAlignment.Left;


            doc.LastSection.Add(tableSN);
            doc.LastSection.Add(tableBankiKontoBankowe);

            //def table Pozycje-Faktury(PF)
            Table table = new Table();

            table.Borders.Width = 0.5;

            //def column Lp
            Column column = table.AddColumn(Unit.FromCentimeter(1));


            //def colum NazwaTowaruLubUsługi
            _ = table.AddColumn(Unit.FromCentimeter(6));
            // def column Ilość
            _ = table.AddColumn(Unit.FromCentimeter(1));
            // def column Jednostka
            _ = table.AddColumn(Unit.FromCentimeter(1.5));
            // def column Wartość jednostkowa brutto
            _ = table.AddColumn(Unit.FromCentimeter(4));
            // def column Wartość brutto
            _ = table.AddColumn(Unit.FromCentimeter(3));

            //def header of table
            Row row = table.AddRow();

            Cell cell0 = row.Cells[0];

            cell0.AddParagraph("Lp.");
            cell0.Format.Font.Bold = true;
            cell0.Format.Alignment = ParagraphAlignment.Center;

            Cell cell1 = row.Cells[1];

            cell1.AddParagraph("Nazwa towaru lub usługi");
            cell1.Format.Font.Bold = true;
            cell1.Format.Alignment = ParagraphAlignment.Center;

            Cell cell2 = row.Cells[2];

            cell2.AddParagraph("Ilość");
            cell2.Format.Font.Bold = true;
            cell2.Format.Alignment = ParagraphAlignment.Center;

            Cell cell3 = row.Cells[3];

            cell3.AddParagraph("Jedn.");
            cell3.Format.Font.Bold = true;
            cell3.Format.Alignment = ParagraphAlignment.Center;

            Cell cell4 = row.Cells[4];

            cell4.AddParagraph("Wartość jednostkowa brutto PLN");
            cell4.Format.Font.Bold = true;
            cell4.Format.Alignment = ParagraphAlignment.Center;

            Cell cell5 = row.Cells[5];

            cell5.AddParagraph("Wartość brutto \n PLN");
            cell5.Format.Font.Bold = true;
            cell5.Format.Alignment = ParagraphAlignment.Center;

            Row  row2     = table.AddRow();
            Cell cellR2C0 = row2.Cells[0];

            cellR2C0.AddParagraph("1");
            cellR2C0.Format.Alignment = ParagraphAlignment.Center;

            Cell cellR2C1 = row2.Cells[1];

            cellR2C1.AddParagraph("Abonament xBiuro - pakiet STANDARD na 12-MIESIĘCY");
            cellR2C1.Format.Alignment = ParagraphAlignment.Center;

            Cell cellR2C2 = row2.Cells[2];

            cellR2C2.AddParagraph("1");
            cellR2C2.Format.Alignment = ParagraphAlignment.Center;

            Cell cellR2C3 = row2.Cells[3];

            cellR2C3.AddParagraph("usługa");
            cellR2C3.Format.Alignment = ParagraphAlignment.Center;

            Cell cellR2C4 = row2.Cells[4];

            cellR2C4.AddParagraph("723,24");
            cellR2C4.Format.Alignment = ParagraphAlignment.Center;

            Cell cellR2C5 = row2.Cells[5];

            cellR2C5.AddParagraph("723,24");
            cellR2C5.Format.Alignment = ParagraphAlignment.Center;



            //foreach (var elem in books)
            //{
            //    row = table.AddRow();

            //    cell = row.Cells[0];
            //    cell.AddParagraph(elem.author);

            //    cell = row.Cells[1];
            //    cell.AddParagraph(elem.title);

            //    cell = row.Cells[2];
            //    cell.AddParagraph(elem.year.ToString());

            //}

            //add table to document
            doc.LastSection.Add(table);

            Paragraph slownie = sec.AddParagraph();

            slownie.Format.Font.Bold = true;
            slownie.AddText("\n SŁOWNIE: SIEDEMSET DWADZIEŚCIA TRZY ZŁOTE I 24/100 GROSZY BRUTTO");

            //def tablePODSUMOWANIE Razem, Zapłacono, Pozostało do zapłaty
            Table tablePodsumowanie = new Table();

            tablePodsumowanie.Borders.Width = 0.5;
            Column columnPodsumowanie1 = tablePodsumowanie.AddColumn(Unit.FromCentimeter(8.25));

            columnPodsumowanie1.Format.Alignment = ParagraphAlignment.Right;
            Column columnPodsumowanie2 = tablePodsumowanie.AddColumn(Unit.FromCentimeter(8.25));

            columnPodsumowanie2.Format.Alignment = ParagraphAlignment.Center;
            Row  rowPodsumowanie1  = tablePodsumowanie.AddRow();
            Cell cellPodsumowanie1 = rowPodsumowanie1.Cells[0];

            cellPodsumowanie1 = rowPodsumowanie1.Cells[0];
            cellPodsumowanie1.AddParagraph("Razem");
            cellPodsumowanie1.Format.Font.Bold = true;
            cellPodsumowanie1 = rowPodsumowanie1.Cells[1];
            cellPodsumowanie1.AddParagraph("723,24 PLN");
            cellPodsumowanie1.Format.Font.Bold = false;

            Row  rowPodsumowanie2  = tablePodsumowanie.AddRow();
            Cell cellPodsumowanie2 = rowPodsumowanie2.Cells[0];

            cellPodsumowanie2 = rowPodsumowanie2.Cells[0];
            cellPodsumowanie2.AddParagraph("Zapłacono");
            // rowKontoBankowe.Format.Alignment = ParagraphAlignment.Right;
            cellPodsumowanie2.Format.Font.Bold = true;

            cellPodsumowanie2 = rowPodsumowanie2.Cells[1];
            cellPodsumowanie2.AddParagraph("0,00 PLN");
            cellPodsumowanie2.Format.Font.Bold = false;

            Row  rowPodsumowanie3  = tablePodsumowanie.AddRow();
            Cell cellPodsumowanie3 = rowPodsumowanie3.Cells[0];

            cellPodsumowanie3 = rowPodsumowanie3.Cells[0];
            cellPodsumowanie3.AddParagraph("Pozostało do zaplaty");
            // rowKontoBankowe.Format.Alignment = ParagraphAlignment.Right;
            cellPodsumowanie3.Format.Font.Bold = true;

            cellPodsumowanie3 = rowPodsumowanie3.Cells[1];
            cellPodsumowanie3.AddParagraph("723,24 PLN");
            cellPodsumowanie3.Format.Font.Bold = false;

            doc.LastSection.Add(tablePodsumowanie);

            Paragraph uwagi = sec.AddParagraph();

            uwagi.Format.Font.Bold = false;
            uwagi.AddText("UWAGI: Zwolnienie podmiotowe z VAT wg. art. 113 ust. 1 Ustawy o VAT. W przypadku braku opłacenia faktury w terminie świadczenie usługi zostanie automatycznie wstrzymane. \n \n \n");


            //def table bank i konto bankowe
            Table tablePodpisy = new Table();

            tablePodpisy.Borders.Width = 0.0;
            Column columnPodpisy1 = tablePodpisy.AddColumn(Unit.FromCentimeter(8.25));

            columnPodpisy1.Format.Alignment = ParagraphAlignment.Center;
            Column columnPodpisy2 = tablePodpisy.AddColumn(Unit.FromCentimeter(8.25));

            columnPodpisy2.Format.Alignment = ParagraphAlignment.Center;
            Row  rowPodpisy  = tablePodpisy.AddRow();
            Cell cellPodpisy = rowPodpisy.Cells[0];

            cellPodpisy = rowPodpisy.Cells[0];
            cellPodpisy.AddParagraph("Faktura bez podpisu odbiorcy faktury ");
            cellPodpisy = rowPodpisy.Cells[1];
            cellPodpisy.AddParagraph("Osoba upoważniona do wystawienia faktury ");


            Row  rowPodpisy2  = tablePodpisy.AddRow();
            Cell cellPodpisy2 = rowPodpisy2.Cells[0];

            cellPodpisy2 = rowPodpisy.Cells[0];
            cellPodpisy2.AddParagraph(" ");

            cellPodpisy2 = rowPodpisy.Cells[1];
            cellPodpisy2.AddParagraph("\n \n Tomasz Chajduga");

            doc.LastSection.Add(tablePodpisy);


            // Create a renderer and prepare (=layout) the document
            MigraDoc.Rendering.DocumentRenderer docRenderer = new MigraDoc.Rendering.DocumentRenderer(doc);
            docRenderer.PrepareDocument();
            gfx.MUH = PdfFontEncoding.Unicode;

            docRenderer.RenderPage(gfx, 1);


            const string filename = "HelloWorld4.pdf"; //When drawing is done, write the file

            document.Save(filename);                   // Save the document...

            //Process.Start(filename); // ...and start a viewer.
        }