Ejemplo n.º 1
0
        static public void AddTextToThePageCenter(Form1 Parent)
        {
            if (Parent.m_CurDoc == null)
            {
                Document.CreateNewDoc(Parent);
            }
            IPXC_Pages          pages  = Parent.m_CurDoc.Pages;
            IPXC_Page           page   = pages[0];
            PXC_Rect            rcPage = page.get_Box(PXC_BoxType.PBox_PageBox);
            IPXC_ContentCreator CC     = Parent.m_CurDoc.CreateContentCreator();
            IPXC_Font           font   = Parent.m_CurDoc.CreateNewFont("Tahoma", 0, 400);

            CC.SaveState();
            CC.SetFont(font);
            CC.SetStrokeColorRGB(0x000000);
            CC.SetFontSize(36);
            string   str   = "Centered Text";
            PXC_Rect rcOut = new PXC_Rect();

            //Calculating the text rectangle
            CC.ShowTextBlock(str, ref rcPage, ref rcPage, (uint)PXC_DrawTextFlags.DTF_CalcSizeOnly, -1, null, null, null, out rcOut);
            //Placing it in the center of page
            double nCX = (rcPage.right - rcPage.left) / 2.0;
            double nCY = (rcPage.top - rcPage.bottom) / 2.0;
            double nW  = rcOut.right - rcOut.left;
            double nH  = rcOut.top - rcOut.bottom;

            rcOut.left   = nCX - nW / 2.0;
            rcOut.bottom = nCY - nH / 2.0;
            rcOut.right  = rcOut.left + nW;
            rcOut.top    = rcOut.bottom + nH;
            //Outputting the text
            PXC_Rect rc = new PXC_Rect();

            CC.ShowTextBlock(str, ref rcOut, ref rcOut, 0, -1, null, null, null, out rc);
            CC.RestoreState();
            page.PlaceContent(CC.Detach());
            Marshal.ReleaseComObject(page);
            Marshal.ReleaseComObject(pages);
        }
Ejemplo n.º 2
0
        static public int ConvertFromTXT(Form1 Parent)
        {
            if (Parent.m_CurDoc == null)
            {
                Document.CreateNewDoc(Parent);
            }
            IPXC_Pages pages     = Parent.m_CurDoc.Pages;
            IPXC_Page  firstPage = pages[0];
            PXC_Rect   rc        = firstPage.get_Box(PXC_BoxType.PBox_PageBox);

            Marshal.ReleaseComObject(firstPage);
            IPXC_UndoRedoData   urData;
            IPXC_ContentCreator CC   = Parent.m_CurDoc.CreateContentCreator();
            IPXC_Page           page = pages.InsertPage(0, ref rc, out urData);
            DrawTextCallbacks   drawTextCallbacks = new DrawTextCallbacks();

            drawTextCallbacks.m_currPage = page;

            drawTextCallbacks.m_Text = File.ReadAllText(Environment.CurrentDirectory + "\\Documents\\Hobbit.txt");

            IPXC_Font font = Parent.m_CurDoc.CreateNewFont("Times New Roman", 0, 400);

            CC.SetColorRGB(0x00000000);
            CC.SetFont(font);
            CC.SetFontSize(15);

            PXC_Rect rect = new PXC_Rect();

            rect.top    = rc.top - 40;
            rect.right  = rc.right - 40;
            rect.bottom = rc.bottom + 40;
            rect.left   = rc.left + 40;

            CC.ShowTextBlock(drawTextCallbacks.m_Text, rect, rect, (uint)PXC_DrawTextFlags.DTF_Center, -1, null, null, drawTextCallbacks, out rect);
            Marshal.ReleaseComObject(page);
            Marshal.ReleaseComObject(pages);

            return((int)Form1.eFormUpdateFlags.efuf_All);
        }
        static public int AddRedactAnnotation(Form1 Parent)
        {
            if (Parent.m_CurDoc == null)
            {
                Document.CreateNewDoc(Parent);
            }

            IPXC_UndoRedoData urData    = null;
            IPXC_Pages        pages     = Parent.m_CurDoc.Pages;
            IPXC_Page         firstPage = pages[0];
            PXC_Rect          rcPage    = firstPage.get_Box(PXC_BoxType.PBox_PageBox);

            Marshal.ReleaseComObject(firstPage);
            IPXC_Page           page    = pages.InsertPage(0, ref rcPage, out urData);
            IPXS_Inst           pxsInst = Parent.m_pxcInst.GetExtension("PXS");
            IAUX_Inst           auxInst = Parent.m_pxcInst.GetExtension("AUX");
            IPXC_ContentCreator CC      = Parent.m_CurDoc.CreateContentCreator();
            double nCX = (rcPage.right - rcPage.left) / 2.0;
            double nCY = (rcPage.top - rcPage.bottom) / 4.0 * 3.0;

            IPXC_Font font = Parent.m_CurDoc.CreateNewFont("Arial", (uint)PXC_CreateFontFlags.CreateFont_Monospaced, 700);

            CC.SetFontSize(30);
            CC.SetFont(font);
            CC.SetColorRGB(0x00000000);
            for (int i = 0; i < 4; i++)
            {
                CC.ShowTextLine(nCX - 190, nCY - (40 * i), "This is a story of long ago.", -1, (uint)PXC_ShowTextLineFlags.STLF_Default | (uint)PXC_ShowTextLineFlags.STLF_AllowSubstitution);
            }
            page.PlaceContent(CC.Detach(), (uint)PXC_PlaceContentFlags.PlaceContent_Replace);
            IPXC_PageText Text = page.GetText(null, false);

            PXC_Rect rcOut = new PXC_Rect();

            rcOut.left   = nCX - 150;
            rcOut.bottom = nCY - 100;
            rcOut.right  = nCX + 150;
            rcOut.top    = nCY + 100;
            //Getting Redact annotation atom for the InsertNewAnnot method
            uint                     nText = pxsInst.StrToAtom("Redact");
            IPXC_Annotation          annot = unchecked (page.InsertNewAnnot(nText, ref rcOut));
            IPXC_AnnotData_Redaction aData = annot.Data as IPXC_AnnotData_Redaction;

            aData.Title = "Redact annotation 1.";

            IPXC_QuadsF quadsF = Parent.m_pxcInst.CreateQuads();
            uint        afafaf = quadsF.Count;
            PXC_RectF   rectF  = new PXC_RectF();

            Text.GetTextQuads3(8, 75, quadsF, out rectF);
            aData.Quads = quadsF;
            var color = auxInst.CreateColor(ColorType.ColorType_RGB);

            color.SetRGB(0.0f, 0.0f, 0.0f);
            aData.FColor = color;
            aData.SColor = color;
            annot.Data   = aData;

            Marshal.ReleaseComObject(page);
            Marshal.ReleaseComObject(pages);

            return((int)Form1.eFormUpdateFlags.efuf_Annotations);
        }