public static MigraDoc.DocumentObjectModel.Document CreateDocument(string input)
        {
            MigraDoc.DocumentObjectModel.Document document = new MigraDoc.DocumentObjectModel.Document();
            document.DefaultPageSetup.Orientation    = MigraDoc.DocumentObjectModel.Orientation.Portrait;
            document.DefaultPageSetup.HeaderDistance = 1;
            Section section = document.AddSection();

            section.PageSetup.TopMargin    = 90;
            section.PageSetup.BottomMargin = 20;
            section.PageSetup.RightMargin  = 5;
            section.PageSetup.LeftMargin   = 50;
            Paragraph header = section.Headers.Primary.AddParagraph();

            MigraDoc.DocumentObjectModel.Shapes.Image img = new MigraDoc.DocumentObjectModel.Shapes.Image();
            header.AddImage(@"\\192.168.201.6\Telex\white.png");
            Paragraph paragraph = section.AddParagraph();

            MigraDoc.DocumentObjectModel.Shapes.Image img2 = new MigraDoc.DocumentObjectModel.Shapes.Image();
            header.AddImage(@"\\192.168.201.6\Telex\logo.png");
            Paragraph paragraph2 = section.AddParagraph();

            paragraph.Format.Font.Color = MigraDoc.DocumentObjectModel.Color.FromCmyk(0, 0, 0, 100);
            paragraph.Format.Font.Name  = "Courier New";
            paragraph.Format.Font.Size  = 9;
            paragraph.AddText(input.Replace(" ", " "));
            return(document);
        }//--------------------------------------
        void Run()
        {
            if (File.Exists(outputName))
            {
                File.Delete(outputName);
            }

            var doc = new Document();
            doc.DefaultPageSetup.Orientation = Orientation.Portrait;
            doc.DefaultPageSetup.PageFormat = PageFormat.A4;
            //doc.DefaultPageSetup.LeftMargin = Unit.FromMillimeter(5.0);
            //doc.DefaultPageSetup.RightMargin = Unit.FromMillimeter(5.0);
            //doc.DefaultPageSetup.BottomMargin = Unit.FromMillimeter(5.0);
            //doc.DefaultPageSetup.TopMargin = Unit.FromMillimeter(5.0);
            StyleDoc(doc);
            var section = doc.AddSection();
            var footer = new TextFrame();

            section.Footers.Primary.Add(footer);
            var html = File.ReadAllText("example.html");
            section.AddHtml(html);

            var renderer = new PdfDocumentRenderer();
            renderer.Document = doc;
            renderer.RenderDocument();

            renderer.Save(outputName);
            Process.Start(outputName);
        }
    /// <summary>
    /// Defines page setup, headers, and footers.
    /// </summary>
    static void DefineContentSection(Document document, Project currentProject)
    {
    	try {
    	  Section section = document.AddSection();
	      section.PageSetup.OddAndEvenPagesHeaderFooter = true;
	      section.PageSetup.StartingNumber = 1;
	
	      HeaderFooter header = section.Headers.Primary;
	      header.AddParagraph(currentProject.Name);
	      
	      header = section.Headers.EvenPage;
	      header.AddParagraph(currentProject.Name);
	
	      // Create a paragraph with centered page number. See definition of style "Footer".
	      Paragraph paragraph = new Paragraph();
	      paragraph.AddTab();
	      paragraph.AddPageField();
	
	      // Add paragraph to footer for odd pages.
	      section.Footers.Primary.Add(paragraph);
	      // Add clone of paragraph to footer for odd pages. Cloning is necessary because an object must
	      // not belong to more than one other object. If you forget cloning an exception is thrown.
	      section.Footers.EvenPage.Add(paragraph.Clone());
    	} catch (Exception ex) {
    		throw ex;
    	}
     
    }
        private void SetDocument(ref Document document, Order order)
        {
            var tableColor = new Color(0, 0, 0, 0);
            Section section = document.AddSection();

            //HEADER
            SetHeader(ref section);

            //FOOTER
            SetFooter(ref section);

            //INFO
            SetInfo(order, ref section);

            //TABLE STYLE
            Table table = SetTableStyle(ref section, tableColor);

            //HEADERS
            SetTableHeader(ref table, tableColor);

            //ITEMS
            SetTableData(order, ref table);

            //SUMMARY
            SetTableSummary(order, ref table);
        }
Exemple #5
0
    /// <summary>
    /// Defines the cover page.
    /// </summary>
    public static void DefineCover(Document document, Project currentProject)
    {
    	try {
    		Section section = document.AddSection();

		    Paragraph paragraph = section.AddParagraph();
		    paragraph.Format.SpaceAfter = "3cm";
				    
		    Image image = section.AddImage(System.IO.Path.GetDirectoryName( System.Reflection.Assembly.GetExecutingAssembly().Location)+@"\\logo.jpg");
		    image.Width = "6cm";
		
		    paragraph = section.AddParagraph("Report generated using Cameratrap Manager\nfor the project:\n"+currentProject.Name);
		    paragraph.Format.Font.Size = 16;
		    paragraph.Format.Font.Color = Colors.DarkRed;
		    paragraph.Format.SpaceBefore = "6cm";
		    paragraph.Format.SpaceAfter = "3cm";
		
		    paragraph=section.AddParagraph("Creation date: " + currentProject.StartDate.ToString());
		    paragraph=section.AddParagraph("Last modified: " + currentProject.CompletionDate.ToString());
		      
		    paragraph = section.AddParagraph("Rendering date: ");
		    paragraph.AddDateField();
    	} catch (Exception ex) {
    		throw ex;
    	}
    	
     
    }
        /// <summary>
        /// Tests alignments.
        /// </summary>
        public static void Alignment(string pdfOutputFile)
        {
            Document document = new Document();
            Section section = document.AddSection();
            section.PageSetup.LeftMargin = 0;
            section.PageSetup.RightMargin = 0;
            Paragraph par = section.AddParagraph();
            //      FillFormattedParagraph(par);
            //      par.Format.Alignment = ParagraphAlignment.Left;

            //      par = section.AddParagraph();
            //      FillFormattedParagraph(par);
            //      par.Format.Alignment = ParagraphAlignment.Right;

            //      par = section.AddParagraph();
            FillFormattedParagraph(par);
            par.Format.Alignment = ParagraphAlignment.Center;
            //
            //      par = section.AddParagraph();
            //      FillFormattedParagraph(par);
            //      par.Format.Alignment = ParagraphAlignment.Justify;

            par.Format.FirstLineIndent = "-2cm";
            par.Format.LeftIndent = "2cm";
            par.Format.RightIndent = "3cm";
            PdfDocumentRenderer renderer = new PdfDocumentRenderer();
            renderer.Document = document;
            renderer.RenderDocument();
            renderer.PdfDocument.Save(pdfOutputFile);
        }
        public Boolean Convert(String inputFileName, String outputFileName)
        {
            try
            {
                var text = File.ReadAllText(inputFileName);

                // Create a MigraDoc document
                Document document = new Document();
                var section = document.AddSection();
                var paragraph = section.AddParagraph();
                paragraph.Format.Font.Size = 12;
                paragraph.AddFormattedText(text);


                PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(unicode, embedding);
                pdfRenderer.Document = document;
                pdfRenderer.RenderDocument();
                pdfRenderer.PdfDocument.Save(outputFileName);
                return true;
            }
            catch (Exception ex)
            {
                Logger.WarnFormat(ex, "Error converting file {0} to Pdf.", inputFileName);
                return false;
            }
        }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="doc"></param>
        public ReportTools(Document doc)
        {
            document = doc;
            DefineStyles(document);

            section = document.AddSection();
        }
    /// <summary>
    /// Creates the initial sample document.
    /// </summary>
    public static Document CreateSample1()
    {
      // Create a new MigraDoc document
      Document document = new Document();

      // Add a section to the document
      Section section = document.AddSection();

      // Add a paragraph to the section
      Paragraph paragraph = section.AddParagraph();

      // Add some text to the paragraph
      paragraph.AddFormattedText("Hi!");

      paragraph = section.AddParagraph();
      paragraph.AddText("This is a MigraDoc document created for the DocumentViewer sample application.");
      paragraph.AddText("The DocumentViewer demonstrates all techniques you need to preview and print a MigraDoc document, and convert it to a PDF, RTF, or image file.");

      section.AddParagraph();
      section.AddParagraph();
      paragraph = section.AddParagraph("A4 portrait");
      paragraph.Format.Font.Size = "1.5cm";

      section.AddPageBreak();
      section.AddParagraph().AddText("Page 2");

      section = document.AddSection();
      section.PageSetup.Orientation = Orientation.Landscape;

      paragraph = section.AddParagraph("A4 landscape");
      paragraph.Format.Font.Size = "1.5cm";

      section.AddPageBreak();
      section.AddParagraph().AddText("Page 4");

      section = document.AddSection();
      section.PageSetup.Orientation = Orientation.Portrait;
      section.PageSetup.PageFormat = PageFormat.A5;

      paragraph = section.AddParagraph("A5 portrait");
      paragraph.Format.Font.Size = "1.5cm";

      section.AddPageBreak();
      section.AddParagraph().AddText("Page 6");

      return document;
    }
Exemple #10
0
        private MigraDoc.DocumentObjectModel.Document CreatePrintDocument(PrintDocument pd)
        {
            string text;

            MigraDoc.DocumentObjectModel.Document doc = new MigraDoc.DocumentObjectModel.Document();
            doc.DefaultPageSetup.PageWidth    = Unit.FromInch((double)pd.DefaultPageSettings.PaperSize.Width / 100);
            doc.DefaultPageSetup.PageHeight   = Unit.FromInch((double)pd.DefaultPageSettings.PaperSize.Height / 100);
            doc.DefaultPageSetup.TopMargin    = Unit.FromInch((double)pd.DefaultPageSettings.Margins.Top / 100);
            doc.DefaultPageSetup.LeftMargin   = Unit.FromInch((double)pd.DefaultPageSettings.Margins.Left / 100);
            doc.DefaultPageSetup.RightMargin  = Unit.FromInch((double)pd.DefaultPageSettings.Margins.Right / 100);
            doc.DefaultPageSetup.BottomMargin = Unit.FromInch((double)pd.DefaultPageSettings.Margins.Bottom / 100);
            MigraDoc.DocumentObjectModel.Section section = doc.AddSection();
            section.PageSetup.StartingNumber = 1;
            MigraDoc.DocumentObjectModel.Font headingFont = MigraDocHelper.CreateFont(13, true);
            MigraDoc.DocumentObjectModel.Font bodyFontx   = MigraDocHelper.CreateFont(9, false);
            MigraDoc.DocumentObjectModel.Font nameFontx   = MigraDocHelper.CreateFont(9, true);
            MigraDoc.DocumentObjectModel.Font totalFontx  = MigraDocHelper.CreateFont(9, true);
            Paragraph pageNumParag = new Paragraph();

            pageNumParag.AddText(Lan.g(this, "Page") + " ");
            pageNumParag.AddPageField();
            pageNumParag.AddText(" " + Lan.g(this, "of") + " ");
            pageNumParag.AddNumPagesField();
            section.Footers.Primary.Add(pageNumParag);
            Paragraph       par       = section.AddParagraph();
            ParagraphFormat parformat = new ParagraphFormat();

            parformat.Alignment = ParagraphAlignment.Center;
            parformat.Font      = MigraDocHelper.CreateFont(14, true);
            par.Format          = parformat;
            //Render the reconcile grid.
            par = section.AddParagraph();
            par.Format.Alignment = ParagraphAlignment.Center;
            par.AddFormattedText(Lan.g(this, "RECONCILE"), totalFontx);
            par.AddLineBreak();
            text = Accounts.GetAccount(ReconcileCur.AccountNum).Description.ToUpper();
            par.AddFormattedText(text, totalFontx);
            par.AddLineBreak();
            text = PrefC.GetString(PrefName.PracticeTitle);
            par.AddText(text);
            par.AddLineBreak();
            text = PrefC.GetString(PrefName.PracticePhone);
            if (text.Length == 10 && Application.CurrentCulture.Name == "en-US")
            {
                text = "(" + text.Substring(0, 3) + ")" + text.Substring(3, 3) + "-" + text.Substring(6);
            }
            par.AddText(text);
            par.AddLineBreak();
            par.AddText(MiscData.GetNowDateTime().ToShortDateString());
            par.AddLineBreak();
            par.AddText(Lan.g(this, "Reconcile Date") + ": " + PIn.Date(textDate.Text).ToShortDateString());
            par.AddLineBreak();
            par.AddText(labelStart.Text + ": " + PIn.Double(textStart.Text).ToString("n"));
            par.AddLineBreak();
            par.AddText(labelEnd.Text + ": " + PIn.Double(textEnd.Text).ToString("n"));
            MigraDocHelper.InsertSpacer(section, 10);
            MigraDocHelper.DrawGrid(section, gridMain);
            return(doc);
        }
Exemple #11
0
 /// <summary>
 /// Create a pdf file of a single recipe
 /// </summary>
 /// <param name="recipe">Recipe Entry</param>
 /// <param name="filename">string of save location</param>
 /// <param name="preview">bool</param>
 public static void SingleRecipePDF(RecipeEntry recipe, string filename, bool preview)
 {
     Document file = new Document();
     file.Info.Title = recipe.Name;
     Section section = file.AddSection();
     DrawRecipe(recipe, ref section);
     SavePDF(file, filename, preview);
 }
Exemple #12
0
        public void VisitParagraph(Paragraph element)
        {
            if (_pdfSection == null)
            {
                _pdfSection = _document.AddSection();
            }

            _pdfParagraph = _pdfCell?.AddParagraph() ?? _pdfSection.AddParagraph();
            SetParagraphProperties(element.ParagraphProperties);
        }
