Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            using (var doc = new PdfDocument())
            {
                var page = doc.AddPage();
                using (var graphic = XGraphics.FromPdfPage(page, XGraphicsUnit.Millimeter))
                {
                    graphic.DrawString("Test Invoice", new XFont("Arial", 20.0), XBrushes.Black, 20.0, 150.0);
                }
                using (var canvas = new PdfSharpCanvas(page, "Arial"))
                {
                    QRBill.Draw(Bill, canvas);
                }
                doc.Save("Output.pdf");
            }

            File.WriteAllBytes("OutputOriginal.pdf", QRBill.Generate(Bill));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates two PDF documents with a QR bill.
        /// <para>
        /// The first document consist of static text and the QR bill. It is
        /// entirely created by this program.
        /// </para>
        /// <para>
        /// The second document mainly consist of content from a template. The content is copied,
        /// and the QR bill is added on the last page.
        /// </para>
        /// </summary>
        static void Main()
        {
            // create new PDF file with QR bill
            using (var doc = new PdfDocument())
            {
                var page = doc.AddPage();
                page.Size = PageSize.A4;

                // static text on page
                using (var graphic = XGraphics.FromPdfPage(page, XGraphicsUnit.Millimeter))
                {
                    graphic.DrawString("Test Invoice", new XFont("Arial", 20.0), XBrushes.Black, 20.0, 150.0);
                }

                // add QR bill
                using (var canvas = new PdfSharpCanvas(page, "Arial"))
                {
                    QRBill.Draw(Bill, canvas);
                }

                // save document
                doc.Save("Output1.pdf");
            }

            // append QR bill to existing PDF file (on last page)
            using (var templateDoc = PdfReader.Open(OpenInvoice("invoice.pdf"), PdfDocumentOpenMode.Import))
                using (var doc = new PdfDocument())
                {
                    // copy all pages
                    foreach (var page in templateDoc.Pages)
                    {
                        doc.AddPage(page);
                    }

                    var lastPage = doc.Pages[doc.Pages.Count - 1];
                    using (var canvas = new PdfSharpCanvas(lastPage, "Arial"))
                    {
                        QRBill.Draw(Bill, canvas);
                    }

                    doc.Save("Output2.pdf");
                }
        }