public static void DefineParagraphs(Document document, ArticlesWithWordMigra article) { Paragraph paragraphTitle = document.LastSection.AddParagraph(article.Title, "Heading1"); Paragraph paragraph = document.LastSection.AddParagraph(article.Context, "Normal"); paragraphTitle.AddBookmark("Paragraphs Title"); paragraph.AddBookmark("Paragraphs"); }
private void butPrint_Click(object sender, EventArgs e) { PrintDocument pd = new PrintDocument(); //TODO: Implement ODprintout pattern - MigraDoc if (!PrinterL.SetPrinter(pd, PrintSituation.Default, 0, "Reconcile list printed")) { return; //User cancelled. } pd.DefaultPageSettings.Margins = new Margins(25, 25, 40, 40); if (pd.DefaultPageSettings.PrintableArea.Height == 0) { pd.DefaultPageSettings.PaperSize = new PaperSize("default", 850, 1100); } MigraDoc.DocumentObjectModel.Document doc = CreatePrintDocument(pd); MigraDoc.Rendering.Printing.MigraDocPrintDocument printdoc = new MigraDoc.Rendering.Printing.MigraDocPrintDocument(); MigraDoc.Rendering.DocumentRenderer renderer = new MigraDoc.Rendering.DocumentRenderer(doc); renderer.PrepareDocument(); printdoc.PrinterSettings = pd.PrinterSettings; printdoc.Renderer = renderer; #if DEBUG FormRpPrintPreview pView = new FormRpPrintPreview(printdoc); pView.ShowDialog(); #else printdoc.Print(); #endif }
/// <summary> /// Renders a MigraDoc document to the specified file. /// </summary> public void Render(Document doc, string file, string workingDirectory) { StreamWriter strmWrtr = null; try { _document = doc; _docObject = doc; _workingDirectory = workingDirectory; string path = file; if (workingDirectory != null) path = Path.Combine(workingDirectory, file); strmWrtr = new StreamWriter(path, false, System.Text.Encoding.Default); _rtfWriter = new RtfWriter(strmWrtr); WriteDocument(); } finally { if (strmWrtr != null) { strmWrtr.Flush(); strmWrtr.Close(); } } }
/// <summary> /// Creates a report on specs issues, according to user's choices /// </summary> /// <returns>The document created, or null</returns> public override Document BuildDocument() { Document retVal = new Document(); Log.Info("Creating spec issues report"); retVal.Info.Title = "EFS Specification issues report"; retVal.Info.Author = "ERTMS Solutions"; retVal.Info.Subject = "Specification issues report"; SpecIssuesReport report = new SpecIssuesReport(retVal); if (AddInformationNeeded) { Log.Info("..generating information needed"); report.CreateMoreInformationArticle(this); } if (AddSpecIssues) { Log.Info("..generating spec issues"); report.CreateSpecIssuesArticle(this); } if (AddDesignChoices) { Log.Info("..generating design choices"); report.CreateDesignChoicesArticle(this); } return retVal; }
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); }//--------------------------------------
public static Document CreateDocument(Project currentProject) { try { // Create a new MigraDoc document Document document = new Document(); document.Info.Title = "Cameratrap Manager Report for "+currentProject.Name; document.Info.Subject = currentProject.Subject; document.Info.Author = currentProject.Creator; Styles.DefineStyles(document); Cover.DefineCover(document, currentProject); // TableOfContents.DefineTableOfContents(document); DefineContentSection(document, currentProject); Paragraphs.Project_overview(document, currentProject); Tables.DefineTables(document, currentProject); Charts.DefineCharts(document, currentProject); return document; } catch (Exception ex) { throw ex; } }
private void setDocumentStyle(ref Document document) { Style style = document.Styles["Normal"]; style.Font.Name = "Calibri"; style = document.Styles[StyleNames.Header]; //style.Section.PageSetupHeaders.EvenPage.AddTable(); style.ParagraphFormat.AddTabStop("1cm", TabAlignment.Center); style = document.Styles[StyleNames.Footer]; style.ParagraphFormat.AddTabStop("1cm", TabAlignment.Center); style.ParagraphFormat.Alignment = ParagraphAlignment.Center; style.ParagraphFormat.Font.Bold = false; style.ParagraphFormat.Font.Size = 7; style = document.Styles[StyleNames.Heading1]; style.ParagraphFormat.Alignment = ParagraphAlignment.Center; style.ParagraphFormat.Font.Bold = true; style = document.Styles[StyleNames.Heading2]; style.ParagraphFormat.Font.Bold = false; style = document.Styles[StyleNames.Heading3]; style.ParagraphFormat.Alignment = ParagraphAlignment.Center; style.ParagraphFormat.Font.Bold = true; style.ParagraphFormat.Font.Size = 6; style = document.Styles[StyleNames.Heading4]; style.ParagraphFormat.Alignment = ParagraphAlignment.Center; style.ParagraphFormat.Font.Bold = false; style.ParagraphFormat.Font.Size = 8; style = document.Styles[StyleNames.Heading5]; style.ParagraphFormat.Alignment = ParagraphAlignment.Justify; style.ParagraphFormat.Font.Bold = false; style.ParagraphFormat.Font.Size = 7; }
/// <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; } }
public static void Project_overview(Document document, Project currentProject) { try { Paragraph paragraph = document.LastSection.AddParagraph("Camera Trap Project Overview", "Heading1"); paragraph.AddBookmark("Overview"); document.LastSection.AddParagraph("Subject", "Heading2"); paragraph = document.LastSection.AddParagraph(); paragraph.Format.Alignment = ParagraphAlignment.Left; paragraph.AddText(currentProject.Subject); document.LastSection.AddParagraph("Description", "Heading2"); paragraph = document.LastSection.AddParagraph(); paragraph.Format.Alignment = ParagraphAlignment.Left; paragraph.AddText(currentProject.Description); document.LastSection.AddParagraph("Type of project", "Heading2"); paragraph = document.LastSection.AddParagraph(); paragraph.Format.Alignment = ParagraphAlignment.Left; paragraph.AddText(currentProject.Type); } catch (Exception ex) { throw ex; } }
static void DemonstrateAlignment(Document document) { try { document.LastSection.AddParagraph("Alignment", "Heading2"); document.LastSection.AddParagraph("Left Aligned", "Heading3"); Paragraph paragraph = document.LastSection.AddParagraph(); paragraph.Format.Alignment = ParagraphAlignment.Left; paragraph.AddText("Algo de texto"); document.LastSection.AddParagraph("Right Aligned", "Heading3"); paragraph = document.LastSection.AddParagraph(); paragraph.Format.Alignment = ParagraphAlignment.Right; paragraph.AddText("Algo de texto"); document.LastSection.AddParagraph("Centered", "Heading3"); paragraph = document.LastSection.AddParagraph(); paragraph.Format.Alignment = ParagraphAlignment.Center; paragraph.AddText("Algo de texto"); document.LastSection.AddParagraph("Justified", "Heading3"); paragraph = document.LastSection.AddParagraph(); paragraph.Format.Alignment = ParagraphAlignment.Justify; paragraph.AddText("Algo de texto"); } 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); }
/// <summary> /// Constructor /// </summary> /// <param name="doc"></param> public ReportTools(Document doc) { document = doc; DefineStyles(document); section = document.AddSection(); }
public static void DemonstrateSimpleTable(Document document) { document.LastSection.AddParagraph("Simple Tables", "Heading2"); Table table = new Table(); table.Borders.Width = 0.75; Column column = table.AddColumn(Unit.FromCentimeter(2)); column.Format.Alignment = ParagraphAlignment.Center; table.AddColumn(Unit.FromCentimeter(5)); Row row = table.AddRow(); row.Shading.Color = Colors.PaleGoldenrod; Cell cell = row.Cells[0]; cell.AddParagraph("Itemus"); cell = row.Cells[1]; cell.AddParagraph("Descriptum"); row = table.AddRow(); cell = row.Cells[0]; cell.AddParagraph("1"); cell = row.Cells[1]; cell.AddParagraph(FillerText.ShortText); row = table.AddRow(); cell = row.Cells[0]; cell.AddParagraph("2"); cell = row.Cells[1]; cell.AddParagraph(FillerText.Text); table.SetEdge(0, 0, 2, 3, Edge.Box, BorderStyle.Single, 1.5, Colors.Black); document.LastSection.Add(table); }
public static void DefineCharts(Document document) { Paragraph paragraph = document.LastSection.AddParagraph("Chart Overview", "Heading1"); paragraph.AddBookmark("Charts"); document.LastSection.AddParagraph("Sample Chart", "Heading2"); Chart chart = new Chart(); chart.Left = 0; chart.Width = Unit.FromCentimeter(16); chart.Height = Unit.FromCentimeter(12); Series series = chart.SeriesCollection.AddSeries(); series.ChartType = ChartType.Column2D; series.Add(new double[]{1, 17, 45, 5, 3, 20, 11, 23, 8, 19}); series.HasDataLabel = true; series = chart.SeriesCollection.AddSeries(); series.ChartType = ChartType.Line; series.Add(new double[]{41, 7, 5, 45, 13, 10, 21, 13, 18, 9}); XSeries xseries = chart.XValues.AddXSeries(); xseries.Add("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N"); chart.XAxis.MajorTickMark = TickMarkType.Outside; chart.XAxis.Title.Caption = "X-Axis"; chart.YAxis.MajorTickMark = TickMarkType.Outside; chart.YAxis.HasMajorGridlines = true; chart.PlotArea.LineFormat.Color = Colors.DarkGray; chart.PlotArea.LineFormat.Width = 1; document.LastSection.Add(chart); }
public string crearPdf(string[] fotos) { Document document = new Document(); PdfDocument pdfDocument = new PdfDocument(); document.DefaultPageSetup.PageFormat = PageFormat.A4; document.DefaultPageSetup.LeftMargin = "1cm"; document.DefaultPageSetup.TopMargin = "1cm"; setDocumentStyle(ref document); string footerText = "LISTADO DE CODIGO DE BARRAS POR PROPIETARIO CON NIT Y NUMERO DE UNIDAD "; setDocumentHeaders2( ref document, footerText ); foreach (string foto in fotos) { document.LastSection.AddImage(foto); //document.Section.AddImage(foto); //deja codigo de barras por pagina document.AddSection(); //duplica la imagendocument.LastSection.AddImage(foto); } PdfDocumentRenderer pdfDocumentRenderer = new PdfDocumentRenderer(false, PdfFontEmbedding.Always); pdfDocumentRenderer.Document = document; pdfDocumentRenderer.RenderDocument(); string filename = "archivopdf\\ARCHIVO_CODIGO_DE_BARRAS.pdf"; pdfDocumentRenderer.PdfDocument.Save(filename); return filename; }
// [UnitTestFunction] public static void TestParagraph() { Document doc = new Document(); doc.Styles["Heading3"].Font.Color = Color.CadetBlue; Section sec = doc.Sections.AddSection(); Paragraph par = sec.AddParagraph(); par.Style = "Heading4"; par.AddText("A bit "); FormattedText ft = par.AddFormattedText("differently formatted"); ft.Style = "InvalidStyleName"; ft.Font.Size = 40; ft.Font.Name = "Courier New"; //ft.Font.Color = Color.Azure; ft.Font.Bold = true; ft.Font.Italic = true; //ft.Font.Underline = Underline.Dotted; par.AddText(" text."); DocumentRenderer docRndrr = new DocumentRenderer(); docRndrr.Render(doc, "RtfParagraph.txt", null); File.Copy("RtfParagraph.txt", "RtfParagraph.rtf", true); System.Diagnostics.Process.Start("RtfParagraph.rtf"); }
public void CreateDocument(DataTable dt, string filename) { // Create a new MigraDoc document this.document = new Document(); this.document.Info.Title = "A sample invoice"; this.document.Info.Subject = "Demonstrates how to create an invoice."; this.document.Info.Author = "Stefan Lange"; DefineStyles(); CreatePage(); FillContent(dt); // Create a renderer for PDF that uses Unicode font encoding. var pdfRenderer = new PdfDocumentRenderer(true); // Set the MigraDoc document. pdfRenderer.Document = document; // Create the PDF document. pdfRenderer.RenderDocument(); // Save the PDF document... //var filename = "Invoice.pdf"; // I don't want to close the document constantly... //filename = "Invoice-" + Guid.NewGuid().ToString("N").ToUpper() + ".pdf"; pdfRenderer.Save(filename); // ...and start a viewer. //Process.Start(filename); }
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); }
/// <summary> /// Renders <paramref name="control"/> to the <paramref name="document"/>. /// </summary> /// <param name="document">The PDF document.</param> /// <param name="control">The control to be rendered.</param> /// <param name="level">The depth down the control tree being rendered (affects indenting).</param> /// <param name="controlList">The complete control list.</param> protected override void DoRender(Document document, Control control, int level, ControlList controlList) { TextFrame frameTemplate = this.CreateCharacterInputBox(document.Styles[StyleNames.Normal]); Paragraph paragraphTemplate = new Paragraph { Style = StyleNames.Normal, Format = { Alignment = ParagraphAlignment.Justify, Font = { Color = Colors.LightGray } } }; Unit spacer = new Unit((frameTemplate.Width.Point - paragraphTemplate.Format.Font.Size.Point) / 4, UnitType.Point); paragraphTemplate.Format.SpaceBefore = spacer; paragraphTemplate.Format.LeftIndent = spacer; frameTemplate.MarginBottom = frameTemplate.Height; for (int i = 0; i < 8; i++) { TextFrame frame = frameTemplate.Clone(); frame.WrapFormat.DistanceLeft = (frame.Width * i) + (new Unit(PdfConstants.IndentMultiplier * level, UnitType.Millimeter)); string watermark = i < 2 ? "D" : i < 4 ? "M" : "Y"; Paragraph paragraph = paragraphTemplate.Clone(); paragraph.AddText(watermark); frame.Add(paragraph); document.LastSection.Add(frame); } TextFrame clearFrame = frameTemplate.Clone(); clearFrame.WrapFormat.Style = WrapStyle.TopBottom; clearFrame.LineFormat.Width = 0; document.LastSection.Add(clearFrame); }
public static void AddTripSummary(Document document, BookingInfo booking) { Table table = document.LastSection.AddTable(); table.Borders.Visible = true; table.TopPadding = TopPadding; table.BottomPadding = BottomPadding; table.Format.Alignment = ParagraphAlignment.Justify; table.Rows.Height = 1; Column column = table.AddColumn("5cm"); column.Format.Alignment = ParagraphAlignment.Right; column = table.AddColumn("11cm"); column.Format.Alignment = ParagraphAlignment.Left; table.AddTableHeader("TRIP SUMMARY"); table.AddTableRow("City of service:", booking.City, "Normal"); table.AddTableRow("Type of Journey:", booking.TypeOfJourney, "Normal"); table.AddTableRow("Pick-Up Date/Time:", booking.PickUpTime, "NormalBold"); table.AddTableRow("Type of Vehicle:", booking.Vehicle, "Normal"); table.AddTableRow("Pick-Up Location:", booking.PickUp, "NormalBold"); table.AddTableRow("Drop-Off Location:", booking.DropOff, "NormalBold"); if (booking.Stops.Count() > 0) table.AddStopTableRow("Added Stops (" + booking.Stops.Count() + "):", booking.Stops, "Normal"); table.AddTableFooter(""); }
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> /// 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 static Document CreateDocument(string title, string subject) { Document document = new Document(); #region DocInfo document.Info.Title = title; document.Info.Subject = subject; Locales currentLocale = LocalesExtension.LocalesFromString(Thread.CurrentThread.CurrentUICulture.Name); document.Info.Author = "RecruitmentSystem"; #endregion #region DocStyle //Set normal text styles Style style = document.Styles[StyleNames.Normal]; style.Font.Name = "Arial"; //Set header styles style = document.Styles[StyleNames.Header]; style.ParagraphFormat.AddTabStop("16cm", TabAlignment.Right); //Set footer styles style = document.Styles[StyleNames.Footer]; style.ParagraphFormat.AddTabStop("8cm", TabAlignment.Center); //Add table style style = document.Styles.AddStyle("Table", StyleNames.Normal); style.Font.Name = "Arial"; style.Font.Size = 9; #endregion return document; }
public static PdfDocument CreatePdf(string author) { var document = new Document(); var sec = document.Sections.AddSection(); sec.AddParagraph("Author:" + author); return RenderDocument(document); }
static void DemonstrateAlignment(Document document) { document.LastSection.AddParagraph("Alignment", "Heading2"); document.LastSection.AddParagraph("Left Aligned", "Heading3"); Paragraph paragraph = document.LastSection.AddParagraph(); paragraph.Format.Alignment = ParagraphAlignment.Left; paragraph.AddText(FillerText.Text); document.LastSection.AddParagraph("Right Aligned", "Heading3"); paragraph = document.LastSection.AddParagraph(); paragraph.Format.Alignment = ParagraphAlignment.Right; paragraph.AddText(FillerText.Text); document.LastSection.AddParagraph("Centered", "Heading3"); paragraph = document.LastSection.AddParagraph(); paragraph.Format.Alignment = ParagraphAlignment.Center; paragraph.AddText(FillerText.Text); document.LastSection.AddParagraph("Justified", "Heading3"); paragraph = document.LastSection.AddParagraph(); paragraph.Format.Alignment = ParagraphAlignment.Justify; paragraph.AddText(FillerText.MediumText); }
public override Document BuildDocument() { Document retVal = new Document(); Log.Info("Creating findings report"); retVal.Info.Title = "EFS Subset-076 Findings report"; retVal.Info.Author = "ERTMS Solutions"; retVal.Info.Subject = "Subset-076 findings report"; FindingsReport report = new FindingsReport(retVal); if (addReviewed) { report.ReviewedParagraphs = false; BuildSections(report); } if (addNotReviewed) { report.ReviewedParagraphs = true; BuildSections(report); } return retVal; }
static void DemonstrateIndent(Document document) { document.LastSection.AddParagraph("Indent", "Heading2"); document.LastSection.AddParagraph("Left Indent", "Heading3"); Paragraph paragraph = document.LastSection.AddParagraph(); paragraph.Format.LeftIndent = "2cm"; paragraph.AddText(FillerText.Text); document.LastSection.AddParagraph("Right Indent", "Heading3"); paragraph = document.LastSection.AddParagraph(); paragraph.Format.RightIndent = "1in"; paragraph.AddText(FillerText.Text); document.LastSection.AddParagraph("First Line Indent", "Heading3"); paragraph = document.LastSection.AddParagraph(); paragraph.Format.FirstLineIndent = "12mm"; paragraph.AddText(FillerText.Text); document.LastSection.AddParagraph("First Line Negative Indent", "Heading3"); paragraph = document.LastSection.AddParagraph(); paragraph.Format.LeftIndent = "1.5cm"; paragraph.Format.FirstLineIndent = "-1.5cm"; paragraph.AddText(FillerText.Text); }
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 the cover page. /// </summary> public static void DefineTableOfContents(Document document) { Section section = document.LastSection; section.AddPageBreak(); Paragraph paragraph = section.AddParagraph("Table of Contents"); paragraph.Format.Font.Size = 14; paragraph.Format.Font.Bold = true; paragraph.Format.SpaceAfter = 24; paragraph.Format.OutlineLevel = OutlineLevel.Level1; paragraph = section.AddParagraph(); paragraph.Style = "TOC"; Hyperlink hyperlink = paragraph.AddHyperlink("Paragraphs"); hyperlink.AddText("Paragraphs\t"); hyperlink.AddPageRefField("Paragraphs"); paragraph = section.AddParagraph(); paragraph.Style = "TOC"; hyperlink = paragraph.AddHyperlink("Tables"); hyperlink.AddText("Tables\t"); hyperlink.AddPageRefField("Tables"); paragraph = section.AddParagraph(); paragraph.Style = "TOC"; hyperlink = paragraph.AddHyperlink("Charts"); hyperlink.AddText("Charts\t"); hyperlink.AddPageRefField("Charts"); }
// [UnitTestFunction] public static void TestSpecialCharacters() { Document doc = new Document(); Section sec = doc.Sections.AddSection(); Paragraph par = sec.AddParagraph(); par.AddCharacter('\x93'); par.AddCharacter(SymbolName.Blank); par.AddCharacter(SymbolName.Bullet); par.AddCharacter(SymbolName.Copyright); par.AddCharacter(SymbolName.Em); par.AddCharacter(SymbolName.Em4); par.AddCharacter(SymbolName.EmDash); par.AddCharacter(SymbolName.En); par.AddCharacter(SymbolName.EnDash); par.AddCharacter(SymbolName.Euro); par.AddCharacter(SymbolName.HardBlank); par.AddCharacter(SymbolName.LineBreak); par.AddCharacter(SymbolName.Not); par.AddCharacter(SymbolName.ParaBreak); par.AddCharacter(SymbolName.RegisteredTrademark); par.AddCharacter(SymbolName.Tab); par.AddCharacter(SymbolName.Trademark); DocumentRenderer docRndrr = new DocumentRenderer(); docRndrr.Render(doc, "RtfSpecialChars.txt", null); File.Copy("RtfSpecialChars.txt", "RtfSpecialChars.rtf", true); System.Diagnostics.Process.Start("RtfSpecialChars.txt"); }
public static void CellMerge(string outputFile) { Document document = new Document(); Section sec = document.Sections.AddSection(); sec.AddParagraph("A paragraph before."); Table table = sec.AddTable(); table.Borders.Visible = true; table.AddColumn(); table.AddColumn(); Row row = table.AddRow(); Cell cell = row.Cells[0]; cell.MergeRight = 1; cell.Borders.Visible = true; cell.Borders.Left.Width = 8; cell.Borders.Right.Width = 2; cell.AddParagraph("First Cell"); row = table.AddRow(); cell = row.Cells[1]; cell.AddParagraph("Last Cell within this row"); cell.MergeDown = 1; cell.Borders.Bottom.Width = 15; cell.Borders.Right.Width = 30; cell.Shading.Color = Colors.LightBlue; row = table.AddRow(); sec.AddParagraph("A Paragraph afterwards"); PdfPrinter printer = new PdfPrinter(); printer.Document = document; printer.PrintDocument(); printer.PdfDocument.Save(outputFile); }
Document CreateDocument(string strProID, string strProTitle, string strProType, List<RevisionHistory> listRevisionHistory, string strProObjective, string strProAppName, string[] strArrayProDatabase, string[] strArrayProMiddleware, string[] strArrayProPicturePathTopology, string[] strArrayProPicturePathMenuRelation, string[] strArrayProPicturePathDatabaseDiagram, List<Solution> listSolution, string[] strArrayProJobBatch, string[] strArrayProParam, List<Attachment> listAttachment, string strProTestScenario, string strProOtherInfo, List<Approval> listApproval) { Document document = new Document(); document.Info.Title = strProID; document.Info.Subject = strProTitle; document.Info.Author = DataStaging.GetApprovalArrayFromListApproval(listApproval)[0].StrName; DefineStyles(document, FontName, Colors.Black, Colors.White, Colors.Black); DefineTitle(document, strProID, strProTitle, strProType); DefineDocumentChangeControl(document, FontName, Colors.Black, listRevisionHistory); DefineObjectives(document, strProObjective); DefineScope(document, strProAppName, strArrayProDatabase, strArrayProMiddleware); DefineTopology(document, strArrayProPicturePathTopology); DefineMenuRelation(document, strArrayProPicturePathMenuRelation); DefineDatabaseDiagram(document, strArrayProPicturePathDatabaseDiagram); DefineSolution(document, FontName, Colors.Black, listSolution); DefineJobBatch(document, strArrayProJobBatch); DefineParam(document, strArrayProParam); DefineAttachment(document, listAttachment); DefineTestScenario(document, strProTestScenario); DefineOtherInfo(document, strProOtherInfo); DefineApproval(document, FontName, Colors.Black, listApproval); return document; }
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); }
/// <summary> /// Render a document in PDF format /// </summary> public PdfDocument RenderPDF(MigraDoc.DocumentObjectModel.Document document) { this.renderer.Document = document; this.renderer.RenderDocument(); return(this.renderer.PdfDocument); }
//public GeneratePDFResults(List<Student> students) //{ // Document doc = Document(students); //} public Document GenerateResults(IList <Student> students) { this.document = new MigraDoc.DocumentObjectModel.Document(); this.document.Info.Title = "Faculty Admission Results"; DefineStyles(); CreatePage(students); return(this.document); }
private static Document InitializePDFDocument(int columnNumber, out Unit availableWidth, out Unit availableColumnWidth, bool orientationPDF, bool groupmode = false, bool includeAggregateColumn = false) { //create Document setup var document = new MigraDoc.DocumentObjectModel.Document(); if (!orientationPDF) { document.DefaultPageSetup.Orientation = Orientation.Landscape; } else { document.DefaultPageSetup.Orientation = Orientation.Portrait; } document.DefaultPageSetup.PageFormat = PageFormat.A4; document.DefaultPageSetup.LeftMargin = Unit.FromCentimeter(2); document.DefaultPageSetup.TopMargin = Unit.FromCentimeter(1); //calculate the static width of each column if (!includeAggregateColumn) { if (!orientationPDF) { availableWidth = document.DefaultPageSetup.PageHeight - (document.DefaultPageSetup.LeftMargin * 2); } else { availableWidth = document.DefaultPageSetup.PageWidth - (document.DefaultPageSetup.LeftMargin * 2); } } else //include aggregate column { //We multiply more than 2 (for each margin (left, right)) including the fixed width of the aggregate column /*In groupMode the aggregate column has width equal with other columns due to dynamic item(s) * without groupmode column is autofit so we multiply with 2,7 */ if (!orientationPDF) { availableWidth = document.DefaultPageSetup.PageHeight - (document.DefaultPageSetup.LeftMargin * ((groupmode) ? 2 : 2.7));//No prtrait } else { availableWidth = document.DefaultPageSetup.PageWidth - (document.DefaultPageSetup.LeftMargin * ((groupmode) ? 2 : 2.7)); } } availableWidth.ConvertType(UnitType.Centimeter); availableColumnWidth = availableWidth / (columnNumber); availableColumnWidth.ConvertType(UnitType.Centimeter); return(document); }
static void Main(string[] args) { // Create a MigraDoc document. var document = CreateDocument(); #if DEBUG MigraDoc.DocumentObjectModel.IO.Xml.DdlWriter.WriteToFile(document, "MigraDoc.xml"); MigraDoc.DocumentObjectModel.Document document3 = null; using (StreamReader sr = File.OpenText("MigraDoc.xml")) { var errors = new MigraDoc.DocumentObjectModel.IO.DdlReaderErrors(); var reader = new MigraDoc.DocumentObjectModel.IO.Xml.DdlReader(sr, errors); document3 = reader.ReadDocument(); using (StreamWriter sw = new StreamWriter("MigraDoc.xml.error")) { foreach (MigraDoc.DocumentObjectModel.IO.DdlReaderError error in errors) { sw.WriteLine("{0}:{1} {2} {3}", error.SourceLine, error.SourceColumn, error.ErrorLevel, error.ErrorMessage); } } } #endif // ----- Unicode encoding and font program embedding in MigraDoc is demonstrated here. ----- // A flag indicating whether to create a Unicode PDF or a WinAnsi PDF file. // This setting applies to all fonts used in the PDF document. // This setting has no effect on the RTF renderer. const bool unicode = true; // Create a renderer for the MigraDoc document. var pdfRenderer = new PdfDocumentRenderer(unicode); // Associate the MigraDoc document with a renderer. pdfRenderer.Document = document3; // Layout and render document to PDF. pdfRenderer.RenderDocument(); // Save the document... const string filename = "HelloWorld.pdf"; pdfRenderer.PdfDocument.Save(filename); // ...and start a viewer. Process.Start(filename); }
/// <summary> /// Creates the invoice document. /// </summary> public Document CreateDocument() { // Create a new MigraDoc document this.document = new Document(); this.document.Info.Title = ""; this.document.Info.Subject = ""; this.document.Info.Author = "Aftab"; DefineStyles(); CreatePage(); FillContent(); return(this.document); }
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 }
private void butPrint_Click(object sender, EventArgs e) { MigraDoc.DocumentObjectModel.Document doc = CreatePrintDocument(); 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(); pView.printPreviewControl2.Document = printdoc; pView.ShowDialog(); #else //Always prints to the Windows default printer. if (PrinterL.SetPrinter(pd2, PrintSituation.Default, 0, "Reconcile list printed")) { printdoc.Print(); } #endif }
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); }
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 }
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); } }
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); } }
public PdfRendererVisitor(InterpreterContext context, PdfDocumentContext documentContext, object model = null) : base(context, model) { _documentContext = documentContext; _document = new PdfDocument(); }
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); } }
///<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 Timer_tick(object sender, ElapsedEventArgs e) { SwiftConfClass.WriteAppLogs("<<<<<>>>>>> THIS MESSAGE PASS TO SYSTEM AFTER 10 MIN <<<<<>>>>>"); //create a data store--- DataTable FileData_tbl = new DataTable(); FileData_tbl.Columns.Add("FileName", typeof(string)); DataRow row = FileData_tbl.NewRow(); //---------------------- //Date format DateTime dt = DateTime.Now; string month = DateTime.Now.Month.ToString(); int MonthConvert = Int16.Parse(month); int PerMonth = MonthConvert; string monthName = (CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(PerMonth)).ToLower(); string dateFormat = "swift_" + DateTime.Now.Year + "_" + monthName.Substring(0, 3) + "_" + DateTime.Now.Day; DirectoryInfo dir = new DirectoryInfo(@"\\192.168.201.6\telex\Telex_pending");// FileInfo[] Files = dir.GetFiles("*.out"); foreach (FileInfo file in Files) { string[] separatingStrings = { "{1:" }; string contents = File.ReadAllText(@"\\192.168.201.6\telex\Telex_pending\" + file.Name); string[] words = contents.Split(separatingStrings, System.StringSplitOptions.RemoveEmptyEntries); string FolderName = file.Name.Substring(1, 8); FileData_tbl.Rows.Add(FolderName); //---------------------------------- for (int i = 0; i <= words.Length - 1; i++) { string strVal = words[i]; //COPY STRVALTO I.TXT AND SAVE Directory.CreateDirectory(@"\\192.168.201.6\Telex\" + dateFormat + @"\" + FolderName); File.WriteAllText(@"\\192.168.201.6\Telex\" + dateFormat + @"\" + FolderName + @"\" + i + ".txt", "{1:" + strVal); //EMPTY STRVAL FOR NEXT VALUE strVal = String.Empty; } try { File.Move(@"\\192.168.201.6\telex\Telex_pending\" + file.Name, @"\\192.168.201.6\Telex\Processed\" + file.Name); } catch (Exception exc) { if (exc.Message.Contains("Cannot create a file when that file already exists")) { SwiftConfClass.WriteAppLogs(string.Format("file: {0} already exist in processed folder. moving to duplicate folder ...", file.Name)); try { File.Move(@"\\192.168.201.6\Telex\" + file.Name, @"\\192.168.201.6\Telex\Processed\duplicate\" + file.Name); } catch (Exception _exc) { if (exc.Message.Contains("Cannot create a file when that file already exists")) { SwiftConfClass.WriteAppLogs(string.Format("file: {0} already exist in duplicate folder. deleting the file ...", file.Name)); file.Delete(); return; } else { SwiftConfClass.WriteAppLogs(_exc.Message); } } return; } else { SwiftConfClass.WriteAppLogs(exc.Message); } } File.Delete(@"\\192.168.201.6\Telex\" + dateFormat + @"\" + FolderName + @"\0.txt"); }//ENDOFFOREEACH //----------------------------------------------- //step #2 foreach (DataRow dr in FileData_tbl.Rows) { //FIND NUMBER OF FILE IN A DIRECTORY string path = @"\\192.168.201.6\Telex\" + dateFormat + @"\" + dr["FileName"].ToString(); int fCount = Directory.GetFiles(path, "*", SearchOption.TopDirectoryOnly).Length; SwiftConfClass.WriteAppLogs("<<< FILE " + dr["FileName"].ToString() + "out" + " IS PROGRESSING >>>"); //-----------------------WHEN THERE IS A FILE (only on file)--------------------------- if (fCount < 2) { //------------------------------------ //string RectDeclimator = "{2:"; string RecString = File.ReadAllText(@"\\192.168.201.6\Telex\" + dateFormat + @"\" + dr["FileName"].ToString() + @"\1.txt"); //int RecIndex = RecString.LastIndexOf(RectDeclimator); int MT103position = RecString.IndexOf("I103"); string bic_code = RecString.Substring(MT103position + 4, 11); //------------------------------------READ BANK NAME FROM FLEXCUBE---------------------------- if (con == null || con.State != ConnectionState.Open) { con.Open(); } // string queryR = "SELECT bank_name FROM fccprod.ISTM_BIC_DIRECTORY@fc WHERE bic_code like '" + bic_code + "'"; OracleCommand cmdR = new OracleCommand(queryR, con); OracleDataReader datardR = cmdR.ExecuteReader(); DataTable Bank_name_dataTbl = new DataTable(); Bank_name_dataTbl.Load(datardR); foreach (DataRow dtrow in Bank_name_dataTbl.Rows) { BankName = dtrow["bank_name"].ToString(); } //------------------------------------- string accountDeclimator = ":50K:/"; string accountString = File.ReadAllText(@"\\192.168.201.6\Telex\" + dateFormat + @"\" + dr["FileName"].ToString() + @"\1.txt"); int accIndex = accountString.LastIndexOf(accountDeclimator); string account = accountString.Substring(accIndex + 6, 16); //------------------------------------- string murDeclimator = "{108:"; string murString = File.ReadAllText(@"\\192.168.201.6\Telex\" + dateFormat + @"\" + dr["FileName"].ToString() + @"\1.txt"); int murIndex = murString.LastIndexOf(murDeclimator); string mur = murString.Substring(murIndex + 5, 16); //------------------------------FIND UTER------------------------------------------- string uterDeclimator = "{121:"; string uterString = File.ReadAllText(@"\\192.168.201.6\Telex\" + dateFormat + @"\" + dr["FileName"].ToString() + @"\1.txt"); int uterIndex = uterString.LastIndexOf(uterDeclimator); string uter = uterString.Substring(uterIndex + 5, 36); //--------------------------------------------------------------------------- cust_no = account.Substring(7, 7); if (con == null || con.State != ConnectionState.Open) { con.Open(); } string query = "SELECT * from fccprod.sttm_customer@fc WHERE customer_no ='" + cust_no + "'"; OracleCommand cmd = new OracleCommand(query, con); OracleDataReader datard = cmd.ExecuteReader(); DataTable udf_3_dataTbl = new DataTable(); udf_3_dataTbl.Load(datard); foreach (DataRow dtrow in udf_3_dataTbl.Rows) { CustomeEmail = dtrow["udf_3"].ToString(); } path = @"\\192.168.201.6\Telex\" + dateFormat + @"\" + dr["FileName"].ToString() + @"\1.txt"; //generate pdf file string LongMessage; using (var streamReader = new StreamReader(path)) { LongMessage = streamReader.ReadToEnd(); } string emailBody = Environment.NewLine + "<<<< Message Header >>>>" + Environment.NewLine + "_ _ _ _ __ _ _ _ __ _ _ _ __ _ _ _ __ _ _ _ __ _ _ _ __ _ _ _ __ _ _ _ __ _ _" + Environment.NewLine + Environment.NewLine + "SWIFT INPUT: FIN 103 Single Customer Credit Trasfer" + Environment.NewLine + Environment.NewLine + " AFBIBAFKAXXX " + Environment.NewLine + Environment.NewLine + Environment.NewLine + " AFGHANISTAN INTERNATIONAL BANK - KABUL" + Environment.NewLine + Environment.NewLine + Environment.NewLine + "_ _ _ _ __ _ _ _ __ _ _ _ __ _ _ _ __ _ _ _ __ _ _ _ __ _ _ _ __ _ _ _ __ _ _" + Environment.NewLine + Environment.NewLine + "Reciever: '" + bic_code + "'" + Environment.NewLine + " '" + BankName + "'" + Environment.NewLine + "MUR: '" + mur + "'" + Environment.NewLine + "UETR: '" + uter + "'" + Environment.NewLine + Environment.NewLine + Environment.NewLine + "<<<< MESSAGE TEXT >>>>" + Environment.NewLine + "_ _ _ _ __ _ _ _ __ _ _ _ __ _ _ _ __ _ _ _ __ _ _ _ __ _ _ _ __ _ _ _ __ _ _" + Environment.NewLine + Environment.NewLine + LongMessage + Environment.NewLine + "_ _ _ _ __ _ _ _ __ _ _ _ __ _ _ _ __ _ _ _ __ _ _ _ __ _ _ _ __ _ _ _ __ _ _" + Environment.NewLine + Environment.NewLine + "Thank you for using AIB" + Environment.NewLine + DateTime.Today.ToLongDateString(); MigraDoc.DocumentObjectModel.Document document = CreateDocument(emailBody); document.UseCmykColor = true; const bool unicode = false; // const PdfFontEmbedding embedding = PdfFontEmbedding.Always; PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(unicode); pdfRenderer.Document = document; pdfRenderer.RenderDocument(); // Save the document... string filename = @"\\192.168.201.6\Telex\pdf\" + @"\" + uter + ".pdf"; try { pdfRenderer.PdfDocument.Save(filename); } catch (Exception _exc) { SwiftConfClass.WriteAppLogs(_exc.Message); } //-----------------------------------EMAIL sending portion------------------------------------------------- string Msg = SwiftConfClass.PopulateBody(path, account, uter, mur); path = String.Empty; //SendEmail(ToEmail, Subj, Message, account, uetr, mur,address,account) SwiftConfClass.SendEmail(CustomeEmail, "SWIFT Confirmation", Msg, mur, filename, account, dr["FileName"].ToString()); //-------------------------------------- } // end of if(file<2) else { // I WILL WORK ON IT SOON //Step #1 count number of file in the folder for (int i = 1; i <= fCount; i++) { string RecString = File.ReadAllText(@"\\192.168.201.6\Telex\" + dateFormat + @"\" + dr["FileName"].ToString() + @"\" + i + ".txt"); //int RecIndex = RecString.LastIndexOf(RectDeclimator); int MT103position = RecString.IndexOf("I103"); string bic_code = RecString.Substring(MT103position + 4, 8); //------------------------------------READ BANK NAME FROM FLEXCUBE---------------------------- if (con == null || con.State != ConnectionState.Open) { con.Open(); } // string queryR = "select bank_name from fccprod.ISTM_BIC_DIRECTORY@fc where bic_code like '%" + bic_code + "%'"; OracleCommand cmdR = new OracleCommand(queryR, con); OracleDataReader datardR = cmdR.ExecuteReader(); DataTable Bank_name_dataTbl = new DataTable(); Bank_name_dataTbl.Load(datardR); foreach (DataRow dtrow in Bank_name_dataTbl.Rows) { BankName = dtrow["bank_name"].ToString(); } //------------------------------------------------------- string accountDeclimator = ":50K:/"; string accountString = File.ReadAllText(@"\\192.168.201.6\Telex\" + dateFormat + @"\" + dr["FileName"].ToString() + @"\" + i + ".txt"); int accIndex = accountString.LastIndexOf(accountDeclimator); string account = accountString.Substring(accIndex + 6, 16); //------------------------------------- string murDeclimator = "{108:"; string murString = File.ReadAllText(@"\\192.168.201.6\Telex\" + dateFormat + @"\" + dr["FileName"].ToString() + @"\" + i + ".txt"); int murIndex = murString.LastIndexOf(murDeclimator); string mur = murString.Substring(murIndex + 5, 16); //------------------------------FIND UTER------------------------------------------- string uterDeclimator = "{121:"; string uterString = File.ReadAllText(@"\\192.168.201.6\Telex\" + dateFormat + @"\" + dr["FileName"].ToString() + @"\" + i + ".txt"); int uterIndex = uterString.LastIndexOf(uterDeclimator); string uter = uterString.Substring(uterIndex + 5, 36); cust_no = account.Substring(7, 7); //------------------------------------------------- if (con == null || con.State != ConnectionState.Open) { con.Open(); } string query = "SELECT * from fccprod.sttm_customer@fc where customer_no ='" + cust_no + "'"; // string query = "select UDF_3 from sttm_cust_account@fc where upper(ac_desc) like '%" + txtSearch.Text.ToUpper() + "%'"; OracleCommand cmd = new OracleCommand(query, con); OracleDataReader datard = cmd.ExecuteReader(); DataTable udf_3_dataTbl = new DataTable(); udf_3_dataTbl.Load(datard); foreach (DataRow dtrow in udf_3_dataTbl.Rows) { CustomeEmail = dtrow["udf_3"].ToString(); } path = @"\\192.168.201.6\Telex\" + dateFormat + @"\" + dr["FileName"].ToString() + @"\" + i + ".txt"; //generate pdf file string LongMessage; using (var streamReader = new StreamReader(path)) { LongMessage = streamReader.ReadToEnd(); } string emailBody = Environment.NewLine + "<<< Message Header >>>" + Environment.NewLine + "_ _ _ _ __ _ _ _ __ _ _ _ __ _ _ _ __ _ _ _ __ _ _ _ __ _ _ _ __ _ _ _ __ _ _" + Environment.NewLine + Environment.NewLine + "SWIFT INPUT: FIN 103 Single Customer Credit Trasfer" + Environment.NewLine + Environment.NewLine + " AFBIBAFKAXXX " + Environment.NewLine + Environment.NewLine + Environment.NewLine + " AFGHANISTAN INTERNATIONAL BANK - KABUL" + Environment.NewLine + Environment.NewLine + Environment.NewLine + "_ _ _ _ __ _ _ _ __ _ _ _ __ _ _ _ __ _ _ _ __ _ _ _ __ _ _ _ __ _ _ _ __ _ _" + Environment.NewLine + "Reciever: '" + bic_code + "'" + Environment.NewLine + " '" + BankName + "'" + Environment.NewLine + "MUR: '" + mur + "'" + Environment.NewLine + "UETR: '" + uter + "'" + Environment.NewLine + Environment.NewLine + Environment.NewLine + "<<< MESSAGE TEXT >>>" + Environment.NewLine + "_ _ _ _ __ _ _ _ __ _ _ _ __ _ _ _ __ _ _ _ __ _ _ _ __ _ _ _ __ _ _ _ __ _ _ " + Environment.NewLine + Environment.NewLine + "{1:" + LongMessage + Environment.NewLine + "_ _ _ _ __ _ _ _ __ _ _ _ __ _ _ _ __ _ _ _ __ _ _ _ __ _ _ _ __ _ _ _ __ _ _" + Environment.NewLine + Environment.NewLine + "Thank you for using AIB" + Environment.NewLine + DateTime.Today.ToLongDateString(); MigraDoc.DocumentObjectModel.Document document = CreateDocument(emailBody); document.UseCmykColor = true; const bool unicode = false; // const PdfFontEmbedding embedding = PdfFontEmbedding.Always; PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(unicode); pdfRenderer.Document = document; pdfRenderer.RenderDocument(); // Save the document... string filename = @"\\192.168.201.6\Telex\pdf\" + @"\" + uter + ".pdf"; try { pdfRenderer.PdfDocument.Save(filename); } catch (Exception _exc) { SwiftConfClass.WriteAppLogs(_exc.Message); } //-----------------------------------EMAIL sending portion------------------------------------------------- string Msg = SwiftConfClass.PopulateBody(path, account, uter, mur); path = String.Empty; //SendEmail(ToEmail, Subj, Message, account, uetr, mur,address,account)// prototype SwiftConfClass.SendEmail(CustomeEmail, "SWIFT Confirmation", Msg, mur, filename, account, dr["FileName"].ToString()); }// } } }
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); }
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); }
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(); } }
/// <summary> /// Add MigraDoc styles. /// </summary> /// <param name="doc">The document to add the styles to.</param> private static void AddStylesToDoc(MigraDoc.DocumentObjectModel.Document doc) { var body = doc.Styles["Normal"]; body.Font.Size = MigraDoc.DocumentObjectModel.Unit.FromPoint(10); if (doc.Styles["TableText"] == null) { var tableTextStyle = doc.AddStyle("TableText", "Normal"); // tableTextStyle.ParagraphFormat.LineSpacing = 0; tableTextStyle.ParagraphFormat.SpaceAfter = 5; } body.ParagraphFormat.LineSpacingRule = MigraDoc.DocumentObjectModel.LineSpacingRule.Multiple; body.ParagraphFormat.LineSpacing = 1.0; body.ParagraphFormat.SpaceAfter = 10; var footer = doc.Styles["Footer"]; footer.Font.Size = MigraDoc.DocumentObjectModel.Unit.FromPoint(9); var h1 = doc.Styles["Heading1"]; h1.Font.Bold = true; h1.Font.Size = MigraDoc.DocumentObjectModel.Unit.FromPoint(15); h1.ParagraphFormat.SpaceBefore = 0; var h2 = doc.Styles["Heading2"]; h2.Font.Bold = true; h2.Font.Size = MigraDoc.DocumentObjectModel.Unit.FromPoint(13); h2.ParagraphFormat.SpaceBefore = 0; var h3 = doc.Styles["Heading3"]; h3.Font.Bold = true; h3.Font.Size = MigraDoc.DocumentObjectModel.Unit.FromPoint(11); h3.ParagraphFormat.SpaceBefore = 0; var h4 = doc.Styles["Heading4"]; h4.Font.Bold = true; h4.Font.Size = MigraDoc.DocumentObjectModel.Unit.FromPoint(10); h4.ParagraphFormat.SpaceBefore = 0; var h5 = doc.Styles["Heading5"]; h5.Font.Bold = true; h5.Font.Size = MigraDoc.DocumentObjectModel.Unit.FromPoint(9); h5.ParagraphFormat.SpaceBefore = 0; var h6 = doc.Styles["Heading6"]; h6.Font.Bold = true; h6.Font.Size = MigraDoc.DocumentObjectModel.Unit.FromPoint(9); h6.ParagraphFormat.SpaceBefore = 0; var links = doc.Styles["Hyperlink"]; links.Font.Color = MigraDoc.DocumentObjectModel.Colors.Blue; if (doc.Styles["ListEnd"] == null) { var unorderedlist = doc.AddStyle("ListStart", "Normal"); unorderedlist.ParagraphFormat.SpaceAfter = 0; } if (doc.Styles["UnorderedList"] == null) { var unorderedlist = doc.AddStyle("UnorderedList", "Normal"); var listInfo = new MigraDoc.DocumentObjectModel.ListInfo(); listInfo.ListType = MigraDoc.DocumentObjectModel.ListType.BulletList1; unorderedlist.ParagraphFormat.ListInfo = listInfo; unorderedlist.ParagraphFormat.LeftIndent = "1cm"; unorderedlist.ParagraphFormat.FirstLineIndent = "-0.5cm"; unorderedlist.ParagraphFormat.SpaceAfter = 0; } if (doc.Styles["OrderedList"] == null) { var orderedlist = doc.AddStyle("OrderedList", "UnorderedList"); orderedlist.ParagraphFormat.ListInfo.ListType = MigraDoc.DocumentObjectModel.ListType.NumberList1; orderedlist.ParagraphFormat.LeftIndent = "1cm"; orderedlist.ParagraphFormat.FirstLineIndent = "-0.5cm"; orderedlist.ParagraphFormat.SpaceAfter = 0; } if (doc.Styles["ListEnd"] == null) { var unorderedlist = doc.AddStyle("ListEnd", "Normal"); unorderedlist.ParagraphFormat.SpaceAfter = 0; } if (doc.Styles["HorizontalRule"] == null) { var hr = doc.AddStyle("HorizontalRule", "Normal"); var hrBorder = new MigraDoc.DocumentObjectModel.Border(); hrBorder.Width = "1pt"; hrBorder.Color = MigraDoc.DocumentObjectModel.Colors.DarkGray; hr.ParagraphFormat.Borders.Bottom = hrBorder; hr.ParagraphFormat.LineSpacing = 0; hr.ParagraphFormat.SpaceBefore = 15; } if (doc.Styles["TableParagraph"] == null) { var style = doc.Styles.AddStyle("TableParagraph", "Normal"); style.Font.Size = 8; style.ParagraphFormat.SpaceAfter = Unit.FromCentimeter(0); style.Font = new MigraDoc.DocumentObjectModel.Font("Courier New"); } }