Exemple #13
0
    protected void InitDocument()
    {
      Document = new Document();

      CurrentSection = Document.AddSection();
      CurrentSection.PageSetup.PageFormat = PageFormat.A4;
      CurrentSection.PageSetup.TopMargin = Unit.FromMillimeter(10);
      CurrentSection.PageSetup.LeftMargin = Unit.FromMillimeter(10);
      CurrentSection.PageSetup.RightMargin = Unit.FromMillimeter(10);
      CurrentSection.PageSetup.BottomMargin = Unit.FromMillimeter(10);
    }
 /// <summary>
 /// Tests AddFormattedText.
 /// </summary>
 public static void Formatted(string pdfOutputFile)
 {
     Document document = new Document();
     Section section = document.AddSection();
     Paragraph par = section.AddParagraph();
     FillFormattedParagraph(par);
     PdfDocumentRenderer printer = new PdfDocumentRenderer();
     printer.Document = document;
     printer.RenderDocument();
     printer.PdfDocument.Save(pdfOutputFile);
 }
 public PDFDocumentBuilder()
 {
     document = new Document();
     const bool unicode = true;
     pdfRenderer = new PdfDocumentRenderer(unicode);
     document.Info.Title = "Search results";
     document.Info.Author = "Zajęcia projektowe z TO grupa 9:30 Wtorek";
     DefineStyles(document);
     pdfRenderer.Document = document;
     section = document.AddSection();
 }
        Document CreateDocument()
        {
            // Create a new MigraDoc document
            Document document = new Document();

            // Add a section to the document
            Section section = document.AddSection();

            // Add a paragraph to the section
            Paragraph paragraph = section.AddParagraph();

            // Add some text to the paragraph
            paragraph.AddImage(Application.StartupPath + "\\images\\logo.png");
            paragraph.AddFormattedText("Braze number: " + textBox1.Text + "\n", TextFormat.Bold);
            paragraph.AddFormattedText("Date: " + textBox2.Text + "\n", TextFormat.NotBold);
            paragraph.AddFormattedText("Duration: " + textBox3.Text + "\n", TextFormat.NotBold);
            paragraph.AddFormattedText("Status: " + textBox5.Text + "\n\n", TextFormat.NotBold);
            paragraph.AddFormattedText("Log: " +"\n", TextFormat.Bold);
            int loCount = 0;
            for (int i = 0; i < listView1.Items.Count; i++)
            {
                if (listView1.Items[i].Text.Contains("The large Nitrogen valve is opened."))
                {
                    if (loCount < 2)
                    {
                        paragraph.AddFormattedText(listView1.Items[i].Text + "\n", TextFormat.NotBold);
                    }
                    loCount++;
                    if (loCount == 2)
                    {
                        paragraph.AddFormattedText("...\n", TextFormat.NotBold);
                    }
                }
                else if (listView1.Items[i].Text.Contains("The large Nitrogen valve is closed."))
                {
                    if (loCount < 2)
                    {
                        paragraph.AddFormattedText(listView1.Items[i].Text + "\n", TextFormat.NotBold);
                    }

                }
                else
                {
                    paragraph.AddFormattedText(listView1.Items[i].Text + "\n", TextFormat.NotBold);
                }
            }
            //paragraph.AddImage("../../SomeImage.png");
            //paragraph.AddImage("../../Logo.pdf");
            //section.AddImage("../../Logo.pdf");
            section.AddImage(Application.StartupPath + "\\temp\\testa.png");
            section.AddImage(Application.StartupPath + "\\temp\\testb.png");

            return document;
        }
Exemple #17
0
        private static Document CreateHelloWorld()
        {
            var doc = new Document();
            var section = doc.AddSection();
            var p = section.AddParagraph("Hello World");
            p = section.AddParagraph();
            p.AddImage(System.IO.Path.Combine(Environment.CurrentDirectory, "Diagram.png"));

            DefineCharts(doc);

            return doc;
        }
        public static void Borders(string outputFile)
        {
            Document document = new Document();
              Section section = document.AddSection();
              Paragraph par = section.AddParagraph();
              FillFormattedParagraph(par);
              GiveBorders(par);

              PdfPrinter printer = new PdfPrinter();
              printer.Document = document;
              printer.PrintDocument();
              printer.PdfDocument.Save(outputFile);
        }
Exemple #19
0
 /// <summary>
 /// Create a pdf file of all recipes
 /// </summary>
 /// <param name="recipes">List of Recipe Entries</param>
 /// <param name="filename">string of save location</param>
 /// <param name="preview">bool</param>
 public static void AllRecipesPDF(List<RecipeEntry> recipes, string filename, bool preview)
 {
     Document file = new Document();
     file.Info.Title = "Recipe Book";
     //Categories come in to play here.
     //I can create lists of recipes by category using LINQ
     //Then for each category create a new header section.
     foreach (RecipeEntry recipe in recipes)
     {
         Section section = file.AddSection();
         DrawRecipe(recipe, ref section);
     }
     SavePDF(file, filename, preview);
 }
Exemple #20
0
 static void Main(string[] args)
 {
     using (var stream = new MemoryStream())
     {
         // Generate RTF (using MigraDoc)
         var migraDoc  = new MigraDoc.DocumentObjectModel.Document();
         var section   = migraDoc.AddSection();
         var paragraph = section.AddParagraph();
         paragraph.AddFormattedText("Hello World!", TextFormat.Bold);
         var rtfDocumentRenderer = new RtfDocumentRenderer();
         rtfDocumentRenderer.Render(migraDoc, stream, false, null);
         // Convert RTF to DOCX (using Spire.Doc)
         var spireDoc = new Spire.Doc.Document();
         spireDoc.LoadFromStream(stream, FileFormat.Auto);
         spireDoc.SaveToFile("D:\\example.docx", FileFormat.Docx);
     }
 }
        private void PrintReceipt(string receiptStr)
        {
            string[] receiptLines = receiptStr.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
            MigraDoc.DocumentObjectModel.Document doc = new MigraDoc.DocumentObjectModel.Document();
            doc.DefaultPageSetup.PageWidth   = Unit.FromInch(3.0);
            doc.DefaultPageSetup.PageHeight  = Unit.FromInch(0.181 * receiptLines.Length + 0.56);     //enough to print receipt text plus 9/16 inch (0.56) extra space at bottom.
            doc.DefaultPageSetup.TopMargin   = Unit.FromInch(0.25);
            doc.DefaultPageSetup.LeftMargin  = Unit.FromInch(0.25);
            doc.DefaultPageSetup.RightMargin = Unit.FromInch(0.25);
            MigraDoc.DocumentObjectModel.Font bodyFontx = MigraDocHelper.CreateFont(8, false);
            bodyFontx.Name = FontFamily.GenericMonospace.Name;
            MigraDoc.DocumentObjectModel.Section section = doc.AddSection();
            Paragraph       par       = section.AddParagraph();
            ParagraphFormat parformat = new ParagraphFormat();

            parformat.Alignment = ParagraphAlignment.Left;
            parformat.Font      = bodyFontx;
            par.Format          = parformat;
            par.AddFormattedText(receiptStr, bodyFontx);
            MigraDoc.Rendering.Printing.MigraDocPrintDocument printdoc = new MigraDoc.Rendering.Printing.MigraDocPrintDocument();
            MigraDoc.Rendering.DocumentRenderer renderer = new MigraDoc.Rendering.DocumentRenderer(doc);
            renderer.PrepareDocument();
            printdoc.Renderer = renderer;
#if DEBUG
            FormRpPrintPreview pView = new FormRpPrintPreview(printdoc);
            pView.ShowDialog();
#else
            try {
                ODprintout printout = PrinterL.CreateODprintout(
                    printSit: PrintSituation.Receipt,
                    auditPatNum: _patCur.PatNum,
                    auditDescription: Lans.g(this, "PayConnect receipt printed")
                    );
                if (PrinterL.TrySetPrinter(printout))
                {
                    printdoc.PrinterSettings = printout.PrintDoc.PrinterSettings;
                    printdoc.Print();
                }
            }
            catch (Exception ex) {
                MessageBox.Show(Lan.g(this, "Printer not available.") + "\r\n" + Lan.g(this, "Original error") + ": " + ex.Message);
            }
#endif
        }
Exemple #22
0
    /// <summary>
    /// Defines the cover page.
    /// </summary>
    public static void DefineCover(Document document)
    {
      Section section = document.AddSection();

      Paragraph paragraph = section.AddParagraph();
      paragraph.Format.SpaceAfter = "3cm";

      Image image = section.AddImage("../../images/Logo landscape.png");
      image.Width = "10cm";

      paragraph = section.AddParagraph("A sample document that demonstrates the\ncapabilities of MigraDoc");
      paragraph.Format.Font.Size = 16;
      paragraph.Format.Font.Color = Colors.DarkRed;
      paragraph.Format.SpaceBefore = "8cm";
      paragraph.Format.SpaceAfter = "3cm";

      paragraph = section.AddParagraph("Rendering date: ");
      paragraph.AddDateField();
    }
Exemple #23
0
        /// <summary>
        /// Creates an absolutely minimalistic document.
        /// </summary>
        static Document CreateDocument()
        {
            // Create a new MigraDoc document
              Document document = new Document();

              // Add a section to the document
              Section section = document.AddSection();

              // Add a paragraph to the section
              Paragraph paragraph = section.AddParagraph();

              paragraph.Format.Font.Color = Color.FromCmyk(100, 30, 20, 50);

              // Add some text to the paragraph
              //paragraph.AddFormattedText("Hello, World!  öäüÖÄÜß~§≤≥≈≠", TextFormat.Italic);
              paragraph.AddFormattedText("Hello, World!", TextFormat.Bold);

              return document;
        }
        /// <summary>
        /// Returns a memory stream that represents this invoice in pdf form
        /// Based on code from http://www.pdfsharp.net/wiki/Default.aspx?Page=Invoice-sample&NS=&AspxAutoDetectCookieSupport=1 as well as associated methods
        /// </summary>
        /// <returns>A memory stream containing a pdf</returns>
        public MemoryStream ToPdf()
        {
            // Create a new MigraDoc document
            var document = new Document();
            // Each MigraDoc document needs at least one section.
            // main content
            Section section = document.AddSection();
            document.Info.Title = "Invoice #"+id;

            // we have to put it in a file first because this thing only works on file paths
            var fileName = Path.GetTempFileName();
            SettingsData.Default.InvoiceLogo.Save(fileName);

            DefineStyles(document);
            CreateSectionIntro(section, fileName);
            AddAddressFrame(section);
            AddDateFields(section);
            var table = CreateTableWithHeader(section);
            PopulateTable(table);

            if (SettingsData.Default.NoteAfterInvoiceItemList != null)
            {
                // Add the notes paragraph
                var paragraph = document.LastSection.AddParagraph();
                paragraph.Format.SpaceBefore = "1cm";
                paragraph.Format.Borders.Width = 0.75;
                paragraph.Format.Borders.Distance = 3;
                paragraph.Format.Borders.Color = Colors.Black;
                paragraph.Format.Shading.Color = Colors.LightGray;
                paragraph.AddText(SettingsData.Default.NoteAfterInvoiceItemList);
            }

            var renderer = new PdfDocumentRenderer(true) {Document = document};
            renderer.PrepareRenderPages();
            renderer.RenderDocument();
            var pdf = renderer.PdfDocument;
            File.Delete(fileName);

            var ms = new MemoryStream();
            pdf.Save(ms, false);
            ms.Seek(0, SeekOrigin.Begin); // reset the stream to the beginning
            return ms;
        }
 /// <summary>
 /// Tests texts and blanks.
 /// </summary>
 public static void TextAndBlanks(string pdfOutputFile)
 {
     Document document = new Document();
     Section section = document.AddSection();
     Paragraph par = section.AddParagraph("Dies");
     for (int idx = 0; idx <= 40; ++idx)
     {
         par.AddCharacter(SymbolName.Blank);
         par.AddText(idx.ToString());
         par.AddCharacter(SymbolName.Blank);
         par.AddText((idx + 1).ToString());
         par.AddCharacter(SymbolName.Blank);
         par.AddText((idx + 2).ToString());
     }
     PdfDocumentRenderer renderer = new PdfDocumentRenderer();
     renderer.Document = document;
     renderer.RenderDocument();
     renderer.PdfDocument.Save(pdfOutputFile);
 }
        public void CanGeneratePrettyReport()
        {
            var data = GetTestData();

            var atlanticData = GetDivision("Atlantic", data);
            var centralData = GetDivision("Central", data);

            var doc = new Document();
            var section = doc.AddSection();

            var title = section.AddParagraph("Standings");
            title.Format.Font.Size = Unit.FromPoint(16);
            title.Format.Font.Underline = Underline.Single;
            title.Format.Alignment = ParagraphAlignment.Center;
            title.Format.SpaceAfter = Unit.FromPoint(12);

            var atlanticHeading = section.AddParagraph("Atlantic Division");
            atlanticHeading.Format.Font.Bold = true;
            atlanticHeading.Format.Borders.Bottom.Color = Colors.Black;
            atlanticHeading.Format.Borders.Bottom.Width = Unit.FromPoint(1);
            section.AddParagraph();

            var atlanticTable = AddDivisionTableTo(section, "Atlantic");
            section.AddParagraph();

            var centralHeading = section.AddParagraph("Cental Division");
            centralHeading.Format.Font.Bold = true;
            centralHeading.Format.Borders.Bottom.Color = Colors.Black;
            centralHeading.Format.Borders.Bottom.Width = Unit.FromPoint(1);
            section.AddParagraph();

            var centralTable = AddDivisionTableTo(section, "Central");

            PopulateDivisionTable(atlanticTable, atlanticData);
            PopulateDivisionTable(centralTable, centralData);

            var pdfRenderer = new PdfDocumentRenderer();
            pdfRenderer.Document = doc;
            pdfRenderer.RenderDocument();

            pdfRenderer.Save(@"standings.pdf");
        }
        private MigraDoc.DocumentObjectModel.Document CreatePrintDocument()
        {
            string text;

            MigraDoc.DocumentObjectModel.Document doc = new MigraDoc.DocumentObjectModel.Document();
            doc.DefaultPageSetup.PageWidth   = Unit.FromInch(8.5);
            doc.DefaultPageSetup.PageHeight  = Unit.FromInch(11);
            doc.DefaultPageSetup.TopMargin   = Unit.FromInch(.5);
            doc.DefaultPageSetup.LeftMargin  = Unit.FromInch(.5);
            doc.DefaultPageSetup.RightMargin = Unit.FromInch(.5);
            MigraDoc.DocumentObjectModel.Section section     = doc.AddSection();
            MigraDoc.DocumentObjectModel.Font    headingFont = MigraDocHelper.CreateFont(13, true);
            MigraDoc.DocumentObjectModel.Font    bodyFontx   = MigraDocHelper.CreateFont(9, false);
            MigraDoc.DocumentObjectModel.Font    nameFontx   = MigraDocHelper.CreateFont(9, true);
            MigraDoc.DocumentObjectModel.Font    totalFontx  = MigraDocHelper.CreateFont(9, true);
            Paragraph       par       = section.AddParagraph();
            ParagraphFormat parformat = new ParagraphFormat();

            parformat.Alignment = ParagraphAlignment.Center;
            parformat.Font      = MigraDocHelper.CreateFont(14, true);
            par.Format          = parformat;
            //Render the reconcile grid.
            par = section.AddParagraph();
            par.Format.Alignment = ParagraphAlignment.Center;
            par.AddFormattedText(Lan.g(this, "RECONCILE"), totalFontx);
            par.AddLineBreak();
            text = Accounts.GetAccount(ReconcileCur.AccountNum).Description.ToUpper();
            par.AddFormattedText(text, totalFontx);
            par.AddLineBreak();
            text = PrefC.GetString(PrefName.PracticeTitle);
            par.AddText(text);
            par.AddLineBreak();
            text = PrefC.GetString(PrefName.PracticePhone);
            if (text.Length == 10 && Application.CurrentCulture.Name == "en-US")
            {
                text = "(" + text.Substring(0, 3) + ")" + text.Substring(3, 3) + "-" + text.Substring(6);
            }
            par.AddText(text);
            MigraDocHelper.InsertSpacer(section, 10);
            MigraDocHelper.DrawGrid(section, gridMain);
            return(doc);
        }
Exemple #28
0
 public void setDocumentHeaders2(ref Document document, string footerText)
 {
     Section section = document.AddSection();
     section.PageSetup.OddAndEvenPagesHeaderFooter = true;
     //section.PageSetup.HeaderDistance = "1cm";
     document.DefaultPageSetup.HeaderDistance = "1cm";
     //document.DefaultPageSetup.TopMargin = "2.5cm";
     document.DefaultPageSetup.TopMargin = "1.5cm";
     section.PageSetup.StartingNumber = 1;
     HeaderFooter headerPrimaryPage = section.Headers.Primary;
     Table headerTable = headerPrimaryPage.AddTable();
     HeaderFooter headerEvenPage = section.Headers.EvenPage;
     Table headerTableEvenPage = headerEvenPage.AddTable();
     Paragraph footerParagraphfirstPage = section.Headers.Primary.AddParagraph();
     footerParagraphfirstPage.AddText(footerText);
     footerParagraphfirstPage.Style = StyleNames.Header;
     Paragraph footerParagraphEvenPage = section.Headers.EvenPage.AddParagraph();
     footerParagraphEvenPage.AddText(footerText);
     footerParagraphEvenPage.Style = StyleNames.Header;
 }
Exemple #29
0
        /// <summary>
        /// Creates an absolutely minimalistic document.
        /// </summary>
        static Document CreateDocument()
        {
            // Create a new MigraDoc document
              Document document = new Document();

              // Add a section to the document
              Section section = document.AddSection();

              // Add a paragraph to the section
              Paragraph paragraph = section.AddParagraph();

              // Add some text to the paragraph
              paragraph.AddFormattedText("Hello, World!", TextFormat.Italic);
              //paragraph.AddImage("../../SomeImage.png");
              //paragraph.AddImage("../../Logo.pdf");
              //section.AddImage("../../Logo.pdf");
              section.AddImage("../../SomeImage.png");

              return document;
        }
        /// <summary>
        /// Defines page setup, headers, and footers.
        /// </summary>
        private static void DefineContentSection(Document document, List<QueryData> data )
        {
            Section section = document.AddSection();
            //section.PageSetup.OddAndEvenPagesHeaderFooter = true;
            section.PageSetup.StartingNumber = 1;

            HeaderFooter header = section.Headers.Primary;
            header.AddParagraph(data[0].ProjectName + " - Отчет проверки данных от " + DateTime.Now.ToShortDateString() );
            header.Format.Alignment = ParagraphAlignment.Center;
            // Create a paragraph with centered page number. See definition of style "Footer".
            Paragraph paragraph = new Paragraph();
            paragraph.AddTab();
            paragraph.AddPageField();
            paragraph.AddText(" из ");
            paragraph.AddNumPagesField();
            // Add paragraph to footer for odd pages.
            section.Footers.Primary.Add(paragraph);
            // Add clone of paragraph to footer for odd pages. Cloning is necessary because an object must
            // not belong to more than one other object. If you forget cloning an exception is thrown.
            section.Footers.EvenPage.Add(paragraph.Clone());
        }
Exemple #31
0
        public static Document Generate(Booking booking)
        {
            Document document = new Document();
            document.Info.Title = "Confirmation Voucher";
            document.Info.Subject = booking.ReferenceId;
            document.Info.Author = booking.AssociationName;

            DefineStyles(document);

            Section section = document.AddSection();

            AddLogo(document, booking);
            AddTripSummary(document, booking);
            AddMeetingPoint(document, booking);
            AddPassengers(document, booking);
            section.AddParagraph();
            AddPayment(document, booking);
            AddBookedByInfo(document, booking);

            return document;
        }
Exemple #32
0
    public static void Test()
    {
      Document doc = new Document();
      Section sec = doc.AddSection();

      Chart chart = sec.AddChart(ChartType.Line);
      chart.Width = "13cm";
      chart.Height = "8cm";
      chart.FillFormat.Color = Color.Linen;
      chart.LineFormat.Width = 2;

      chart.PlotArea.FillFormat.Color = Color.Blue;

//      chart.XAxis.Title.Caption = "X-Axis";
//      chart.YAxis.Title.Caption = "Y-Axis";

      DocumentRenderer docRenderer = new DocumentRenderer();
      docRenderer.Render(doc, "RtfChart.txt");
      DdlWriter.SerializeToFile(doc, "RtfChart.mdddl");
      System.IO.File.Copy("RtfChart.txt", "RtfChart.rtf", true);
      System.Diagnostics.Process.Start("RtfChart.txt");
    }
        public void CanGeneratePdfTable()
        {
            var doc = new Document();
            var section = doc.AddSection();
            var table = section.AddTable();

            var column1 = table.AddColumn();
            var column2 = table.AddColumn();

            var row1 = table.AddRow();
            row1.Cells[0].AddParagraph("Ryan");
            row1.Cells[1].AddParagraph("30");

            var row2 = table.AddRow();
            row2.Cells[0].AddParagraph("Joe");
            row2.Cells[1].AddParagraph("99");

            var pdfRenderer = new PdfDocumentRenderer();
            pdfRenderer.Document = doc;
            pdfRenderer.RenderDocument();

            pdfRenderer.Save(@"pdfsharptest.pdf");
        }
Exemple #34
0
        public static Document Generate(BookingDispatching dispatch, Association association, AirportMeetingPoint meetingPoint)
        {
            BookingInfo bookingInfo = new BookingInfo(dispatch, association, meetingPoint);

            Document document = new Document();
            document.Info.Title = "Confirmation Voucher";
            document.Info.Subject = dispatch.Booking.ReferenceId;
            document.Info.Author = bookingInfo.AssociationName;

            DefineStyles(document);

            Section section = document.AddSection();

            AddLogo(document, bookingInfo);
            AddTripSummary(document, bookingInfo);
            AddMeetingPoint(document, bookingInfo);
            AddPassengers(document, bookingInfo);
            section.AddParagraph();
            AddPayment(document, bookingInfo);
            AddBookedByInfo(document, bookingInfo);

            return document;
        }
        public static void Fields(string outputFile)
        {
            Document document = new Document();
              Section section = document.AddSection();
              Paragraph par = section.AddParagraph();
              par.AddText("Section: ");
              par.AddSectionField().Format = "ALPHABETIC";
              par.AddLineBreak();

              par.AddText("SectionPages: ");
              par.AddSectionField().Format = "alphabetic";
              par.AddLineBreak();

              par.AddText("Page: ");
              par.AddPageField().Format = "ROMAN";
              par.AddLineBreak();

              par.AddText("NumPages: ");
              par.AddNumPagesField();
              par.AddLineBreak();

              par.AddText("Date: ");
              par.AddDateField();
              par.AddLineBreak();

              par.AddText("Bookmark: ");
              par.AddBookmark("Egal");
              par.AddLineBreak();

              par.AddText("PageRef: ");
              par.AddPageRefField("Egal");

              PdfPrinter printer = new PdfPrinter();
              printer.Document = document;
              printer.PrintDocument();
              printer.PdfDocument.Save(outputFile);
        }
Exemple #36
0
        private void PrintReceipt(string receiptStr)
        {
            string[] receiptLines = receiptStr.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
            MigraDoc.DocumentObjectModel.Document doc = new MigraDoc.DocumentObjectModel.Document();
            doc.DefaultPageSetup.PageWidth   = Unit.FromInch(3.0);
            doc.DefaultPageSetup.PageHeight  = Unit.FromInch(0.181 * receiptLines.Length + 0.56);     //enough to print receipt text plus 9/16 inch (0.56) extra space at bottom.
            doc.DefaultPageSetup.TopMargin   = Unit.FromInch(0.25);
            doc.DefaultPageSetup.LeftMargin  = Unit.FromInch(0.25);
            doc.DefaultPageSetup.RightMargin = Unit.FromInch(0.25);
            MigraDoc.DocumentObjectModel.Font bodyFontx = MigraDocHelper.CreateFont(8, false);
            bodyFontx.Name = FontFamily.GenericMonospace.Name;
            MigraDoc.DocumentObjectModel.Section section = doc.AddSection();
            Paragraph       par       = section.AddParagraph();
            ParagraphFormat parformat = new ParagraphFormat();

            parformat.Alignment = ParagraphAlignment.Left;
            parformat.Font      = bodyFontx;
            par.Format          = parformat;
            par.AddFormattedText(receiptStr, bodyFontx);
            MigraDoc.Rendering.Printing.MigraDocPrintDocument printdoc = new MigraDoc.Rendering.Printing.MigraDocPrintDocument();
            MigraDoc.Rendering.DocumentRenderer renderer = new MigraDoc.Rendering.DocumentRenderer(doc);
            renderer.PrepareDocument();
            printdoc.Renderer = renderer;
            //we might want to surround some of this with a try-catch
#if DEBUG
            FormRpPrintPreview pView = new FormRpPrintPreview();
            pView.printPreviewControl2.Document = printdoc;
            pView.ShowDialog();
#else
            if (PrinterL.SetPrinter(pd2, PrintSituation.Receipt, PatCur.PatNum, "PayConnect receipt printed"))
            {
                printdoc.PrinterSettings = pd2.PrinterSettings;
                printdoc.Print();
            }
#endif
        }
        void Run()
        {
            if (File.Exists(outputName))
            {
                File.Delete(outputName);
            }

            var parser = new ExCSS.StylesheetParser();
            var css = File.ReadAllText("Site.css");
            var sheet = parser.Parse(css);

            var doc = new Document();
            //doc.DefaultPageSetup.Orientation = Orientation.Portrait;
            //doc.DefaultPageSetup.PageFormat = PageFormat.A4;
            //doc.DefaultPageSetup.FooterDistance = Unit.FromCentimeter(0.01);

            Func<string, byte[]> imageProc = s =>
                {
                    var i = System.Drawing.Image.FromFile(s);
                    var ms = new MemoryStream();
                    i.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                    return ms.ToArray();
                };
            
            var section = doc.AddSection();
            var html = File.ReadAllText("example.html");
            section.AddHtml(sheet, html, new HtmlConverter(imageProc));


            var renderer = new PdfDocumentRenderer();
            renderer.Document = doc;
            renderer.RenderDocument();

            renderer.Save(outputName);
            Process.Start(outputName);
        }
        public bool GetPdfNow(int id, int radno, string thenum, string company, DateTime combined)
        {
            try
            {
                using (var db = new ImportPermitEntities())
                {
                    var log = new LogicObject();

                    var appItems = (from t in db.ApplicationItems.Include("Application")
                                    where t.ApplicationId == id
                                    orderby t.EstimatedValue descending

                                    select t).ToList();

                    if (!appItems.Any())
                    {
                        return(false);
                    }
                    var items = new List <DatabaseObject>();
                    appItems.ForEach(t =>
                    {
                        var im = new DatabaseObject()
                        {
                            Id = t.Id,
                            ApplicationItemId                = t.Id,
                            ApplicationItemProductName       = t.Product.Name,
                            ApplicationItemEstimatedQuantity = t.EstimatedQuantity,
                            ApplicationItemEstimatedValue    = t.EstimatedValue,
                        };
                        var appCountries = db.ApplicationCountries.Where(a => a.ApplicationItemId == im.Id).Include("Country").ToList();
                        var depotList    = db.ThroughPuts.Where(a => a.ApplicationItemId == im.Id).Include("Depot").ToList();
                        if (appCountries.Any() && depotList.Any())
                        {
                            im.ApplicationItemPortOfOrigin = "";
                            appCountries.ForEach(c =>
                            {
                                if (string.IsNullOrEmpty(im.ApplicationItemPortOfOrigin))
                                {
                                    im.ApplicationItemPortOfOrigin = c.Country.Name;
                                }
                                else
                                {
                                    im.ApplicationItemPortOfOrigin += ", " + c.Country.Name;
                                }
                            });

                            im.ApplicationItemPortOfDischarge = "";
                            depotList.ForEach(d =>
                            {
                                if (string.IsNullOrEmpty(im.ApplicationItemPortOfDischarge))
                                {
                                    im.ApplicationItemPortOfDischarge = d.Depot.Name;
                                }
                                else
                                {
                                    im.ApplicationItemPortOfDischarge += ", " + d.Depot.Name;
                                }
                            });

                            items.Add(im);
                        }
                    });


                    PdfDocument pdf = new PdfDocument();

                    //Next step is to create a an Empty page.

                    PdfPage pp = pdf.AddPage();



                    string path = System.IO.Path.Combine(Server.MapPath("~/PermDoc"), "permitup.pdf");

                    //Then create an XGraphics Object

                    XGraphics gfx = XGraphics.FromPdfPage(pp);

                    XImage image = XImage.FromFile(path);
                    gfx.DrawImage(image, 0, 0);



                    XFont font  = new XFont("Calibri", 12, XFontStyle.Regular);
                    XFont font2 = new XFont("Calibri", 10, XFontStyle.Regular);


                    gfx.DrawString(thenum, font, XBrushes.Black, new XRect(392, 70, pp.Width.Point, pp.Height.Point),
                                   XStringFormats.TopLeft);

                    gfx.DrawString(DateTime.Now.ToString("dd/MM/yy"), font, XBrushes.Black,
                                   new XRect(390, 95, pp.Width.Point, pp.Height.Point), XStringFormats.TopLeft);

                    gfx.DrawString("", font, XBrushes.Black, new XRect(70, 125, pp.Width.Point, pp.Height.Point),
                                   XStringFormats.TopLeft);

                    gfx.DrawString("", font, XBrushes.Black, new XRect(70, 150, pp.Width.Point, pp.Height.Point),
                                   XStringFormats.TopLeft);

                    gfx.DrawString("", font, XBrushes.Black, new XRect(60, 175, pp.Width.Point, pp.Height.Point),
                                   XStringFormats.TopLeft);


                    gfx.DrawString(company, font, XBrushes.Black, new XRect(80, 218, pp.Width.Point, pp.Height.Point),
                                   XStringFormats.TopLeft);

                    gfx.DrawString("", font, XBrushes.Black, new XRect(92, 240, pp.Width.Point, pp.Height.Point),
                                   XStringFormats.TopLeft);



                    MigraDoc.DocumentObjectModel.Document doc = new MigraDoc.DocumentObjectModel.Document();

                    Section section = doc.AddSection();

                    var table = section.AddTable();



                    //table = section.AddTable();
                    table.Style = "Table";

                    table.Borders.Width       = 0.25;
                    table.Borders.Left.Width  = 0.5;
                    table.Borders.Right.Width = 0.5;
                    table.Rows.LeftIndent     = 0;

                    Column column = table.AddColumn("4cm");
                    column.Format.Alignment = ParagraphAlignment.Center;


                    column = table.AddColumn("4cm");
                    column.Format.Alignment = ParagraphAlignment.Center;

                    column = table.AddColumn("4cm");
                    column.Format.Alignment = ParagraphAlignment.Center;

                    column = table.AddColumn("4cm");
                    column.Format.Alignment = ParagraphAlignment.Center;



                    // Create the header of the table
                    Row row = table.AddRow();
                    //row = table.AddRow();
                    row.HeadingFormat    = true;
                    row.Format.Alignment = ParagraphAlignment.Center;
                    row.Format.Font.Bold = true;


                    row.Cells[0].AddParagraph("Type of Petroleum Product:");
                    row.Cells[0].Format.Alignment = ParagraphAlignment.Left;


                    row.Cells[1].AddParagraph("Country of origin:");
                    row.Cells[1].Format.Alignment = ParagraphAlignment.Left;

                    row.Cells[2].AddParagraph("Quantity/Weight (Metric Tones):");
                    row.Cells[2].Format.Alignment = ParagraphAlignment.Left;

                    row.Cells[3].AddParagraph("Estimated Value($):");
                    row.Cells[3].Format.Alignment = ParagraphAlignment.Left;

                    double total = 0;

                    if (items.Any() && items.Count() <= 7)
                    {
                        foreach (var item in items.ToList())
                        {
                            row = table.AddRow();
                            row.Cells[0].AddParagraph(item.ApplicationItemProductName);
                            row.Cells[0].Format.Alignment = ParagraphAlignment.Left;

                            total = total + item.ApplicationItemEstimatedValue;

                            row.Cells[1].AddParagraph(item.ApplicationItemPortOfOrigin);
                            row.Cells[1].Format.Alignment = ParagraphAlignment.Left;
                            row.Cells[2].AddParagraph(item.ApplicationItemEstimatedQuantity.ToString());
                            row.Cells[2].Format.Alignment = ParagraphAlignment.Left;
                            row.Cells[3].AddParagraph(item.ApplicationItemEstimatedValue.ToString());
                            row.Cells[3].Format.Alignment = ParagraphAlignment.Left;
                        }
                    }
                    else if (items.Any() && items.Count() > 7)
                    {
                        foreach (var item in items.ToList())
                        {
                            row = table.AddRow();
                            row.Format.Font.Size = 8;
                            row.Cells[0].AddParagraph(item.ApplicationItemProductName);
                            row.Cells[0].Format.Alignment = ParagraphAlignment.Left;

                            total = total + item.ApplicationItemEstimatedValue;

                            row.Cells[1].AddParagraph(item.ApplicationItemPortOfOrigin);
                            row.Cells[1].Format.Alignment = ParagraphAlignment.Left;
                            row.Cells[2].AddParagraph(item.ApplicationItemEstimatedQuantity.ToString());
                            row.Cells[2].Format.Alignment = ParagraphAlignment.Left;
                            row.Cells[3].AddParagraph(item.ApplicationItemEstimatedValue.ToString());
                            row.Cells[3].Format.Alignment = ParagraphAlignment.Left;
                        }
                    }

                    //convert total amount to words



                    var amtWords = log.ChangeToWords(total.ToString(), true);


                    const bool             unicode   = false;
                    const PdfFontEmbedding embedding = PdfFontEmbedding.Always;

                    PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(unicode, embedding);

                    // Associate the MigraDoc document with a renderer

                    pdfRenderer.Document = doc;



                    // Layout and render document to PDF

                    pdfRenderer.RenderDocument();



                    var pathtable = System.IO.Path.Combine(Server.MapPath("~/PermDoc"), "table.pdf");

                    pdfRenderer.PdfDocument.Save(pathtable);

                    XImage imagetable = XImage.FromFile(pathtable);
                    gfx.DrawImage(imagetable, 0, 280);


                    //rigid style
                    XImage image2 = XImage.FromFile(System.IO.Path.Combine(Server.MapPath("~/PermDoc"), "permitdown.pdf"));
                    gfx.DrawImage(image2, 0, 550);


                    gfx.DrawString(amtWords, font2, XBrushes.Black, new XRect(135, 556, pp.Width.Point, pp.Height.Point),
                                   XStringFormats.TopLeft);

                    gfx.DrawString("", font, XBrushes.Black, new XRect(238, 593, pp.Width.Point, pp.Height.Point),
                                   XStringFormats.TopLeft);

                    gfx.DrawString("", font, XBrushes.Black, new XRect(220, 633, pp.Width.Point, pp.Height.Point),
                                   XStringFormats.TopLeft);

                    gfx.DrawString(DateTime.Now.ToString("dd/MM/yy"), font, XBrushes.Black,
                                   new XRect(100, 673, pp.Width.Point, pp.Height.Point), XStringFormats.TopLeft);

                    gfx.DrawString(combined.ToString("dd/MM/yy"), font, XBrushes.Black,
                                   new XRect(370, 673, pp.Width.Point, pp.Height.Point), XStringFormats.TopLeft);



                    string path2 = System.IO.Path.Combine(Server.MapPath("~/PermDoc"), "permit" + radno + ".pdf");



                    //string path2 = System.IO.Path.Combine(Server.MapPath("~/PermDoc"), "permit.pdf");

                    pdf.Save(path2);


                    return(true);
                }
            }

            catch (Exception ex)
            {
                return(false);
            }
        }
Exemple #39
0
        void DrawPageHeading(PdfSharp.Pdf.PdfPage page, XGraphics gfx, MimeMessage message)
        {
            var From = message.From.ToString();

            From = Regex.Replace(From, @"""", "");
            var ResentDate = message.ResentDate.DateTime.ToString();
            var Date       = message.Date.DateTime.ToString();
            var To         = message.To.ToString();

            To = Regex.Replace(To, @"""", "");
            var    Subject = message.Subject;
            string filer   = "";

            foreach (var msg_attachment in message.Attachments)
            {
                if ((msg_attachment is MimePart))
                {
                    var part = msg_attachment as MimePart;
                    if (filer.Length > 0)
                    {
                        filer += "," + part.FileName;
                    }
                    else
                    {
                        filer += part.FileName;
                    }
                }
            }

            // HACK²
            gfx.MUH  = PdfFontEncoding.Unicode;
            gfx.MFEH = PdfFontEmbedding.Default;

            // You always need a MigraDoc document for rendering.
            MigraDoc.DocumentObjectModel.Document doc = new MigraDoc.DocumentObjectModel.Document();

            // Create a new style called Table based on style Normal
            var style = doc.Styles.AddStyle("Table", "Normal");

            style.Font.Name = "Verdana";
            style.Font.Name = "Arial";
            style.Font.Size = 9;

            Section sec   = doc.AddSection();
            var     table = sec.AddTable();

            table.Style = "Table";

            // Before you can add a row, you must define the columns
            Column column = table.AddColumn("3cm");

            column.Format.Alignment = ParagraphAlignment.Left;
            column = table.AddColumn("17cm");
            column.Format.Alignment = ParagraphAlignment.Left;

            Row row = table.AddRow();

            row.Cells[0].Borders.Visible = false;
            row.Cells[0].AddParagraph("Fra:");
            row.Cells[0].Format.Font.Bold = true;
            row.Cells[0].Format.Alignment = ParagraphAlignment.Left;
            row.Cells[1].Borders.Visible  = false;
            row.Cells[1].AddParagraph(From);
            row.Cells[1].Format.Font.Bold = false;
            row.Cells[1].Format.Alignment = ParagraphAlignment.Left;
            row.Format.SpaceAfter         = 2;

            row = table.AddRow();
            row.Cells[0].Borders.Visible = false;
            row.Cells[0].AddParagraph("Sendt: ");
            row.Cells[0].Format.Font.Bold = true;
            row.Cells[0].Format.Alignment = ParagraphAlignment.Left;
            row.Cells[1].Borders.Visible  = false;
            row.Cells[1].AddParagraph(Date);
            row.Cells[1].Format.Font.Bold = false;
            row.Cells[1].Format.Alignment = ParagraphAlignment.Left;
            row.Format.SpaceAfter         = 2;

            row = table.AddRow();
            row.Cells[0].Borders.Visible = false;
            row.Cells[0].AddParagraph("Til:");
            row.Cells[0].Format.Font.Bold = true;
            row.Cells[0].Format.Alignment = ParagraphAlignment.Left;
            row.Cells[1].Borders.Visible  = false;
            row.Cells[1].AddParagraph(To);
            row.Cells[1].Format.Font.Bold = false;
            row.Cells[1].Format.Alignment = ParagraphAlignment.Left;
            row.Format.SpaceAfter         = 2;

            row = table.AddRow();
            row.Cells[0].Borders.Visible = false;
            row.Cells[0].AddParagraph("Emne:");
            row.Cells[0].Format.Font.Bold = true;
            row.Cells[0].Format.Alignment = ParagraphAlignment.Left;
            row.Cells[1].Borders.Visible  = false;
            row.Cells[1].AddParagraph(Subject);
            row.Cells[1].Format.Font.Bold = false;
            row.Cells[1].Format.Alignment = ParagraphAlignment.Left;

            if (filer.Length > 0)
            {
                row.Format.SpaceAfter = 2;
                row = table.AddRow();
                row.Cells[0].Borders.Visible = false;
                row.Cells[0].AddParagraph("Vedhæftede filer:");
                row.Cells[0].Format.Font.Bold = true;
                row.Cells[0].Format.Alignment = ParagraphAlignment.Left;
                row.Cells[1].Borders.Visible  = false;
                row.Cells[1].AddParagraph(filer);
                row.Cells[1].Format.Font.Bold = false;
                row.Cells[1].Format.Alignment = ParagraphAlignment.Left;
            }

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

            var box = page.MediaBox.ToXRect();

            box.Inflate(-20, -25);
            // Render the paragraph. You can render tables or shapes the same way.
            docRenderer.RenderObject(gfx, box.Location.X, box.Location.X, box.Width, table);
        }
Exemple #40
0
        public void CreateDocument(List <Recipe> r)
        {
            for (int i = 0; i < r.Count; i++)
            {
                Patient  pa = GetPatient(r[i].PatientId);
                User     u  = GetUser(r[i].DoctorId);
                Medicine m  = GetMedicine(r[i].MedicineId);

                // Create a new MigraDoc document
                Document document = new Document();
                document.Info.Title = "Prescription";


                // Get the predefined style Normal.
                Style style = document.Styles["Normal"];
                style.Font.Name = "Verdana";
                style           = document.Styles[StyleNames.Header];
                style.ParagraphFormat.AddTabStop("16cm", TabAlignment.Right);
                style = document.Styles[StyleNames.Footer];
                style.ParagraphFormat.AddTabStop("8cm", TabAlignment.Center);
                style           = document.Styles.AddStyle("Table", "Normal");
                style.Font.Name = "Verdana";
                style.Font.Name = "Times New Roman";
                style.Font.Size = 9;
                style           = document.Styles.AddStyle("Reference", "Normal");
                style.ParagraphFormat.SpaceBefore = "5mm";
                style.ParagraphFormat.SpaceAfter  = "5mm";
                style.ParagraphFormat.TabStops.AddTabStop("16cm", TabAlignment.Right);


                // Each MigraDoc document needs at least one section.
                Section section = document.AddSection();

                // Put a logo in the header
                Image image = section.Headers.Primary.AddImage("../../Images/bikurofelogo.png");
                image.Height             = "2.5cm";
                image.LockAspectRatio    = true;
                image.RelativeVertical   = RelativeVertical.Line;
                image.RelativeHorizontal = RelativeHorizontal.Margin;
                image.Top              = ShapePosition.Top;
                image.Left             = ShapePosition.Right;
                image.WrapFormat.Style = WrapStyle.Through;


                Paragraph paragraph = section.Footers.Primary.AddParagraph();


                // Create the text frame for the address
                var addressFrame = section.AddTextFrame();
                addressFrame.Height = "3.0cm";
                //addressFrame.Width = "20cm";
                addressFrame.Left = ShapePosition.Center;
                addressFrame.RelativeHorizontal = RelativeHorizontal.Margin;
                addressFrame.Top = "5.0cm";
                addressFrame.RelativeVertical = RelativeVertical.Page;

                // Put sender in address frame
                paragraph = addressFrame.AddParagraph(Reverse("מרשם"));
                paragraph.Format.Font.Name  = "Times New Roman";
                paragraph.Format.Font.Size  = 24;
                paragraph.Format.SpaceAfter = 3;


                // Add the print date field
                paragraph = section.AddParagraph();
                paragraph.Format.SpaceBefore = "8cm";
                paragraph.Style = "Reference";
                //paragraph.AddFormattedText("אאאאאאאאאאא", TextFormat.Bold);
                paragraph.AddTab();
                paragraph.AddText("Prescription, ");
                paragraph.AddDateField("dd.MM.yyyy");


                // Create the item table

                Table table = section.AddTable();
                table.Style = "Table";
                //table.Borders.Color = TableBorder;
                table.Borders.Width       = 0.25;
                table.Borders.Left.Width  = 0.5;
                table.Borders.Right.Width = 0.5;
                table.Rows.LeftIndent     = 0;


                // Before you can add a row, you must define the columns
                Column column = table.AddColumn("1cm");
                column.Format.Alignment = ParagraphAlignment.Center;
                column = table.AddColumn("2.0cm");
                column.Format.Alignment = ParagraphAlignment.Right;
                column = table.AddColumn("2cm");
                column.Format.Alignment = ParagraphAlignment.Right;
                column = table.AddColumn("2cm");
                column.Format.Alignment = ParagraphAlignment.Right;
                column = table.AddColumn("2cm");
                column.Format.Alignment = ParagraphAlignment.Center;
                column = table.AddColumn("2cm");
                column.Format.Alignment = ParagraphAlignment.Right;
                column = table.AddColumn("2cm");
                column.Format.Alignment = ParagraphAlignment.Right;
                column = table.AddColumn("2cm");
                column.Format.Alignment = ParagraphAlignment.Right;

                // Create the header of the table

                Row row = table.AddRow();
                row = table.AddRow();
                row.HeadingFormat    = true;
                row.Format.Alignment = ParagraphAlignment.Center;
                row.Format.Font.Bold = true;



                row.Cells[1].AddParagraph(Reverse("מספר פעמים ביום"));

                row.Cells[1].Format.Alignment = ParagraphAlignment.Right;

                row.Cells[2].AddParagraph(Reverse("משך זמן בימים"));

                row.Cells[2].Format.Alignment = ParagraphAlignment.Right;

                row.Cells[3].AddParagraph(Reverse("שם תרופה"));

                row.Cells[3].Format.Alignment = ParagraphAlignment.Right;

                row.Cells[4].AddParagraph(Reverse("מספר תרופה"));

                row.Cells[4].Format.Alignment = ParagraphAlignment.Right;

                row.Cells[5].AddParagraph(Reverse("שם רופא מטפל"));

                row.Cells[5].Format.Alignment = ParagraphAlignment.Right;

                row.Cells[6].AddParagraph(Reverse("מספר זהות"));

                row.Cells[6].Format.Alignment = ParagraphAlignment.Right;

                row.Cells[7].AddParagraph(Reverse("שם חולה"));

                row.Cells[7].Format.Alignment = ParagraphAlignment.Right;

                table.SetEdge(0, 0, 6, 2, Edge.Box, BorderStyle.Single, 0.75);

                Paragraph p = addressFrame.AddParagraph();

                p.AddLineBreak();

                p.AddLineBreak();

                // Each item fills two rows

                Row row1 = table.AddRow();
                row1.TopPadding = 1.5;
                row1.Cells[7].AddParagraph(Reverse(pa.Fname + " " + pa.Lname));
                row1.Cells[6].AddParagraph(pa.PatientId);
                row1.Cells[5].AddParagraph(Reverse(u.Fname + " " + u.Lname));
                row1.Cells[4].AddParagraph(m.Id);
                row1.Cells[3].AddParagraph(m.CommercialName);
                row1.Cells[2].AddParagraph(r[i].PeriodOfUse.ToString());
                row1.Cells[1].AddParagraph(r[i].QuantityPerDay.ToString());

                string pdfFilename = r[i].RecipeId + ".pdf";
                var    pdf         = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.None);
                pdf.Document = document;
                pdf.RenderDocument();
                pdf.Save(pdfFilename);
                Process.Start(pdfFilename);
            }
        }
