10

XpsDocumentはディスクから読み込まれ ます

XpsDocument.GetFixedDocumentSequence メソッド ()を介してFixedDocumentSequenceを作成します。

DocumentViewer経由で表示する

印刷するヘッダーとフッターを追加したい ヘッダーとフッターを
XPS ドキュメントに戻す必要はなく、印刷出力のみに追加する必要がある

DocumentPaginatorを実装しようとしましたが、サイズ変更または配置が機能しません

FlowDocument へのこのフッターと同じではありませんFlowDocuments
のソリューションをうまく使用します
XAML フロー ドキュメントをスタイル付きの XPS に変換します

FixedDocumentSequence では、サイズ変更はドキュメントから取得されます (推測します)
たとえば、横向きと縦向き
を混在させることができます サイズ変更にフックしてヘッダーとフッター用のスペースを作る方法がわかりません ヘッダー
をスタンプすることはできますが、それは上にありますページの横方向の
ページは切り取られています

リンクに記載されているよう に、提案されたページ サイズDocumentPageです

DocumentPaginator.GetPageを使用してページがロードされたときに必要なサイズの DocumentPage を作成しても、サイズは上書き されます

さらに悪いことに、DocumentPaginator は、横向きと縦向きの混合を適切に処理しないため、Size を適切に認識していないようです。横は縦に印刷され、ページからはみ出します。

誰かが私にコードを投稿するように頼んだ .それを使用する方法については、FlowDocumentのフッターを 参照してください
.// これはGetPageからページサイズを取得します-上記のサイズを無視します


public class DocumentPaginatorWrapperXPS : DocumentPaginator
{
    System.Windows.Size m_PageSize;
    System.Windows.Size m_Margin;
    DocumentPaginator m_Paginator;
    FixedDocumentSequence fixedDocumentSequence;
    Typeface m_Typeface;
    private string printHeader;
    private int? sID;
    private string docID;

