Example #1
0
        static public void AddHeadersAndFootersOnPages(Form1 Parent)
        {
            if (Parent.m_CurDoc == null)
            {
                Document.CreateNewDoc(Parent);
            }

            IAUX_Inst auxInst = Parent.m_pxcInst.GetExtension("AUX");
            IPXC_HeaderAndFooterParams firstHeaderFooter = Parent.m_pxcInst.CreateHeaderAndFooterParams();
            IPXC_Font font  = Parent.m_CurDoc.CreateNewFont("Arial", (uint)PXC_CreateFontFlags.CreateFont_Serif, 400);
            IColor    color = auxInst.CreateColor(ColorType.ColorType_RGB);

            color.SetRGB(0, 0, 0);
            firstHeaderFooter.Font           = font;
            firstHeaderFooter.FillColor      = color;
            firstHeaderFooter.LeftHeaderText = "%[Page]";
            firstHeaderFooter.LeftFooterText = "%[Page] of %[Pages]";
            firstHeaderFooter.BottomMargin   = 36.0f;
            firstHeaderFooter.TopMargin      = 36.0f;
            firstHeaderFooter.RightMargin    = 36.0f;
            firstHeaderFooter.LeftMargin     = 36.0f;
            firstHeaderFooter.FontSize       = 30.0f;
            IPXC_Pages pages  = Parent.m_CurDoc.Pages;
            IBitSet    bitSet = auxInst.CreateBitSet(pages.Count);

            bitSet.Set(0, pages.Count, true);
            Parent.m_CurDoc.PlaceHeadersAndFooters(bitSet, firstHeaderFooter);

            IPXC_HeaderAndFooterParams secondHeaderFooter = Parent.m_pxcInst.CreateHeaderAndFooterParams();

            font = Parent.m_CurDoc.CreateNewFont("Comic Sans MS", (uint)PXC_CreateFontFlags.CreateFont_Italic, 1000);
            color.SetRGB(0.35f, 0.48f, 0.35f);
            secondHeaderFooter.Font             = font;
            secondHeaderFooter.FillColor        = color;
            secondHeaderFooter.CenterHeaderText = "%[Date:MM.dd.yyyy] %[Time]";
            secondHeaderFooter.CenterFooterText = "Version %[AppVersion]";
            secondHeaderFooter.BottomMargin     = 20.0f;
            secondHeaderFooter.TopMargin        = 20.0f;
            secondHeaderFooter.RightMargin      = 40.0f;
            secondHeaderFooter.LeftMargin       = 40.0f;
            secondHeaderFooter.FontSize         = 15.0f;
            Parent.m_CurDoc.PlaceHeadersAndFooters(bitSet, secondHeaderFooter);

            IPXC_HeaderAndFooterParams thirdHeaderFooter = Parent.m_pxcInst.CreateHeaderAndFooterParams();

            font = Parent.m_CurDoc.CreateNewFont("Times New Roman", (uint)PXC_CreateFontFlags.CreateFont_Monospaced, 700);
            color.SetRGB(0.67f, 0.23f, 0.8f);
            thirdHeaderFooter.Font            = font;
            thirdHeaderFooter.FillColor       = color;
            thirdHeaderFooter.RightHeaderText = "%[Computer]";
            thirdHeaderFooter.RightFooterText = "%[User]";
            thirdHeaderFooter.BottomMargin    = 40.0f;
            thirdHeaderFooter.TopMargin       = 40.0f;
            thirdHeaderFooter.RightMargin     = 20.0f;
            thirdHeaderFooter.LeftMargin      = 20.0f;
            thirdHeaderFooter.FontSize        = 20.0f;
            Parent.m_CurDoc.PlaceHeadersAndFooters(bitSet, thirdHeaderFooter);
            Marshal.ReleaseComObject(pages);
        }
        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);
        }
Example #3
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);
        }
        static public int AddFreeTextAnnotation(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");
            //Getting Free text annotation atom for the InsertNewAnnot method
            uint nText = pxsInst.StrToAtom("FreeText");

            double   nCX   = (rcPage.right - rcPage.left) / 2.0;
            double   nCY   = (rcPage.top - rcPage.bottom) / 2.0;
            PXC_Rect rcOut = new PXC_Rect();

            rcOut.left   = nCX - 200;
            rcOut.bottom = nCY + 200;
            rcOut.right  = nCX + 200;
            rcOut.top    = nCY + 300;
            IPXC_Annotation         annot = unchecked (page.InsertNewAnnot(nText, ref rcOut));
            IPXC_AnnotData_FreeText aData = annot.Data as IPXC_AnnotData_FreeText;

            aData.Contents = "Free Text Annotation 1.";
            aData.Title    = "Free Text Annotation 1.";
            IPXC_Font font = Parent.m_CurDoc.CreateNewFont("Arial", (uint)PXC_CreateFontFlags.CreateFont_Monospaced, 700);

            aData.DefaultFont     = font;
            aData.DefaultFontSize = 40;
            var color = auxInst.CreateColor(ColorType.ColorType_RGB);

            color.SetRGB(0.7f, 0.7f, 0.7f);
            aData.DefaultTextColor = color;
            aData.Opacity          = 0.5;
            aData.TextRotation     = 90;
            aData.Subject          = "Typewriter";
            //Setting dashed border pattern
            var border = new PXC_AnnotBorder();

            border.nStyle       = PXC_AnnotBorderStyle.ABS_Beveled;
            border.nWidth       = 4.0f;
            border.DashArray    = new float[15];
            border.DashArray[0] = border.DashArray[1] = 5.0f; //Width of dashes
            border.nDashCount   = 2;                          //Number of dashes
            aData.set_Border(border);
            annot.Data = aData;

            rcOut.bottom         -= 200;
            rcOut.top            -= 200;
            annot                 = unchecked (page.InsertNewAnnot(nText, ref rcOut));
            aData                 = annot.Data as IPXC_AnnotData_FreeText;
            aData.Contents        = "Free Text Annotation 2.";
            aData.DefaultFontSize = 15.0;
            color                 = auxInst.CreateColor(ColorType.ColorType_RGB);
            color.SetRGB(0.0f, 0.0f, 0.0f);
            aData.SColor           = color;
            aData.DefaultTextColor = color;
            //Setting dashed border pattern
            border              = new PXC_AnnotBorder();
            border.nStyle       = PXC_AnnotBorderStyle.ABS_Dashed;
            border.nWidth       = 10.0f;
            border.DashArray    = new float[20];
            border.DashArray[0] = border.DashArray[1] = 5.0f; //Width of dashes
            border.nDashCount   = 4;                          //Number of dashes
            aData.set_Border(border);
            annot.Data = aData;

            rcOut.bottom         -= 200;
            rcOut.top            -= 200;
            annot                 = unchecked (page.InsertNewAnnot(nText, ref rcOut));
            aData                 = annot.Data as IPXC_AnnotData_FreeText;
            aData.Contents        = "Free Text Annotation 3.";
            color                 = auxInst.CreateColor(ColorType.ColorType_RGB);
            aData.DefaultFontSize = 15.0;
            color.SetRGB(1.0f, 1.0f, 1.0f);
            aData.SColor = color;
            color.SetRGB(0.0f, 0.0f, 0.0f);
            aData.DefaultTextColor = color;
            annot.Data             = aData;
            Marshal.ReleaseComObject(page);
            Marshal.ReleaseComObject(pages);

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