Exemple #41
0
        public MemoryStream CreateOrderStream(Guid orderId)
        {
            MigraDoc.DocumentObjectModel.Document document = new MigraDoc.DocumentObjectModel.Document();
            document.Info.Title   = "Order Request";
            document.Info.Subject = "COUNTRY OFFICE, UGANDA";
            document.Info.Author  = "DRC";

            this.section = document.AddSection();

            Image image = section.Headers.Primary.AddImage(HttpContext.Current.Server.MapPath("/Content/reports/logos-90.png"));

            image.LockAspectRatio    = true;
            image.RelativeVertical   = RelativeVertical.Line;
            image.RelativeHorizontal = RelativeHorizontal.Margin;
            image.Top              = ShapePosition.Top;
            image.Left             = "13cm";
            image.WrapFormat.Style = WrapStyle.Through;

            TextFrame heading = this.section.AddTextFrame();

            Paragraph tmpHeadParagraph = heading.AddParagraph("ORDER REQUEST");

            tmpHeadParagraph.Format.Alignment = ParagraphAlignment.Center;

            heading.Top    = ShapePosition.Top;
            heading.Width  = "12.0cm";
            heading.Height = "0.8cm";

            TextFrame countryOfficeAddressFrame;

            countryOfficeAddressFrame                    = section.AddTextFrame();
            countryOfficeAddressFrame.Height             = "3.0cm";
            countryOfficeAddressFrame.Width              = "3.0cm";
            countryOfficeAddressFrame.Left               = ShapePosition.Right;
            countryOfficeAddressFrame.RelativeHorizontal = RelativeHorizontal.Margin;
            countryOfficeAddressFrame.Top                = "3.7cm";
            countryOfficeAddressFrame.RelativeVertical   = RelativeVertical.Page;

            Paragraph paragraph;

            paragraph = countryOfficeAddressFrame.AddParagraph("DANISH REFUGEE COUNCIL");
            paragraph.Format.Font.Name  = "Calibri";
            paragraph.Format.Font.Size  = 7;
            paragraph.Format.SpaceAfter = 3;
            paragraph.AddLineBreak();
            paragraph.AddText("Borgergade 10");
            paragraph.AddLineBreak();
            paragraph.AddText("DK-1300 Copenhagen");
            paragraph.AddLineBreak();
            paragraph.AddText("Denmark");
            paragraph.AddLineBreak();
            paragraph.AddLineBreak();
            paragraph.AddFormattedText("COUNTRY OFFICE, UGANDA", TextFormat.Bold);
            paragraph.AddLineBreak();
            paragraph.AddText("4688 Kalungi Road");
            paragraph.AddLineBreak();
            paragraph.AddText("Muyenga, Kampala");

            paragraph = countryOfficeAddressFrame.AddParagraph("www.drc.dk");
            paragraph.Format.Font.Name      = "Calibri";
            paragraph.Format.Font.Size      = 7;
            paragraph.Format.Font.Color     = new Color(58, 162, 213);
            paragraph.Format.Font.Underline = Underline.Single;
            paragraph.AddLineBreak();
            paragraph.AddText("WWW.danishdemininggroup.dk");


            List <double> sizes = new List <double>();

            sizes.AddRange(new double[] { 4.0, 4.0, 4.0 });
            DataTable  t          = this.GetTable(orderId);
            PrintTable printTable = new PrintTable(t, sizes);

            this.summaryTable = section.AddTable();
            printTable.GenerateTable(this.summaryTable);



            heading          = this.section.AddTextFrame();
            heading.Top      = "0.9cm";
            heading.Width    = Unit.FromCentimeter(14.0);
            tmpHeadParagraph = heading.AddParagraph("Specification/Description, Unit, Quantities, Estimated Prices & PN/BL.");
            tmpHeadParagraph.Format.Alignment = ParagraphAlignment.Center;
            heading.Height = Unit.FromCentimeter(2.0);

            sizes = new List <double>();
            sizes.AddRange(new double[] { 1.0, 3.5, 1.0, 1.0, 2.5, 3.5, 1.0, 2.0, 2.5 });
            t = this.GetDetailsTable(orderId);
            TableOptions options = new TableOptions();

            options.FontSizeCm = 9.0;
            printTable         = new PrintTable(t, sizes, options);

            Table dTable = section.AddTable();

            printTable.GenerateTable(dTable);

            section.AddParagraph(Environment.NewLine);

            sizes = new List <double>();
            sizes.AddRange(new double[] { 4.5, 4.5, 4.5, 4.5 });
            t                  = this.GetTableApproval(orderId);
            options            = new TableOptions();
            options.FontSizeCm = 9.0;
            printTable         = new PrintTable(t, sizes, options);

            dTable = section.AddTable();
            printTable.GenerateTable(dTable);


            PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(true);

            // Set the MigraDoc document
            pdfRenderer.Document = document;

            // Create the PDF document
            pdfRenderer.RenderDocument();

            MemoryStream stream = new MemoryStream();

            pdfRenderer.Save(stream, false);

            return(stream);
        }
Exemple #42
0
        public static Section AddNewSection(this Document document)
        {
            var section = document.AddSection();

            return(section);
        }
Exemple #43
0
        public void CreateCharacterCertificatePDF(string[] CertificateData, string admNo, int admYear)
        {
            if (CertificateData.Length != 5)
            {
                return;
            }
            else
            {
                // Generate nmhs-nexap directory in my document folder
                string containerfolder  = this.GenerateDocumentBaseDirectory();
                MigraModel.Document doc = new MigraModel.Document();
                MigraModel.Section  sec = doc.AddSection();
                sec.PageSetup           = doc.DefaultPageSetup.Clone();
                sec.PageSetup.TopMargin = ".7cm";

                MigraDoc.DocumentObjectModel.Shapes.TextFrame tframe = sec.AddTextFrame();
                tframe.AddImage("nmhs-logo.jpg");
                tframe.Left               = "-.5cm";
                tframe.Top                = "0.7cm";
                tframe.RelativeVertical   = MigraModel.Shapes.RelativeVertical.Page;
                tframe.RelativeHorizontal = MigraModel.Shapes.RelativeHorizontal.Margin;

                MigraModel.Paragraph paraSchoolName = sec.AddParagraph();
                paraSchoolName.Format.Font.Name  = "Times New Roman";
                paraSchoolName.Format.Alignment  = MigraModel.ParagraphAlignment.Center;
                paraSchoolName.Format.Font.Size  = 25;
                paraSchoolName.Format.Font.Color = MigraDoc.DocumentObjectModel.Colors.DarkBlue;
                string schoolName = "NAIMOUZA HIGH SCHOOL";
                paraSchoolName.AddFormattedText(schoolName, MigraModel.TextFormat.Bold);

                MigraModel.Paragraph paraSchoolAddress = sec.AddParagraph();
                paraSchoolAddress.Format.Font.Size = 14;
                paraSchoolAddress.Format.Alignment = MigraModel.ParagraphAlignment.Center;
                string addrs = "Vill. & P.O. Sujapur, Dist. Malda, 732206";
                paraSchoolAddress.AddText(addrs);

                MigraModel.Paragraph paraSchoolMeta = sec.AddParagraph();
                paraSchoolMeta.Format.Font.Size = 10;
                paraSchoolMeta.Format.Alignment = MigraModel.ParagraphAlignment.Center;
                string meta = "INDEX NO. - R1-110, CONTACT NO. - 03512-246525";
                paraSchoolMeta.AddFormattedText(meta, MigraModel.TextFormat.NotBold);

                MigraModel.Paragraph paraAdmissionMeta = sec.AddParagraph();
                paraAdmissionMeta.Format.Font.Size = 10;
                paraAdmissionMeta.Format.Alignment = MigraModel.ParagraphAlignment.Right;
                string admYr = (admYear != 0) ? admYear.ToString() : "0000";
                string ameta = "Admission Sl. " + admNo + " of " + admYr;
                paraAdmissionMeta.AddFormattedText(ameta, MigraModel.TextFormat.Bold);

                MigraModel.Paragraph paraCertificateType = sec.AddParagraph();
                paraCertificateType.Format.Font.Size = 18;
                paraCertificateType.Format.Alignment = MigraModel.ParagraphAlignment.Center;
                paraCertificateType.AddLineBreak();
                string ctype = "CHARACTER CERTIFICATE";
                paraCertificateType.AddFormattedText(ctype, MigraModel.TextFormat.NotBold);

                MigraModel.Paragraph para_a = sec.AddParagraph();
                para_a.Format.Font.Name  = "Lucida Handwriting";
                para_a.Format.Font.Size  = 16;
                para_a.Format.Font.Color = MigraModel.Colors.DarkBlue;
                para_a.Format.Alignment  = MigraModel.ParagraphAlignment.Justify;
                para_a.AddLineBreak();
                para_a.AddLineBreak();
                para_a.AddLineBreak();
                para_a.AddLineBreak();
                para_a.AddTab();

                string para_aText, para_aTextb, paraTextc, paraTextd, stdName;
                para_aText  = CertificateData[0].Trim();
                para_aTextb = CertificateData[1].Trim();
                paraTextc   = CertificateData[2].Trim();
                paraTextd   = CertificateData[3].Trim();
                stdName     = CertificateData[4].Trim();

                para_a.AddText(para_aText);

                MigraModel.Paragraph para_b = sec.AddParagraph();
                para_b.Format.Font.Name  = "Lucida Handwriting";
                para_b.Format.Font.Size  = 16;
                para_b.Format.Font.Color = MigraModel.Colors.DarkBlue;
                para_b.Format.Alignment  = MigraModel.ParagraphAlignment.Justify;
                para_b.AddLineBreak();
                para_b.AddTab();
                para_b.AddText(para_aTextb);

                MigraModel.Paragraph para_c = sec.AddParagraph();
                para_c.Format.Font.Name  = "Lucida Handwriting";
                para_c.Format.Font.Size  = 16;
                para_c.Format.Font.Color = MigraModel.Colors.DarkBlue;
                para_c.Format.Alignment  = MigraModel.ParagraphAlignment.Justify;
                para_c.AddLineBreak();
                para_c.AddTab();
                para_c.AddText(paraTextc);

                MigraModel.Paragraph para_d = sec.AddParagraph();
                para_d.Format.Font.Name  = "Lucida Handwriting";
                para_d.Format.Font.Size  = 16;
                para_d.Format.Font.Color = MigraModel.Colors.DarkBlue;
                para_d.Format.Alignment  = MigraModel.ParagraphAlignment.Justify;
                para_d.AddLineBreak();
                para_d.AddTab();
                para_d.AddText(paraTextd);


                MigraDoc.DocumentObjectModel.Shapes.TextFrame tframeHMaster = sec.AddTextFrame();
                MigraModel.Paragraph paraHMaster = tframeHMaster.AddParagraph();
                paraHMaster.Format.Font.Size = "14";
                paraHMaster.Format.Alignment = MigraModel.ParagraphAlignment.Center;
                string txt1 = "Headmaster";
                string txt2 = "Naimuza High School";
                string txt3 = "Sujapur, Malda";
                paraHMaster.AddText(txt1);
                paraHMaster.AddLineBreak();
                paraHMaster.AddText(txt2);
                paraHMaster.AddLineBreak();
                paraHMaster.AddText(txt3);
                tframeHMaster.Width              = "6cm";
                tframeHMaster.Left               = "10cm";
                tframeHMaster.Top                = "19cm";
                tframeHMaster.RelativeVertical   = MigraModel.Shapes.RelativeVertical.Page;
                tframeHMaster.RelativeHorizontal = MigraModel.Shapes.RelativeHorizontal.Margin;

                MigraDoc.Rendering.PdfDocumentRenderer docRend = new MigraDoc.Rendering.PdfDocumentRenderer(false);
                docRend.Document = doc;
                try
                {
                    docRend.RenderDocument();
                }
                catch (Exception e)
                {
                    System.Windows.MessageBox.Show(e.Message);
                    return;
                }
                string fname      = "CHR_" + stdName + DateTime.Now.ToString("yyyy-MM-dd HHmmss") + ".pdf";
                string pathString = Path.Combine(containerfolder, fname);
                docRend.PdfDocument.Save(pathString);

                System.Diagnostics.ProcessStartInfo processInfo = new System.Diagnostics.ProcessStartInfo();
                processInfo.FileName = pathString;
                System.Diagnostics.Process.Start(processInfo);
            }
        }