    public DocumentPaginatorWrapperXPS(FixedDocumentSequence FixedDocumentSequence, System.Windows.Size margin, string PrintHeader, int? SID, string DOCID)
    {
        //m_PageSize = pageSize;
        //m_PageSize = new Size(800, 600);

        fixedDocumentSequence = FixedDocumentSequence;

        m_Margin = margin;
        m_Paginator = fixedDocumentSequence.DocumentPaginator;
        //m_Paginator.PageSize = new System.Windows.Size(m_PageSize.Width - margin.Width * 2,
        //                                               //m_PageSize.Height - margin.Width * 2);
        printHeader = PrintHeader;
        sID = SID;
        docID = DOCID;
    }
    Rect Move(Rect rect)
    {
        if (rect.IsEmpty)
        {
            return rect;
        }
        else
        {
            return new Rect(rect.Left + m_Margin.Width, rect.Top + m_Margin.Height,
                            rect.Width, rect.Height);
        }
    }
    private Size sizeXPS;
    public override DocumentPage GetPage(int pageNumber)
    {
        System.Windows.Documents.DocumentPage page = m_Paginator.GetPage(pageNumber);
        Debug.WriteLine(page.Size.Width + " " + page.Size.Height);


        m_Paginator.PageSize = new System.Windows.Size(page.Size.Width/2 - m_Margin.Width * 2, page.Size.Height/2 - m_Margin.Height * 2);

        page = m_Paginator.GetPage(pageNumber);  // this get the page size from GetPage - ignores size above
        Debug.WriteLine(page.Size.Width + " " + page.Size.Height);

        DynamicDocumentPaginator paginatorPage = fixedDocumentSequence.DocumentPaginator as DynamicDocumentPaginator;
        paginatorPage.PageSize = new System.Windows.Size(page.Size.Width / 2 - m_Margin.Width * 2, page.Size.Height / 2 - m_Margin.Height * 2);
        sizeXPS = new System.Windows.Size(page.Size.Width / 2 - m_Margin.Width * 2, page.Size.Height / 2 - m_Margin.Height * 2);
        page = paginatorPage.GetPage(pageNumber);  // still does not change the page size
        Debug.WriteLine(page.Size.Width + " " + page.Size.Height);

        //page.PageSize = new System.Windows.Size(m_PageSize.Width - margin.Width * 2,
        //m_PageSize.Height - margin.Width * 2);
        //page.Size = new System.Windows.Size(page.Size.Width - m_Margin.Width * 2, page.Size.Height - m_Margin.Height * 2);
        //page.Size.Width = page.Size.Width - m_Margin.Width * 2;
        // Create a wrapper visual for transformation and add extras

        ContainerVisual newpage = new ContainerVisual();
        DrawingVisual title = new DrawingVisual();
        using (DrawingContext ctx = title.RenderOpen())
        {
            if (m_Typeface == null)
            {
                m_Typeface = new Typeface("Segoe UI Symbol");  //Ariel
            }
            //FormattedText text = new FormattedText("Attorney eyes only  \uE18B  \u1F440                Page " + (pageNumber + 1), 
            //                                        System.Globalization.CultureInfo.CurrentCulture, FlowDirection.LeftToRight, 
            //                                        m_Typeface, 14, System.Windows.Media.Brushes.Black);

            string pageS = "m_PageSize.Width " + m_PageSize.Width + "  m_Margin.Width " + m_Margin.Width + "  m_PageSize.Height " + m_PageSize.Height + "  m_Margin.Height " + m_Margin.Height + Environment.NewLine +
                            "page.Size.Width " + page.Size.Width + "  page.Size.Height " + page.Size.Height;
            FormattedText header = new FormattedText("\u1F440 " + printHeader + Environment.NewLine + pageS,
                                                    System.Globalization.CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
                                                    m_Typeface, 14, System.Windows.Media.Brushes.Black);
            ctx.DrawText(header, new System.Windows.Point(96 / 2, -96 / 4)); // 1/4 inch above page content
            //text = new FormattedText(pageS, System.Globalization.CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
            //                         m_Typeface, 14, System.Windows.Media.Brushes.Black);

            string goGabe = string.Empty;
            if (sID != null)
            {
                goGabe += Environment.NewLine + "Gabriel Docs™ sysDocID: " + sID;
                if (!string.IsNullOrEmpty(docID))
                    goGabe += "  docID: " + docID;
            }
            goGabe += Environment.NewLine + "Page: " + (pageNumber + 1) + "   Date: " + DateTime.Now.ToString() + "  User: " + App.StaticGabeLib.CurUserP.UserID;
            FormattedText footer = new FormattedText(goGabe
                                                    , System.Globalization.CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
                                                        m_Typeface, 14, System.Windows.Media.Brushes.Black);
            ctx.DrawText(footer, new System.Windows.Point(96 / 2, page.Size.Height - m_Margin.Height));
            //ctx.DrawText(footer, new System.Windows.Point(96 / 2, m_Paginator.PageSize.Height - m_Margin.Height));
        }
        DrawingVisual background = new DrawingVisual();
        using (DrawingContext ctx = background.RenderOpen())
        {
            ctx.DrawRectangle(new SolidColorBrush(System.Windows.Media.Color.FromRgb(240, 240, 240)), null, page.ContentBox);
        }
        newpage.Children.Add(background); // Scale down page and center
        ContainerVisual smallerPage = new ContainerVisual();
        smallerPage.Children.Add(page.Visual);
        smallerPage.Transform = new MatrixTransform(0.8, 0, 0, 0.8, 0.1 * page.ContentBox.Width, 0.1 * page.ContentBox.Height);
        newpage.Children.Add(smallerPage);
        newpage.Children.Add(title);
        newpage.Transform = new TranslateTransform(m_Margin.Width, m_Margin.Height);
        return new DocumentPage(newpage, m_PageSize, Move(page.BleedBox), Move(page.ContentBox));
    }
    public override bool IsPageCountValid
    {
        get
        {
            return m_Paginator.IsPageCountValid;
        }
    }
    public override int PageCount
    {
        get
        {
            return m_Paginator.PageCount;
        }
    }
    public override System.Windows.Size PageSize
    {
        get
        {
            Debug.WriteLine("PageSize " + sizeXPS.Width + " " + sizeXPS.Height);
            return sizeXPS;  // this is not called

            //m_Paginator.PageSize;
        }
        set
        {
            sizeXPS = value;
            // m_Paginator.PageSize = value;
        }
    }
    public override IDocumentPaginatorSource Source
    {
        get
        {
            return m_Paginator.Source;
        }
    }
}
4

0 に答える 0