簡體   English   中英

如何自動分頁符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左右),並將較小的圖表總結為“其他”。 這樣,圖例將適合在一頁上,並且可以避免圖表中出現“零寬度”餅圖。

這實際上不是您問題的答案,但這是一種解決方法,也符合良好實踐。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM