如何自动分页 PDFsharp 文档?
How to auto pagebreak the PDFsharp document?
我正在尝试从 C# WPF 控件生成 PDF 文档。
这是我的 .
我的对象出来了一半,如何自动分页?
下面是我的代码:
System.Windows.Application.Current.Dispatcher.Invoke(new System.Action(() => fixedDoc = new FixedDocument()));
System.Windows.Application.Current.Dispatcher.Invoke(new System.Action(() => fixedDoc1 = new FixedDocument()));
System.Windows.Application.Current.Dispatcher.Invoke(new System.Action(() => pageContent = new PageContent()));
System.Windows.Application.Current.Dispatcher.Invoke(new System.Action(() => pageContent1 = new PageContent()));
System.Windows.Application.Current.Dispatcher.Invoke(new System.Action(() => fixedPage = new FixedPage()));
System.Windows.Application.Current.Dispatcher.Invoke(new System.Action(() => fixedPage1 = new FixedPage()));
var visual = Child as UIElement;
System.Windows.Application.Current.Dispatcher.Invoke(new System.Action(() => (Content).Children.Remove(visual)));
System.Windows.Application.Current.Dispatcher.Invoke(new System.Action(() => fixedPage.Children.Clear()));
System.Windows.Application.Current.Dispatcher.Invoke(new System.Action(() => fixedPage.Children.Add(visual)));
System.Windows.Application.Current.Dispatcher.Invoke(new System.Action(() => ((System.Windows.Markup.IAddChild)pageContent).AddChild(fixedPage)));
System.Windows.Application.Current.Dispatcher.Invoke(new System.Action(() => fixedDoc.Pages.Add(pageContent)));
// write to PDF file
string tempFilename = "temp.Xps";
File.Delete(tempFilename);
XpsDocument xpsd = new XpsDocument(tempFilename, FileAccess.ReadWrite);
XpsDocumentWriter xw = XpsDocument.CreateXpsDocumentWriter(xpsd);
System.Windows.Application.Current.Dispatcher.Invoke(new System.Action(() => xw.Write(fixedDoc)));
System.Windows.Application.Current.Dispatcher.Invoke(new System.Action(() => xpsd.Close()));
filename = filepath + DateTime.Now.ToString("yyyyMMddHHmmss") + "-" + title_ + ".pdf";
PdfSharp.Xps.XpsConverter.Convert(tempFilename, filename, 1);
var visual2 = Child2 as UIElement;
Application.Current.Dispatcher.Invoke(new Action(() => (Content).Children.Remove(visual2)));
Application.Current.Dispatcher.Invoke(new Action(() => fixedPage1.Children.Clear()));
Application.Current.Dispatcher.Invoke(new Action(() => fixedPage1.Children.Add(visual2)));
Application.Current.Dispatcher.Invoke(new Action(() => ((System.Windows.Markup.IAddChild)pageContent1).AddChild(fixedPage1)));
Application.Current.Dispatcher.Invoke(new Action(() => fixedDoc1.Pages.Add(pageContent1)));
// write to PDF file
string tempFilename2 = "temp2.Xps";
File.Delete(tempFilename2);
XpsDocument xpsd2 = new XpsDocument(tempFilename2, FileAccess.ReadWrite);
XpsDocumentWriter xw2 = XpsDocument.CreateXpsDocumentWriter(xpsd2);
Application.Current.Dispatcher.Invoke(new Action(() => xw2.Write(fixedDoc1)));
Application.Current.Dispatcher.Invoke(new Action(() => xpsd2.Close()));
filename2 = filepath + DateTime.Now.ToString("yyyyMMddHHmmss") + "-" + title_ + ".pdf";
PdfSharp.Xps.XpsConverter.Convert(tempFilename2, filename2, 1);
PDFsharp 不自动分页。
我建议像其他人一样处理他们的图表:只显示大的(10、20、30 左右)并将真正小的总结为 "others"。这样,图例将适合一页,并且您可以避免在图表中出现 "zero width" 个饼图。
这并不是您问题的真正答案,但它是一种也符合良好做法的解决方法。
我正在尝试从 C# WPF 控件生成 PDF 文档。
这是我的
我的对象出来了一半,如何自动分页?
下面是我的代码:
System.Windows.Application.Current.Dispatcher.Invoke(new System.Action(() => fixedDoc = new FixedDocument()));
System.Windows.Application.Current.Dispatcher.Invoke(new System.Action(() => fixedDoc1 = new FixedDocument()));
System.Windows.Application.Current.Dispatcher.Invoke(new System.Action(() => pageContent = new PageContent()));
System.Windows.Application.Current.Dispatcher.Invoke(new System.Action(() => pageContent1 = new PageContent()));
System.Windows.Application.Current.Dispatcher.Invoke(new System.Action(() => fixedPage = new FixedPage()));
System.Windows.Application.Current.Dispatcher.Invoke(new System.Action(() => fixedPage1 = new FixedPage()));
var visual = Child as UIElement;
System.Windows.Application.Current.Dispatcher.Invoke(new System.Action(() => (Content).Children.Remove(visual)));
System.Windows.Application.Current.Dispatcher.Invoke(new System.Action(() => fixedPage.Children.Clear()));
System.Windows.Application.Current.Dispatcher.Invoke(new System.Action(() => fixedPage.Children.Add(visual)));
System.Windows.Application.Current.Dispatcher.Invoke(new System.Action(() => ((System.Windows.Markup.IAddChild)pageContent).AddChild(fixedPage)));
System.Windows.Application.Current.Dispatcher.Invoke(new System.Action(() => fixedDoc.Pages.Add(pageContent)));
// write to PDF file
string tempFilename = "temp.Xps";
File.Delete(tempFilename);
XpsDocument xpsd = new XpsDocument(tempFilename, FileAccess.ReadWrite);
XpsDocumentWriter xw = XpsDocument.CreateXpsDocumentWriter(xpsd);
System.Windows.Application.Current.Dispatcher.Invoke(new System.Action(() => xw.Write(fixedDoc)));
System.Windows.Application.Current.Dispatcher.Invoke(new System.Action(() => xpsd.Close()));
filename = filepath + DateTime.Now.ToString("yyyyMMddHHmmss") + "-" + title_ + ".pdf";
PdfSharp.Xps.XpsConverter.Convert(tempFilename, filename, 1);
var visual2 = Child2 as UIElement;
Application.Current.Dispatcher.Invoke(new Action(() => (Content).Children.Remove(visual2)));
Application.Current.Dispatcher.Invoke(new Action(() => fixedPage1.Children.Clear()));
Application.Current.Dispatcher.Invoke(new Action(() => fixedPage1.Children.Add(visual2)));
Application.Current.Dispatcher.Invoke(new Action(() => ((System.Windows.Markup.IAddChild)pageContent1).AddChild(fixedPage1)));
Application.Current.Dispatcher.Invoke(new Action(() => fixedDoc1.Pages.Add(pageContent1)));
// write to PDF file
string tempFilename2 = "temp2.Xps";
File.Delete(tempFilename2);
XpsDocument xpsd2 = new XpsDocument(tempFilename2, FileAccess.ReadWrite);
XpsDocumentWriter xw2 = XpsDocument.CreateXpsDocumentWriter(xpsd2);
Application.Current.Dispatcher.Invoke(new Action(() => xw2.Write(fixedDoc1)));
Application.Current.Dispatcher.Invoke(new Action(() => xpsd2.Close()));
filename2 = filepath + DateTime.Now.ToString("yyyyMMddHHmmss") + "-" + title_ + ".pdf";
PdfSharp.Xps.XpsConverter.Convert(tempFilename2, filename2, 1);
PDFsharp 不自动分页。
我建议像其他人一样处理他们的图表:只显示大的(10、20、30 左右)并将真正小的总结为 "others"。这样,图例将适合一页,并且您可以避免在图表中出现 "zero width" 个饼图。
这并不是您问题的真正答案,但它是一种也符合良好做法的解决方法。