Exemple #44
0
        ///<summary>Supply pd so that we know the paper size and margins.</summary>
        public static void CreateDocument(FormRpStatement sender, MigraDoc.DocumentObjectModel.Document doc, PrintDocument pd, Family fam, Patient pat, DataSet dataSet, Statement Stmt)
        {
            //doc= new MigraDoc.DocumentObjectModel.Document();//don't do this or the reference to the original doc will be lost.
            doc.DefaultPageSetup.PageWidth    = Unit.FromInch((double)pd.DefaultPageSettings.PaperSize.Width / 100);
            doc.DefaultPageSetup.PageHeight   = Unit.FromInch((double)pd.DefaultPageSettings.PaperSize.Height / 100);
            doc.DefaultPageSetup.TopMargin    = Unit.FromInch((double)pd.DefaultPageSettings.Margins.Top / 100);
            doc.DefaultPageSetup.LeftMargin   = Unit.FromInch((double)pd.DefaultPageSettings.Margins.Left / 100);
            doc.DefaultPageSetup.RightMargin  = Unit.FromInch((double)pd.DefaultPageSettings.Margins.Right / 100);
            doc.DefaultPageSetup.BottomMargin = Unit.FromInch((double)pd.DefaultPageSettings.Margins.Bottom / 100);
            MigraDoc.DocumentObjectModel.Section section = doc.AddSection();          //so that Swiss will have different footer for each patient.
            string text;

            MigraDoc.DocumentObjectModel.Font font;
            //GetPatGuar(PatNums[famIndex][0]);
            //Family fam=Patients.GetFamily(Stmt.PatNum);
            Patient PatGuar = fam.ListPats[0];          //.Copy();
            //Patient pat=fam.GetPatient(Stmt.PatNum);
            DataTable tableMisc = dataSet.Tables["misc"];

            //HEADING------------------------------------------------------------------------------
            #region Heading
            Paragraph       par       = section.AddParagraph();
            ParagraphFormat parformat = new ParagraphFormat();
            parformat.Alignment = ParagraphAlignment.Center;
            par.Format          = parformat;
            font = MigraDocHelper.CreateFont(14, true);
            text = "This statement was generated from the plug-in";
            par.AddFormattedText(text, font);
            text = DateTime.Today.ToShortDateString();
            font = MigraDocHelper.CreateFont(10);
            par.AddLineBreak();
            par.AddFormattedText(text, font);
            text = Lan.g("FormRpStatement", "Account Number") + " ";
            if (PrefC.GetBool(PrefName.StatementAccountsUseChartNumber))
            {
                text += PatGuar.ChartNumber;
            }
            else
            {
                text += PatGuar.PatNum;
            }
            par.AddLineBreak();
            par.AddFormattedText(text, font);
            TextFrame frame;
            #endregion
            //Practice Address----------------------------------------------------------------------
            #region Practice Address
            if (PrefC.GetBool(PrefName.StatementShowReturnAddress))
            {
                font  = MigraDocHelper.CreateFont(10);
                frame = section.AddTextFrame();
                frame.RelativeVertical   = RelativeVertical.Page;
                frame.RelativeHorizontal = RelativeHorizontal.Page;
                frame.MarginLeft         = Unit.Zero;
                frame.MarginTop          = Unit.Zero;
                frame.Top   = TopPosition.Parse("0.5 in");
                frame.Left  = LeftPosition.Parse("0.3 in");
                frame.Width = Unit.FromInch(3);
                if (!PrefC.GetBool(PrefName.EasyNoClinics) && Clinics.List.Length > 0 &&           //if using clinics
                    Clinics.GetClinic(PatGuar.ClinicNum) != null)                             //and this patient assigned to a clinic
                {
                    Clinic clinic = Clinics.GetClinic(PatGuar.ClinicNum);
                    par             = frame.AddParagraph();
                    par.Format.Font = font;
                    par.AddText(clinic.Description);
                    par.AddLineBreak();
                    par.AddText(clinic.Address);
                    par.AddLineBreak();
                    if (clinic.Address2 != "")
                    {
                        par.AddText(clinic.Address2);
                        par.AddLineBreak();
                    }
                    if (CultureInfo.CurrentCulture.Name.EndsWith("CH"))                     //CH is for switzerland. eg de-CH
                    {
                        par.AddText(clinic.Zip + " " + clinic.City);
                    }
                    else
                    {
                        par.AddText(clinic.City + ", " + clinic.State + " " + clinic.Zip);
                    }
                    par.AddLineBreak();
                    text = clinic.Phone;
                    if (text.Length == 10)
                    {
                        text = "(" + text.Substring(0, 3) + ")" + text.Substring(3, 3) + "-" + text.Substring(6);
                    }
                    par.AddText(text);
                    par.AddLineBreak();
                }
                else
                {
                    par             = frame.AddParagraph();
                    par.Format.Font = font;
                    par.AddText(PrefC.GetString(PrefName.PracticeTitle));
                    par.AddLineBreak();
                    if (CultureInfo.CurrentCulture.Name == "en-AU")                   //English (Australia)
                    {
                        Provider defaultProv = Providers.GetProv(PrefC.GetLong(PrefName.PracticeDefaultProv));
                        par.AddText("ABN: " + defaultProv.NationalProvID);
                        par.AddLineBreak();
                    }
                    par.AddText(PrefC.GetString(PrefName.PracticeAddress));
                    par.AddLineBreak();
                    if (PrefC.GetString(PrefName.PracticeAddress2) != "")
                    {
                        par.AddText(PrefC.GetString(PrefName.PracticeAddress2));
                        par.AddLineBreak();
                    }
                    if (CultureInfo.CurrentCulture.Name.EndsWith("CH"))                     //CH is for switzerland. eg de-CH
                    {
                        par.AddText(PrefC.GetString(PrefName.PracticeZip) + " " + PrefC.GetString(PrefName.PracticeCity));
                    }
                    else
                    {
                        par.AddText(PrefC.GetString(PrefName.PracticeCity) + ", " + PrefC.GetString(PrefName.PracticeST) + " " + PrefC.GetString(PrefName.PracticeZip));
                    }
                    par.AddLineBreak();
                    text = PrefC.GetString(PrefName.PracticePhone);
                    if (text.Length == 10)
                    {
                        text = "(" + text.Substring(0, 3) + ")" + text.Substring(3, 3) + "-" + text.Substring(6);
                    }
                    par.AddText(text);
                    par.AddLineBreak();
                }
            }
            #endregion
            //AMOUNT ENCLOSED------------------------------------------------------------------------------------------------------
            #region Amount Enclosed
            Table  table;
            Column col;
            Row    row;
            Cell   cell;
            frame = MigraDocHelper.CreateContainer(section, 450, 110, 330, 29);
            if (!Stmt.HidePayment)
            {
                table = MigraDocHelper.DrawTable(frame, 0, 0, 29);
                col   = table.AddColumn(Unit.FromInch(1.1));
                col   = table.AddColumn(Unit.FromInch(1.1));
                col   = table.AddColumn(Unit.FromInch(1.1));
                row   = table.AddRow();
                row.Format.Alignment = ParagraphAlignment.Center;
                row.Borders.Color    = Colors.Black;
                row.Shading.Color    = Colors.LightGray;
                row.TopPadding       = Unit.FromInch(0);
                row.BottomPadding    = Unit.FromInch(0);
                font = MigraDocHelper.CreateFont(8, true);
                cell = row.Cells[0];
                par  = cell.AddParagraph();
                par.AddFormattedText(Lan.g("FormRpStatement", "Amount Due"), font);
                cell = row.Cells[1];
                par  = cell.AddParagraph();
                par.AddFormattedText(Lan.g("FormRpStatement", "Date Due"), font);
                cell = row.Cells[2];
                par  = cell.AddParagraph();
                par.AddFormattedText(Lan.g("FormRpStatement", "Amount Enclosed"), font);
                row = table.AddRow();
                row.Format.Alignment     = ParagraphAlignment.Center;
                row.Borders.Left.Color   = Colors.Gray;
                row.Borders.Bottom.Color = Colors.Gray;
                row.Borders.Right.Color  = Colors.Gray;
                font = MigraDocHelper.CreateFont(9);
                double balTotal = PatGuar.BalTotal;
                if (!PrefC.GetBool(PrefName.BalancesDontSubtractIns))                 //this is typical
                {
                    balTotal -= PatGuar.InsEst;
                }
                for (int m = 0; m < tableMisc.Rows.Count; m++)
                {
                    if (tableMisc.Rows[m]["descript"].ToString() == "payPlanDue")
                    {
                        balTotal += PIn.Double(tableMisc.Rows[m]["value"].ToString());
                        //payPlanDue;//PatGuar.PayPlanDue;
                    }
                }
                text = balTotal.ToString("F");
                cell = row.Cells[0];
                par  = cell.AddParagraph();
                par.AddFormattedText(text, font);
                if (PrefC.GetLong(PrefName.StatementsCalcDueDate) == -1)
                {
                    text = Lan.g("FormRpStatement", "Upon Receipt");
                }
                else
                {
                    text = DateTime.Today.AddDays(PrefC.GetLong(PrefName.StatementsCalcDueDate)).ToShortDateString();
                }
                cell = row.Cells[1];
                par  = cell.AddParagraph();
                par.AddFormattedText(text, font);
            }
            #endregion
            //Credit Card Info--------------------------------------------------------------------------------------------------------
            #region Credit Card Info
            if (!Stmt.HidePayment)
            {
                if (PrefC.GetBool(PrefName.StatementShowCreditCard))
                {
                    float yPos = 60;
                    font = MigraDocHelper.CreateFont(7, true);
                    text = Lan.g("FormRpStatement", "CREDIT CARD TYPE");
                    MigraDocHelper.DrawString(frame, text, font, 0, yPos);
                    float rowHeight            = 26;
                    System.Drawing.Font  wfont = new System.Drawing.Font("Arial", 7, FontStyle.Bold);
                    System.Drawing.Image img   = new Bitmap(500, 30);
                    Graphics             g     = Graphics.FromImage(img);  //just to measure strings
                    MigraDocHelper.DrawLine(frame, System.Drawing.Color.Black, g.MeasureString(text, wfont).Width,
                                            yPos + wfont.GetHeight(g), 326, yPos + wfont.GetHeight(g));
                    yPos += rowHeight;
                    text  = Lan.g("FormRpStatement", "#");
                    MigraDocHelper.DrawString(frame, text, font, 0, yPos);
                    MigraDocHelper.DrawLine(frame, System.Drawing.Color.Black, g.MeasureString(text, wfont).Width,
                                            yPos + wfont.GetHeight(g), 326, yPos + wfont.GetHeight(g));
                    yPos += rowHeight;
                    text  = Lan.g("FormRpStatement", "3 DIGIT CSV");
                    MigraDocHelper.DrawString(frame, text, font, 0, yPos);
                    MigraDocHelper.DrawLine(frame, System.Drawing.Color.Black, g.MeasureString(text, wfont).Width,
                                            yPos + wfont.GetHeight(g), 326, yPos + wfont.GetHeight(g));
                    yPos += rowHeight;
                    text  = Lan.g("FormRpStatement", "EXPIRES");
                    MigraDocHelper.DrawString(frame, text, font, 0, yPos);
                    MigraDocHelper.DrawLine(frame, System.Drawing.Color.Black, g.MeasureString(text, wfont).Width,
                                            yPos + wfont.GetHeight(g), 326, yPos + wfont.GetHeight(g));
                    yPos += rowHeight;
                    text  = Lan.g("FormRpStatement", "AMOUNT APPROVED");
                    MigraDocHelper.DrawString(frame, text, font, 0, yPos);
                    MigraDocHelper.DrawLine(frame, System.Drawing.Color.Black, g.MeasureString(text, wfont).Width,
                                            yPos + wfont.GetHeight(g), 326, yPos + wfont.GetHeight(g));
                    yPos += rowHeight;
                    text  = Lan.g("FormRpStatement", "NAME");
                    MigraDocHelper.DrawString(frame, text, font, 0, yPos);
                    MigraDocHelper.DrawLine(frame, System.Drawing.Color.Black, g.MeasureString(text, wfont).Width,
                                            yPos + wfont.GetHeight(g), 326, yPos + wfont.GetHeight(g));
                    yPos += rowHeight;
                    text  = Lan.g("FormRpStatement", "SIGNATURE");
                    MigraDocHelper.DrawString(frame, text, font, 0, yPos);
                    MigraDocHelper.DrawLine(frame, System.Drawing.Color.Black, g.MeasureString(text, wfont).Width,
                                            yPos + wfont.GetHeight(g), 326, yPos + wfont.GetHeight(g));
                    yPos -= rowHeight;
                    text  = Lan.g("FormRpStatement", "(As it appears on card)");
                    wfont = new System.Drawing.Font("Arial", 5);
                    font  = MigraDocHelper.CreateFont(5);
                    MigraDocHelper.DrawString(frame, text, font, 625 - g.MeasureString(text, wfont).Width / 2 + 5, yPos + 13);
                    g.Dispose();
                    img = null;
                }
            }
            #endregion
            //Patient's Billing Address---------------------------------------------------------------------------------------------
            #region Patient Billing Address
            font            = MigraDocHelper.CreateFont(11);
            frame           = MigraDocHelper.CreateContainer(section, 62.5f + 12.5f, 225 + 1, 300, 200);
            par             = frame.AddParagraph();
            par.Format.Font = font;
            if (Stmt.SinglePatient)
            {
                par.AddText(fam.GetNameInFamFL(Stmt.PatNum));
            }
            else
            {
                par.AddText(PatGuar.GetNameFLFormal());
            }
            par.AddLineBreak();
            par.AddText(PatGuar.Address);
            par.AddLineBreak();
            if (PatGuar.Address2 != "")
            {
                par.AddText(PatGuar.Address2);
                par.AddLineBreak();
            }
            if (CultureInfo.CurrentCulture.Name.EndsWith("CH"))             //CH is for switzerland. eg de-CH
            {
                par.AddText(PatGuar.Zip + " " + PatGuar.City);
            }
            else
            {
                par.AddText(PatGuar.City + ", " + PatGuar.State + " " + PatGuar.Zip);
            }
            //perforated line------------------------------------------------------------------------------------------------------
            //yPos=350;//3.62 inches from top, 1/3 page down
            frame = MigraDocHelper.CreateContainer(section, 0, 350, 850, 30);
            if (!Stmt.HidePayment)
            {
                MigraDocHelper.DrawLine(frame, System.Drawing.Color.LightGray, 0, 0, 850, 0);
                text = Lan.g("FormRpStatement", "PLEASE DETACH AND RETURN THE UPPER PORTION WITH YOUR PAYMENT");
                font = MigraDocHelper.CreateFont(6, true, System.Drawing.Color.Gray);
                par  = frame.AddParagraph();
                par.Format.Alignment = ParagraphAlignment.Center;
                par.Format.Font      = font;
                par.AddText(text);
            }
            #endregion
            //Australian Provider Legend
            #region Australian Provider Legend
            int legendOffset = 0;
            if (CultureInfo.CurrentCulture.Name == "en-AU")           //English (Australia)
            {
                Providers.RefreshCache();
                legendOffset = 25 + 15 * (1 + ProviderC.List.Length);
                MigraDocHelper.InsertSpacer(section, legendOffset);
                frame           = MigraDocHelper.CreateContainer(section, 45, 390, 250, legendOffset);
                par             = frame.AddParagraph();
                par.Format.Font = MigraDocHelper.CreateFont(8, true);
                par.AddLineBreak();
                par.AddText("PROVIDERS:");
                par             = frame.AddParagraph();
                par.Format.Font = MigraDocHelper.CreateFont(8, false);
                for (int i = 0; i < ProviderC.List.Length; i++)           //All non-hidden providers are added to the legend.
                {
                    Provider prov   = ProviderC.List[i];
                    string   suffix = "";
                    if (prov.Suffix.Trim() != "")
                    {
                        suffix = ", " + prov.Suffix.Trim();
                    }
                    par.AddText(prov.Abbr + " - " + prov.FName + " " + prov.LName + suffix + " - " + prov.MedicaidID);
                    par.AddLineBreak();
                }
                par.AddLineBreak();
            }
            #endregion
            //Aging-----------------------------------------------------------------------------------
            #region Aging
            MigraDocHelper.InsertSpacer(section, 275);
            frame = MigraDocHelper.CreateContainer(section, 55, 390 + legendOffset, 250, 29);
            if (!Stmt.HidePayment)
            {
                table = MigraDocHelper.DrawTable(frame, 0, 0, 29);
                col   = table.AddColumn(Unit.FromInch(1.1));
                col   = table.AddColumn(Unit.FromInch(1.1));
                col   = table.AddColumn(Unit.FromInch(1.1));
                col   = table.AddColumn(Unit.FromInch(1.1));
                row   = table.AddRow();
                row.Format.Alignment = ParagraphAlignment.Center;
                row.Borders.Color    = Colors.Black;
                row.Shading.Color    = Colors.LightGray;
                row.TopPadding       = Unit.FromInch(0);
                row.BottomPadding    = Unit.FromInch(0);
                font = MigraDocHelper.CreateFont(8, true);
                cell = row.Cells[0];
                par  = cell.AddParagraph();
                par.AddFormattedText(Lan.g("FormRpStatement", "0-30"), font);
                cell = row.Cells[1];
                par  = cell.AddParagraph();
                par.AddFormattedText(Lan.g("FormRpStatement", "31-60"), font);
                cell = row.Cells[2];
                par  = cell.AddParagraph();
                par.AddFormattedText(Lan.g("FormRpStatement", "61-90"), font);
                cell = row.Cells[3];
                par  = cell.AddParagraph();
                par.AddFormattedText(Lan.g("FormRpStatement", "over 90"), font);
                row = table.AddRow();
                row.Format.Alignment     = ParagraphAlignment.Center;
                row.Borders.Left.Color   = Colors.Gray;
                row.Borders.Bottom.Color = Colors.Gray;
                row.Borders.Right.Color  = Colors.Gray;
                font = MigraDocHelper.CreateFont(9);
                text = PatGuar.Bal_0_30.ToString("F");
                cell = row.Cells[0];
                par  = cell.AddParagraph();
                par.AddFormattedText(text, font);
                text = PatGuar.Bal_31_60.ToString("F");
                cell = row.Cells[1];
                par  = cell.AddParagraph();
                par.AddFormattedText(text, font);
                text = PatGuar.Bal_61_90.ToString("F");
                cell = row.Cells[2];
                par  = cell.AddParagraph();
                par.AddFormattedText(text, font);
                text = PatGuar.BalOver90.ToString("F");
                cell = row.Cells[3];
                par  = cell.AddParagraph();
                par.AddFormattedText(text, font);
            }
            #endregion
            //Floating Balance, Ins info-------------------------------------------------------------------
            #region FloatingBalance
            frame = MigraDocHelper.CreateContainer(section, 460, 380 + legendOffset, 250, 200);
            //table=MigraDocHelper.DrawTable(frame,0,0,90);
            par                 = frame.AddParagraph();
            parformat           = new ParagraphFormat();
            parformat.Alignment = ParagraphAlignment.Right;
            par.Format          = parformat;
            font                = MigraDocHelper.CreateFont(10, false);
            MigraDoc.DocumentObjectModel.Font fontBold = MigraDocHelper.CreateFont(10, true);
            if (PrefC.GetBool(PrefName.BalancesDontSubtractIns))
            {
                text = Lan.g("FormRpStatement", "Balance:");
                par.AddFormattedText(text, fontBold);
                //par.AddLineBreak();
                //text = Lan.g(this, "Ins Pending:");
                //par.AddFormattedText(text, font);
                //par.AddLineBreak();
                //text = Lan.g(this, "After Ins:");
                //par.AddFormattedText(text, font);
                //par.AddLineBreak();
            }
            else              //this is more common
            {
                if (PrefC.GetBool(PrefName.FuchsOptionsOn))
                {
                    text = Lan.g("FormRpStatement", "Balance:");
                    par.AddFormattedText(text, font);
                    par.AddLineBreak();
                    text = Lan.g("FormRpStatement", "-Ins Estimate:");
                    par.AddFormattedText(text, font);
                    par.AddLineBreak();
                    text = Lan.g("FormRpStatement", "=Owed Now:");
                    par.AddFormattedText(text, fontBold);
                    par.AddLineBreak();
                }
                else
                {
                    text = Lan.g("FormRpStatement", "Total:");
                    par.AddFormattedText(text, font);
                    par.AddLineBreak();
                    text = Lan.g("FormRpStatement", "-Ins Estimate:");
                    par.AddFormattedText(text, font);
                    par.AddLineBreak();
                    text = Lan.g("FormRpStatement", "=Balance:");
                    par.AddFormattedText(text, fontBold);
                    par.AddLineBreak();
                }
            }
            frame = MigraDocHelper.CreateContainer(section, 730, 380 + legendOffset, 100, 200);
            //table=MigraDocHelper.DrawTable(frame,0,0,90);
            par                 = frame.AddParagraph();
            parformat           = new ParagraphFormat();
            parformat.Alignment = ParagraphAlignment.Left;
            par.Format          = parformat;
            font                = MigraDocHelper.CreateFont(10, false);
            //numbers:
            if (PrefC.GetBool(PrefName.BalancesDontSubtractIns))
            {
                text = PatGuar.BalTotal.ToString("c");
                par.AddFormattedText(text, fontBold);
                //par.AddLineBreak();
                //text = PatGuar.InsEst.ToString("c");
                //par.AddFormattedText(text, font);
                //par.AddLineBreak();
                //text = (PatGuar.BalTotal - PatGuar.InsEst).ToString("c");
                //par.AddFormattedText(text, font);
                //par.AddLineBreak();
            }
            else              //more common
            {
                if (Stmt.SinglePatient)
                {
                    double patInsEst = 0;
                    for (int m = 0; m < tableMisc.Rows.Count; m++)
                    {
                        if (tableMisc.Rows[m]["descript"].ToString() == "patInsEst")
                        {
                            patInsEst = PIn.Double(tableMisc.Rows[m]["value"].ToString());
                        }
                    }
                    double patBal = pat.EstBalance - patInsEst;
                    text = pat.EstBalance.ToString("c");
                    par.AddFormattedText(text, font);
                    par.AddLineBreak();
                    text = patInsEst.ToString("c");
                    par.AddFormattedText(text, font);
                    par.AddLineBreak();
                    text = patBal.ToString("c");
                    par.AddFormattedText(text, fontBold);
                }
                else
                {
                    text = PatGuar.BalTotal.ToString("c");
                    par.AddFormattedText(text, font);
                    par.AddLineBreak();
                    text = PatGuar.InsEst.ToString("c");
                    par.AddFormattedText(text, font);
                    par.AddLineBreak();
                    text = (PatGuar.BalTotal - PatGuar.InsEst).ToString("c");
                    par.AddFormattedText(text, fontBold);
                    par.AddLineBreak();
                }
            }
            MigraDocHelper.InsertSpacer(section, 80);
            #endregion FloatingBalance
            //Bold note-------------------------------------------------------------------------------
            #region Bold note
            if (Stmt.NoteBold != "")
            {
                MigraDocHelper.InsertSpacer(section, 7);
                font            = MigraDocHelper.CreateFont(10, true, System.Drawing.Color.DarkRed);
                par             = section.AddParagraph();
                par.Format.Font = font;
                par.AddText(Stmt.NoteBold);
                MigraDocHelper.InsertSpacer(section, 8);
            }
            #endregion Bold note
            //Payment plan grid definition---------------------------------------------------------------------------------
            #region PayPlan grid definition
            ODGridColumn gcol;
            ODGridRow    grow;
            ODGrid       gridPP = new ODGrid();
            //this.Controls.Add(gridPP);
            gridPP.BeginUpdate();
            gridPP.Columns.Clear();
            gcol = new ODGridColumn(Lan.g("FormRpStatement", "Date"), 73);
            gridPP.Columns.Add(gcol);
            gcol = new ODGridColumn(Lan.g("FormRpStatement", "Description"), 270);
            gridPP.Columns.Add(gcol);
            gcol = new ODGridColumn(Lan.g("FormRpStatement", "Charges"), 60, HorizontalAlignment.Right);
            gridPP.Columns.Add(gcol);
            gcol = new ODGridColumn(Lan.g("FormRpStatement", "Credits"), 60, HorizontalAlignment.Right);
            gridPP.Columns.Add(gcol);
            gcol = new ODGridColumn(Lan.g("FormRpStatement", "Balance"), 60, HorizontalAlignment.Right);
            gridPP.Columns.Add(gcol);
            gridPP.Width = gridPP.WidthAllColumns + 20;
            gridPP.EndUpdate();
            #endregion PayPlan grid definition
            //Payment plan grid.  There will be only one, if any-----------------------------------------------------------------
            #region PayPlan grid
            DataTable  tablePP = dataSet.Tables["payplan"];
            ODGridCell gcell;
            if (tablePP.Rows.Count > 0)
            {
                //MigraDocHelper.InsertSpacer(section,5);
                par                  = section.AddParagraph();
                par.Format.Font      = MigraDocHelper.CreateFont(10, true);
                par.Format.Alignment = ParagraphAlignment.Center;
                //par.Format.SpaceBefore=Unit.FromInch(.05);
                //par.Format.SpaceAfter=Unit.FromInch(.05);
                par.AddText(Lan.g("FormRpStatement", "Payment Plans"));
                MigraDocHelper.InsertSpacer(section, 2);
                gridPP.BeginUpdate();
                gridPP.Rows.Clear();
                for (int p = 0; p < tablePP.Rows.Count; p++)
                {
                    grow = new ODGridRow();
                    grow.Cells.Add(tablePP.Rows[p]["date"].ToString());
                    grow.Cells.Add(tablePP.Rows[p]["description"].ToString());
                    grow.Cells.Add(tablePP.Rows[p]["charges"].ToString());
                    grow.Cells.Add(tablePP.Rows[p]["credits"].ToString());
                    gcell = new ODGridCell(tablePP.Rows[p]["balance"].ToString());
                    if (p == tablePP.Rows.Count - 1)
                    {
                        gcell.Bold = YN.Yes;
                    }
                    else if (tablePP.Rows[p + 1]["balance"].ToString() == "")                 //if next row balance is blank.
                    {
                        gcell.Bold = YN.Yes;
                    }
                    grow.Cells.Add(gcell);
                    gridPP.Rows.Add(grow);
                }
                gridPP.EndUpdate();
                MigraDocHelper.DrawGrid(section, gridPP);
                MigraDocHelper.InsertSpacer(section, 2);
                par                    = section.AddParagraph();
                par.Format.Font        = MigraDocHelper.CreateFont(10, true);
                par.Format.Alignment   = ParagraphAlignment.Right;
                par.Format.RightIndent = Unit.FromInch(0.25);
                double payPlanDue = 0;
                for (int m = 0; m < tableMisc.Rows.Count; m++)
                {
                    if (tableMisc.Rows[m]["descript"].ToString() == "payPlanDue")
                    {
                        payPlanDue = PIn.Double(tableMisc.Rows[m]["value"].ToString());
                    }
                }
                par.AddText(Lan.g("FormRpStatement", "Payment Plan Amount Due: ") + payPlanDue.ToString("c"));             //PatGuar.PayPlanDue.ToString("c"));
                MigraDocHelper.InsertSpacer(section, 10);
            }
            #endregion PayPlan grid
            //Body Table definition--------------------------------------------------------------------------------------------------------
            #region Body Table definition
            ODGrid gridPat = new ODGrid();
            //this.Controls.Add(gridPat);
            gridPat.BeginUpdate();
            gridPat.Columns.Clear();
            gcol = new ODGridColumn(Lan.g("FormRpStatement", "Date"), 73);
            gridPat.Columns.Add(gcol);
            gcol = new ODGridColumn(Lan.g("FormRpStatement", "Patient"), 100);
            gridPat.Columns.Add(gcol);
            //prov
            gcol = new ODGridColumn(Lan.g("FormRpStatement", "Code"), 45);
            gridPat.Columns.Add(gcol);
            gcol = new ODGridColumn(Lan.g("FormRpStatement", "Tooth"), 42);
            gridPat.Columns.Add(gcol);
            gcol = new ODGridColumn(Lan.g("FormRpStatement", "Description"), 270);
            gridPat.Columns.Add(gcol);
            gcol = new ODGridColumn(Lan.g("FormRpStatement", "Charges"), 60, HorizontalAlignment.Right);
            gridPat.Columns.Add(gcol);
            gcol = new ODGridColumn(Lan.g("FormRpStatement", "Credits"), 60, HorizontalAlignment.Right);
            gridPat.Columns.Add(gcol);
            gcol = new ODGridColumn(Lan.g("FormRpStatement", "Balance"), 60, HorizontalAlignment.Right);
            gridPat.Columns.Add(gcol);
            gridPat.Width = gridPat.WidthAllColumns + 20;
            gridPat.EndUpdate();
            #endregion Body Table definition
            //Loop through each table.  Could be one intermingled, or one for each patient-----------------------------------------
            DataTable tableAccount;
            string    tablename;
            long      patnum;
            for (int i = 0; i < dataSet.Tables.Count; i++)
            {
                tableAccount = dataSet.Tables[i];
                tablename    = tableAccount.TableName;
                if (!tablename.StartsWith("account"))
                {
                    continue;
                }
                par                    = section.AddParagraph();
                par.Format.Font        = MigraDocHelper.CreateFont(10, true);
                par.Format.SpaceBefore = Unit.FromInch(.05);
                par.Format.SpaceAfter  = Unit.FromInch(.05);
                patnum                 = 0;
                if (tablename != "account")               //account123 etc.
                {
                    patnum = PIn.Long(tablename.Substring(7));
                }
                if (patnum != 0)
                {
                    par.AddText(fam.GetNameInFamFLnoPref(patnum));
                }
                //if(FamilyStatementDataList[famIndex].PatAboutList[i].ApptDescript!=""){
                //	par=section.AddParagraph();
                //	par.Format.Font=MigraDocHelper.CreateFont(9);//same as body font
                //	par.AddText(FamilyStatementDataList[famIndex].PatAboutList[i].ApptDescript);
                //}
                gridPat.BeginUpdate();
                gridPat.Rows.Clear();
                //lineData=FamilyStatementDataList[famIndex].PatDataList[i].PatData;
                for (int p = 0; p < tableAccount.Rows.Count; p++)
                {
                    grow = new ODGridRow();
                    grow.Cells.Add(tableAccount.Rows[p]["date"].ToString());
                    grow.Cells.Add(tableAccount.Rows[p]["patient"].ToString());
                    grow.Cells.Add(tableAccount.Rows[p]["ProcCode"].ToString());
                    grow.Cells.Add(tableAccount.Rows[p]["tth"].ToString());
                    if (CultureInfo.CurrentCulture.Name == "en-AU")                   //English (Australia)
                    {
                        if (tableAccount.Rows[p]["prov"].ToString().Trim() != "")
                        {
                            grow.Cells.Add(tableAccount.Rows[p]["prov"].ToString() + " - " + tableAccount.Rows[p]["description"].ToString());
                        }
                        else                          //No provider on this account row item, so don't put the extra leading characters.
                        {
                            grow.Cells.Add(tableAccount.Rows[p]["description"].ToString());
                        }
                    }
                    else                      //Assume English (United States)
                    {
                        grow.Cells.Add(tableAccount.Rows[p]["description"].ToString());
                    }
                    grow.Cells.Add(tableAccount.Rows[p]["charges"].ToString());
                    grow.Cells.Add(tableAccount.Rows[p]["credits"].ToString());
                    grow.Cells.Add(tableAccount.Rows[p]["balance"].ToString());
                    gridPat.Rows.Add(grow);
                }
                gridPat.EndUpdate();
                MigraDocHelper.DrawGrid(section, gridPat);
                //Total
                frame = MigraDocHelper.CreateContainer(section);
                font  = MigraDocHelper.CreateFont(9, true);
                float totalPos = ((float)(doc.DefaultPageSetup.PageWidth.Inch //-doc.DefaultPageSetup.LeftMargin.Inch
                                                                              //-doc.DefaultPageSetup.RightMargin.Inch)
                                          ) * 100f) / 2f + (float)gridPat.WidthAllColumns / 2f + 7;
                RectangleF rectF = new RectangleF(0, 0, totalPos, 16);
                if (patnum != 0)
                {
                    MigraDocHelper.DrawString(frame, " ",
                                              //I decided this was unnecessary:
                                              //dataSet.Tables["patient"].Rows[fam.GetIndex(patnum)]["balance"].ToString(),
                                              font, rectF, ParagraphAlignment.Right);
                    //MigraDocHelper.DrawString(frame,FamilyStatementDataList[famIndex].PatAboutList[i].Balance.ToString("F"),font,rectF,
                    //	ParagraphAlignment.Right);
                }
            }
            gridPat.Dispose();
            //Future appointments---------------------------------------------------------------------------------------------
            #region Future appointments
            font = MigraDocHelper.CreateFont(9);
            DataTable tableAppt = dataSet.Tables["appts"];
            if (tableAppt.Rows.Count > 0)
            {
                par             = section.AddParagraph();
                par.Format.Font = font;
                par.AddText(Lan.g("FormRpStatement", "Scheduled Appointments:"));
            }
            for (int i = 0; i < tableAppt.Rows.Count; i++)
            {
                par.AddLineBreak();
                par.AddText(tableAppt.Rows[i]["descript"].ToString());
            }
            if (tableAppt.Rows.Count > 0)
            {
                MigraDocHelper.InsertSpacer(section, 10);
            }
            #endregion Future appointments
            //Note------------------------------------------------------------------------------------------------------------
            font            = MigraDocHelper.CreateFont(9);
            par             = section.AddParagraph();
            par.Format.Font = font;
            par.AddText(Stmt.Note);
            //bold note
            if (Stmt.NoteBold != "")
            {
                MigraDocHelper.InsertSpacer(section, 10);
                font            = MigraDocHelper.CreateFont(10, true, System.Drawing.Color.DarkRed);
                par             = section.AddParagraph();
                par.Format.Font = font;
                par.AddText(Stmt.NoteBold);
            }
            //return doc;
        }
        private void btnDownloadQRCode_Click(object sender, EventArgs e)
        {
            if (fileDialog.ShowDialog() == DialogResult.OK)
            {
                var document = new MigraDoc.DocumentObjectModel.Document();

                Style style = document.Styles["Normal"];
                style.Font.Name = "Verdana";
                style           = document.Styles[StyleNames.Header];

                style.ParagraphFormat.AddTabStop("16cm", MigraDoc.DocumentObjectModel.TabAlignment.Right);
                style = document.Styles[StyleNames.Footer];
                style.ParagraphFormat.AddTabStop("8cm", MigraDoc.DocumentObjectModel.TabAlignment.Center);

                // Create a new style called Table based on style Normal
                style           = document.Styles.AddStyle("Table", "Normal");
                style.Font.Name = "Verdana";
                style.Font.Name = "Arial";
                style.Font.Size = 8;

                document.DefaultPageSetup.BottomMargin = Unit.FromInch(0.5);
                document.DefaultPageSetup.TopMargin    = Unit.FromInch(0.5);
                document.DefaultPageSetup.RightMargin  = Unit.FromInch(0.5);
                document.DefaultPageSetup.LeftMargin   = Unit.FromInch(0.5);
                document.DefaultPageSetup.Orientation  = MigraDoc.DocumentObjectModel.Orientation.Landscape;

                // Each MigraDoc document needs at least one section.
                Section section = document.AddSection();

                // Create header
                Paragraph paragraph1 = section.AddParagraph();
                paragraph1.AddText("Read Only Connection Code");
                paragraph1.Format.Font.Size   = 24;
                paragraph1.Format.Font.Bold   = true;
                paragraph1.Format.Alignment   = ParagraphAlignment.Left;
                paragraph1.Format.SpaceAfter  = new Unit(16.0);
                paragraph1.Format.SpaceBefore = new Unit(0.0);



                Paragraph paragraph2 = section.AddParagraph();
                paragraph2.AddText("Use this code to share client, farm, and field lists with RFID Module Scan.  Open the RFID Module Scan app, goto \"Settings\", tap \"Connect to Gin\", and then scan this code with the device camera.");
                paragraph2.Format.Font.Size   = 8;
                paragraph2.Format.Font.Bold   = true;
                paragraph2.Format.Alignment   = ParagraphAlignment.Left;
                paragraph2.Format.SpaceAfter  = new Unit(16.0);
                paragraph2.Format.SpaceBefore = new Unit(0.0);

                // Create footer

                /*Paragraph paragraph = section.Footers.Primary.AddParagraph();
                 * paragraph.AddText(string.Format("- Generated {0} {1} -", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString()));
                 * paragraph.Format.Font.Size = 8;
                 * paragraph.Format.Alignment = ParagraphAlignment.Center;*/

                pictureBoxQRCode.Image.Save("connection_code.bmp");
                var image = section.AddImage("connection_code.bmp");
                image.Width  = new Unit(2.0, UnitType.Inch);
                image.Height = new Unit(2.0, UnitType.Inch);

                var pdfRenderer = new MigraDoc.Rendering.PdfDocumentRenderer(false);
                pdfRenderer.Document = document;
                pdfRenderer.RenderDocument();
                pdfRenderer.PdfDocument.Save(fileDialog.FileName);
                System.Diagnostics.Process.Start(fileDialog.FileName);

                this.Close();
            }
        }