GetPageAsMetafile return zero

  • The GetPageAsMetafile-Function returns very ofter Zero and I don't know why. Is there any chance to get the Error-Code?
    Sometime when I am in the Debugger the function returns a correct handle and sometimes not. The last test result with the same original text (2 pages)
    first time every thing okay, secound and third try no page loaded fourth try only page 2 loaded.

    Here are some parts of my c# code

    //// Part 1 Filling copy of the original text and try to get Metafiles
    //////////////////////////////////////////////////////////////////////////

    public TextDynamicPreviewDialog(WPDLLInt editorToBePreviewed)
    {
    InitializeComponent();

    WPDLLInt editorToPreview = new WPDLLInt();
    TextDynamicHelper.RegisterEditor(editorToPreview);

    editorToPreview.Memo.LoadFromString(editorToBePreviewed.Memo.SaveToString(false, "RTF"), false, "RTF");

    editorToPreview.SpecialTextAttr(SpecialTextSel.wpInsertpoints).Hidden = true;

    editorToPreview.OnPaintWatermark += new WPDLLInt.PaintWatermarkEvent(TextEditor_OnPaintWatermark);

    editorToPreview.Memo.ReformatAll(true, false);

    pages = new Metafile[editorToPreview.Memo.TextCursor.PageCount];

    for (int i = 0; i < pages.Length; i++)
    {
    editorToPreview.Memo.ReformatAll(false, false);
    IntPtr metaHandle = editorToPreview.Memo.GetPageAsMetafile(i, 8);
    if (metaHandle.ToInt32() == 0)
    {
    pages[i] = null;
    Console.WriteLine("page " + i.ToString() + " not loaded");
    }
    else
    {
    Metafile aMetafile = new Metafile(metaHandle, true);
    pages[i] = aMetafile;
    }

    }

    editorToPreview.OnPaintWatermark -= TextEditor_OnPaintWatermark;


    //// Part 2 OnPaintWatermark-Event
    /////////////////////////////////////////////////////////////////////////////////
    void TextEditor_OnPaintWatermark(object Sender, int Editor, int Mode, Graphics Canvas, float X, float Y, float X1, float Y1, float Xres, float Yres)
    {
    Canvas.DrawString("OnWatermark Editor=" +
    Editor.ToString() + "; Seite=" + (Mode & 0xffff).ToString() + "; Pos1=" +
    X.ToString() + "/" + Y.ToString() + "; Pos2=" +
    X1.ToString() + "/" + Y1.ToString() + "; Auflösung=" +
    Xres.ToString() + "/" + Yres.ToString(),
    new Font("Arial", Convert.ToInt32(12 * Xres / Canvas.DpiX)), Brushes.BlueViolet, new Point(10, 10));
    }

    • Offizieller Beitrag

    Hi,

    Please check the debug console if there are any messages reported there.

    In this part of the code:

    Code
    for (int i = 0; i < pages.Length; i++) 
    { 
    editorToPreview.Memo.ReformatAll(false, false);

    ReformatAll should not be called - it was called before already.

    Did you try to disable the watermark code?

    For debugging purposes the function SavePageAsMetafile may be also useful.

    Julian

  • Hallo Julian,

    My Output-Window for Console in Visual Studio reports only my own Logs.

    Delete the ReformatAll has no influence to my Problem.

    Disable the watermark code (no eventhandler or Option #32) does not fit the problem.

    Using the new Version 1.36.1 does not solve the problem.

    SavePageAsMetafile runs a little bit better, no emf-File was empty, but not at every page the watermark-Routine was called. It sems to be like a randomnumber genarator which page gets a Watermark. A new call to build the same 4 pages will bring a new result.

    Using the SavePageAsMetafile is okay, but the watermark should be on every page.

    An idea to solve the Problem?