private void OpenDDL_Click(object sender, RoutedEventArgs e) { OpenFileDialog dialog = null; try { dialog = new OpenFileDialog(); dialog.CheckFileExists = true; dialog.CheckPathExists = true; dialog.Filter = "MigraDoc DDL (*.mdddl)|*.mdddl|All Files (*.*)|*.*"; dialog.FilterIndex = 1; dialog.InitialDirectory = System.IO.Path.Combine(GetProgramDirectory(), "..\\.."); //dialog.RestoreDirectory = true; if (dialog.ShowDialog() == true) { Document document = DdlReader.DocumentFromFile(dialog.FileName); string ddl = DdlWriter.WriteToString(document); preview.Ddl = ddl; } } catch (Exception ex) { MessageBox.Show(ex.Message, Title); preview.Ddl = null; // TODO has no effect } finally { //if (dialog != null) // dialog.Dispose(); } //UpdateStatusBar(); }
private void Sample2Click(object sender, RoutedEventArgs e) { Directory.SetCurrentDirectory(GetProgramDirectory()); var document = SampleDocuments.CreateSample2(); Preview.Ddl = DdlWriter.WriteToString(document); }
// [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 void SaveMDDDL(string filename) { DdlWriter dw = new DdlWriter(filename); dw.WriteDocument(Document); dw.Close(); }
private void OpenDdlClick(object sender, RoutedEventArgs e) { try { var dialog = new OpenFileDialog { CheckFileExists = true, CheckPathExists = true, Filter = "MigraDoc DDL (*.mdddl)|*.mdddl|All Files (*.*)|*.*", FilterIndex = 1, InitialDirectory = Path.GetFullPath(Path.Combine(GetProgramDirectory(), "..\\..\\..\\..\\assets\\ddl")) }; //dialog.RestoreDirectory = true; if (dialog.ShowDialog() == true) { var document = DdlReader.DocumentFromFile(dialog.FileName); var folder = Path.GetDirectoryName(dialog.FileName); Environment.CurrentDirectory = folder; var ddl = DdlWriter.WriteToString(document); Preview.Ddl = ddl; } } catch (Exception ex) { MessageBox.Show(ex.Message, Title); Preview.Ddl = null; // TODO has no effect } finally { //if (dialog != null) // dialog.Dispose(); } //UpdateStatusBar(); }
private void miSample2_Click(object sender, EventArgs e) { Directory.SetCurrentDirectory(GetProgramDirectory()); Document document = SampleDocuments.CreateSample2(); this.pagePreview.Ddl = DdlWriter.WriteToString(document); }
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"); }
public ReportWindow(TreeViewItem item) { InitializeComponent(); var document = CreateSample1(item); DocumentPreview1.Ddl = DdlWriter.WriteToString(document); TVItem = item; }
private Document ClonedDocument() { #if MIGRADOC132 // Workaround for bug in Clone() implementation (fixed with PDFsharp 1.50 beta 2). var str = DdlWriter.WriteToString(Document); var result = DdlReader.DocumentFromString(str); return(result); #else return(Document.Clone()); #endif }
// [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"); }
public MainWindow() { InitializeComponent(); // Create a new MigraDoc document Document document = SampleDocuments.CreateSample1(); // HACK string ddl = DdlWriter.WriteToString(document); this.preview.Ddl = ddl; }
//[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"); }
private void initializerBGW_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { try { SetEnabled(true); SetStatus(""); toolStripProgressBar1.Style = ProgressBarStyle.Blocks; preview.Ddl = DdlWriter.WriteToString(document); SetZoomIndexByActualZoom(); } catch { } }
void model_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { const bool unicode = false; const PdfFontEmbedding embedding = PdfFontEmbedding.Always; if (e.PropertyName == "Document") { if (model.Document != null) { docViewer.Ddl = DdlWriter.WriteToString(model.Document); } } }
public Viewer() { InitializeComponent(); // Create a new MigraDoc document. var document = SampleDocuments.CreateSample1(); // HACK var ddl = DdlWriter.WriteToString(document); _pagePreview.Ddl = ddl; UpdateStatusBar(); }
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 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"); }
public OknoPodgladRaportow(Document Raport, string NazwaPliku) { InitializeComponent(); NazwaPlikuDoZapisu = NazwaPliku; // Utworzenie nowego dokumentu MigraDoc var dokument = Raport; var ddl = DdlWriter.WriteToString(dokument); PodgladRaportu.Ddl = ddl; LabelPowiekszenie.Text = "100%"; LabelStrona.Text = "Str. " + PodgladRaportu.Page.ToString(); }
// [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 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 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 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 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"); }
void model_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { const bool unicode = false; const PdfFontEmbedding embedding = PdfFontEmbedding.Always; if (e.PropertyName == "Document") { if (model.Document != null) { //PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(unicode, embedding); //pdfRenderer.Document = model.Document; //pdfRenderer.RenderDocument(); //const string filename = "HelloWorld.pdf"; //pdfRenderer.PdfDocument.Save(filename); //Process.Start(filename); string ddl = DdlWriter.WriteToString(model.Document); docViewer.Ddl = ddl; } } }
// [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); } }
public static void Test() { Document doc = new Document(); Section sec = doc.AddSection(); Chart chart = sec.AddChart(ChartType.Line); chart.Width = "13cm"; chart.Height = "8cm"; chart.FillFormat.Color = Color.Linen; chart.LineFormat.Width = 2; chart.PlotArea.FillFormat.Color = Color.Blue; // chart.XAxis.Title.Caption = "X-Axis"; // chart.YAxis.Title.Caption = "Y-Axis"; DocumentRenderer docRenderer = new DocumentRenderer(); docRenderer.Render(doc, "RtfChart.txt"); DdlWriter.SerializeToFile(doc, "RtfChart.mdddl"); System.IO.File.Copy("RtfChart.txt", "RtfChart.rtf", true); System.Diagnostics.Process.Start("RtfChart.txt"); }
// [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"); }
private void Sample2_Click(object sender, RoutedEventArgs e) { Document document = SampleDocuments.CreateSample2(); this.preview.Ddl = DdlWriter.WriteToString(document); }