// [UnitTestFunction] public static void TestSection() { Document doc = new Document(); Section sec = doc.AddSection(); Table tbl = sec.AddTable(); tbl.AddColumn(); Row rw = tbl.AddRow(); rw.Cells[0].AddParagraph("Table 1"); sec = doc.AddSection(); tbl = sec.AddTable(); tbl.AddColumn(); rw = tbl.AddRow(); rw.Cells[0].AddParagraph("Table 2"); DocumentRenderer docRndrr = new DocumentRenderer(); docRndrr.Render(doc, "RtfSection.txt", null); File.Copy("RtfSection.txt", "RtfSection.rtf", true); System.Diagnostics.Process.Start("RtfSection.txt"); DdlWriter.WriteToFile(doc, "RtfSection.mdddl"); }
public static void TestVermögensverwaltung() { Document doc = DocumentObjectModel.IO.DdlReader.DocumentFromFile("Vermögensverwaltung.mdddl"); //, null); DocumentRenderer docRndrr = new DocumentRenderer(); docRndrr.Render(doc, "RtfVermögensverwaltung.txt", null); File.Copy("RtfVermögensverwaltung.txt", "RtfVermögensverwaltung.rtf", true); System.Diagnostics.Process.Start("RtfVermögensverwaltung.txt"); DdlWriter.WriteToFile(doc, "RtfVermögensverwaltung.mdddl"); }
// [UnitTestFunction] public static void TestImage() { Document doc = new Document(); doc.AddSection().AddImage("logo.jpg").ScaleHeight = 0.5f; DocumentRenderer docRndrr = new DocumentRenderer(); docRndrr.Render(doc, "RtfImage.txt", null); File.Copy("RtfImage.txt", "RtfImage.rtf", true); System.Diagnostics.Process.Start("RtfImage.txt"); DdlWriter.WriteToFile(doc, "RtfImage.mdddl"); }
//[UnitTestFunction] public static void TestImagePath() { Document doc = new Document(); doc.ImagePath = "Images"; doc.Sections.AddSection().AddImage("logo.gif"); DocumentRenderer docRndrr = new DocumentRenderer(); docRndrr.Render(doc, "RtfImagePath.txt", null); File.Copy("RtfImagePath.txt", "RtfImagePath.rtf", true); System.Diagnostics.Process.Start("RtfImagePath.txt"); DdlWriter.WriteToFile(doc, "RtfImagePath.mdddl"); }
protected void SaveDocument(string migraDocName, string fileName) { DdlWriter.WriteToFile(_document, migraDocName); PdfDocumentRenderer renderer = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.Always); renderer.Document = _document; renderer.RenderDocument(); // string filename = "HelloMigraDoc.pdf"; renderer.PdfDocument.Save(fileName); }
// [UnitTestFunction] public static void TestInvalidStyle() { Document doc = new Document(); Section sec = doc.Sections.AddSection(); Paragraph par = sec.AddParagraph(); par.AddFormattedText("text", "_invalid_"); DocumentRenderer docRndrr = new DocumentRenderer(); docRndrr.Render(doc, "RtfInvalidStyle.txt", null); File.Copy("RtfInvalidStyle.txt", "RtfInvalidStyle.rtf", true); System.Diagnostics.Process.Start("RtfInvalidStyle.txt", null); DdlWriter.WriteToFile(doc, "RtfInvalidStyle.mdddl"); }
// [UnitTestFunction] public static void TestCharacterStyleAsParagraphStyle() { Document doc = new Document(); doc.Styles.AddStyle("charstyle", Style.DefaultParagraphFontName).Font.Italic = true; Section sec = doc.Sections.AddSection(); sec.AddParagraph("CharStyle").Style = "charstyle"; DocumentRenderer docRndrr = new DocumentRenderer(); docRndrr.Render(doc, "RtfCharacterStyleAsParagraphStyle.txt", null); File.Copy("RtfCharacterStyleAsParagraphStyle.txt", "RtfCharacterStyleAsParagraphStyle.rtf", true); System.Diagnostics.Process.Start("RtfCharacterStyleAsParagraphStyle.txt"); DdlWriter.WriteToFile(doc, "RtfCharacterStyleAsParagraphStyle.mdddl"); }
//[UnitTestFunction] public static void TestBorderDistances() { Document doc = new Document(); Section sec = doc.Sections.AddSection(); Paragraph par = sec.AddParagraph("left dist = 10"); par.Format.Borders.DistanceFromLeft = 10; DocumentRenderer docRndrr = new DocumentRenderer(); docRndrr.Render(doc, "RtfBorderDistances.txt", null); File.Copy("RtfBorderDistances.txt", "RtfBorderDistances.rtf", true); System.Diagnostics.Process.Start("RtfBorderDistances.txt"); DdlWriter.WriteToFile(doc, "RtfBorderDistances.mdddl"); }
// [UnitTestFunction] public static void TestRowHeight() { Document doc = new Document(); Section sec = doc.Sections.AddSection(); Table tbl = sec.AddTable(); tbl.AddColumn(); tbl.Rows.Height = 40; tbl.Rows.AddRow(); tbl.Borders.Visible = true; DocumentRenderer docRndrr = new DocumentRenderer(); docRndrr.Render(doc, "RtfRowHeight.txt", null); File.Copy("RtfRowHeight.txt", "RtfRowHeight.rtf", true); System.Diagnostics.Process.Start("RtfRowHeight.txt"); DdlWriter.WriteToFile(doc, "RtfRowHeight.mdddl"); }
// [UnitTestFunction] public static void TestHeaderParagraphStyle() { Document doc = new Document(); Style myHdrStl = doc.Styles.AddStyle("MyHeaderStyle", "Normal"); myHdrStl.ParagraphFormat.TabStops.AddTabStop("10cm"); Paragraph par = doc.AddSection().Headers.Primary.AddParagraph(); par.Style = "MyHeaderStyle"; par.Elements.AddTab(); par.Elements.AddText("Hallo"); DocumentRenderer docRndrr = new DocumentRenderer(); docRndrr.Render(doc, "RtfHeaderParagraphStyle.txt", null); File.Copy("RtfHeaderParagraphStyle.txt", "RtfHeaderParagraphStyle.rtf", true); System.Diagnostics.Process.Start("RtfHeaderParagraphStyle.txt"); DdlWriter.WriteToFile(doc, "RtfHeaderParagraphStyle.mdddl"); }
// [UnitTestFunction] public static void TestVerticalAlign() { Document doc = new Document(); Section sec = doc.Sections.AddSection(); Table tbl = sec.AddTable(); tbl.AddColumn(); tbl.Rows.Height = 40; tbl.Rows.AddRow().VerticalAlignment = VerticalAlignment.Bottom; tbl[0, 0].AddParagraph("Text"); tbl.Borders.Visible = true; DocumentRenderer docRndrr = new DocumentRenderer(); docRndrr.Render(doc, "RtfVerticalAlign.txt", null); File.Copy("RtfVerticalAlign.txt", "RtfVerticalAlign.rtf", true); System.Diagnostics.Process.Start("RtfVerticalAlign.txt"); DdlWriter.WriteToFile(doc, "RtfVerticalAlign.mdddl"); }
// [UnitTestFunction] public static void TestPageFormat() { Document doc = new Document(); Section sec1 = doc.Sections.AddSection(); sec1.PageSetup.PageFormat = PageFormat.A4; sec1.AddParagraph("PageFormat a4"); Section sec2 = doc.Sections.AddSection(); sec2.PageSetup.PageFormat = PageFormat.A6; sec2.PageSetup.Orientation = Orientation.Landscape; DocumentRenderer docRndrr = new DocumentRenderer(); docRndrr.Render(doc, "RtfPageFormat.txt", null); File.Copy("RtfPageFormat.txt", "RtfPageFormat.rtf", true); System.Diagnostics.Process.Start("RtfPageFormat.txt"); DdlWriter.WriteToFile(doc, "RtfPageFormat.mdddl"); }
// [UnitTestFunction] public static void TestTextFramePos() { Document doc = new Document(); Section sec = doc.Sections.AddSection(); sec.AddParagraph("paragraphBefore"); TextFrame txtFrm = sec.AddTextFrame(); txtFrm.RelativeHorizontal = RelativeHorizontal.Page; txtFrm.WrapFormat.Style = WrapStyle.Through; txtFrm.WrapFormat.DistanceRight = "5cm"; txtFrm.Left = ShapePosition.Right; sec.AddParagraph("paragraphAfter"); DocumentRenderer docRndrr = new DocumentRenderer(); docRndrr.Render(doc, "RtfTextFramePos.txt", null); File.Copy("RtfTextFramePos.txt", "RtfTextFramePos.rtf", true); System.Diagnostics.Process.Start("RtfTextFramePos.txt"); DdlWriter.WriteToFile(doc, "RtfTextFramePos.mdddl"); }
public bool SavePdfDocument(Document document, string path, string filename) { if (document == null) { throw new ArgumentNullException("Document cannot be null"); } if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException("Path cannot be null or empty"); } if (string.IsNullOrEmpty(filename)) { throw new ArgumentNullException("Filename cannot be null or empty"); } try { string fullPath = GetFullPath(path, filename); DdlWriter.WriteToFile(document, "MigraDoc.mdddl"); PdfDocumentRenderer renderer = new PdfDocumentRenderer(true, PdfSharp1_32.Pdf.PdfFontEmbedding.Always); renderer.Document = document; renderer.RenderDocument(); renderer.PdfDocument.Save(fullPath); return(true); } catch (Exception) { return(false); } }
// [UnitTestFunction] public static void Test() { Document doc = new Document(); Style styl = doc.AddStyle("TestStyle1", Style.DefaultParagraphFontName); styl.Font.Bold = true; Section sec = doc.AddSection(); sec.PageSetup.PageHeight = "30cm"; sec.Headers.FirstPage.Format.Font.Bold = true; sec.Headers.Primary.AddParagraph("This is the Primary Header."); sec.Headers.FirstPage.AddParagraph("This is the First Page Header."); sec.Headers.EvenPage.AddParagraph("This is the Even Page Header."); Paragraph par = sec.AddParagraph("Paragraph 1"); // par.Style = "TestStyle1"; par.Format.ListInfo.NumberPosition = 2; par = sec.AddParagraph("Paragraph 2"); par.Format.ListInfo.ListType = ListType.BulletList3; Image img1 = par.AddImage("logo.gif"); // Image img1 = par.AddImage("tick_green.png"); img1.ScaleHeight = 5; img1.ScaleWidth = 2; img1.Height = "0.3cm"; img1.Width = "5cm"; img1.PictureFormat.CropLeft = "-2cm"; img1.FillFormat.Color = Color.PowderBlue; img1.LineFormat.Width = 2; par = sec.AddParagraph("Paragraph 3"); par.AddLineBreak(); par.Format.ListInfo.NumberPosition = 2; TextFrame tf = sec.AddTextFrame(); tf.WrapFormat.Style = WrapStyle.None; tf.RelativeHorizontal = RelativeHorizontal.Page; tf.RelativeVertical = RelativeVertical.Page; tf.Top = Unit.FromCm(2); tf.Left = ShapePosition.Center; tf.Height = "20cm"; tf.Width = "10cm"; tf.FillFormat.Color = Color.LemonChiffon; tf.LineFormat.Color = Color.BlueViolet; tf.LineFormat.DashStyle = DashStyle.DashDotDot; tf.LineFormat.Width = 2; tf.AddParagraph("in a text frame"); tf.MarginTop = "3cm"; tf.Orientation = TextOrientation.Downward; Image img = sec.AddImage("test1.jpg"); img.ScaleHeight = 500; img.ScaleWidth = 200; img.Height = "10cm"; img.Width = "10cm"; img.PictureFormat.CropLeft = "-2cm"; img.FillFormat.Color = Color.LawnGreen; img.LineFormat.Width = 3; img.WrapFormat.Style = WrapStyle.None; sec = doc.AddSection();//.AddParagraph("test"); sec.PageSetup.PageWidth = "30cm"; sec.AddParagraph("Section 2"); DocumentRenderer docRenderer = new DocumentRenderer(); docRenderer.Render(doc, "RtfListInfo.txt", null); DdlWriter.WriteToFile(doc, "RtfListInfo.mdddl"); System.IO.File.Copy("RtfListInfo.txt", "RtfListInfo.rtf", true); System.Diagnostics.Process.Start("RtfListInfo.txt"); }