Exemplo n.º 1
0
        private void HighlightQuads(PDFXEdit.IPXV_Document doc, int page, int wb, int wl)
        {
            if (dhp.doc != null)
            {
                dhp.doc.InvalidatePageRects((uint)dhp.page, dhp.bbox, 1);
            }

            PDFXEdit.IPXC_Document cdoc = doc.CoreDoc;
            if (dhp.doc != doc)
            {
                dhp.Start(pdfCtl.Inst, doc);
            }

            dhp.page = page;
            dhp.quads.Clear();

            PDFXEdit.IPXC_PageText pageText = cdoc.Pages[(uint)page].GetText(null);
            if (pageText != null)
            {
                pageText.GetTextQuads3((uint)wb, (uint)wl, dhp.quads, out dhp.bbox);                 // method added in build 6.0.322.4
            }
            if (dhp.doc != null)
            {
                dhp.doc.InvalidatePageRects((uint)dhp.page, dhp.bbox, 1);
            }
        }
Exemplo n.º 2
0
        public void ExtractDocToTiff(object obj)
        {
            try
            {
                stData data = (stData)obj;

                var importCV                    = FindNeededImportConverter(Path.GetExtension(data.sDoc));
                PDFXEdit.IAFS_Name name         = m_fsInst.DefaultFileSys.StringToName(data.sDoc);
                int openFileFlags               = (int)(PDFXEdit.AFS_OpenFileFlags.AFS_OpenFile_Read | PDFXEdit.AFS_OpenFileFlags.AFS_OpenFile_ShareRead);
                PDFXEdit.IAFS_File     destFile = m_fsInst.DefaultFileSys.OpenFile(name, openFileFlags);
                PDFXEdit.IPXC_Document Doc      = importCV.Convert(m_Inst, destFile);

                //PDFXEdit.IPXC_Document Doc = m_pxcInst.OpenDocumentFromFile(data.sDoc, null);
                PDFXEdit.IOperation Op    = m_Inst.CreateOp(m_nID);
                PDFXEdit.ICabNode   input = Op.Params.Root["Input"];
                input.Add().v             = Doc;
                PDFXEdit.ICabNode options = Op.Params.Root["Options"];
                options["PagesRange.Type"].v  = "All";
                options["DestFolder"].v       = data.sFolder;           //Output folder
                options["ExportMode"].v       = "AllToMutliPage";
                options["Zoom"].v             = 150;
                options["ShowResultFolder"].v = data.bLast;                 //We'll show the result folder only when we'll work with last doc
                //Saving as tiff
                PDFXEdit.ICabNode fmtParams = options["FormatParams"];
                //Compression type
                fmtParams["COMP"].v = 5;                 //LZW compression
                //X DPI
                fmtParams["DPIX"].v = 150;
                //Y DPI
                fmtParams["DPIY"].v = 150;
                //Image format
                fmtParams["FMT"].v = PDFXEdit.IXC_ImageFileFormatIDs.FMT_TIFF_ID; //TIFF
                //Image type
                fmtParams["ITYP"].v = 16;                                         //24 TrueColor
                //Use Predictor
                fmtParams["PRED"].v = 1;                                          //Yes
                //Thumbnail
                fmtParams["ITYP"].v = 0;                                          //No
                Op.Do();
                Doc.Close();
                m_nSavedFilesCount++;
                if (m_nSavedFilesCount == m_aFiles.Count)
                {
                    MessageBox.Show("Export completed");
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 3
0
 public void ExtractDocToTiff(object obj)
 {
     try
     {
         stData data = (stData)obj;
         PDFXEdit.IPXC_Document Doc   = m_pxcInst.OpenDocumentFromFile(data.sDoc, null);
         PDFXEdit.IOperation    Op    = m_Inst.CreateOp(m_nID);
         PDFXEdit.ICabNode      input = Op.Params.Root["Input"];
         input.Add().v             = Doc;
         PDFXEdit.ICabNode options = Op.Params.Root["Options"];
         options["PagesRange.Type"].v  = "All";
         options["DestFolder"].v       = data.sFolder;           //Output folder
         options["ExportMode"].v       = "AllToMutliPage";
         options["Zoom"].v             = 150;
         options["ShowResultFolder"].v = data.bLast;                 //We'll show the result folder only when we'll work with last doc
         //Saving as tiff
         PDFXEdit.ICabNode fmtParams = options["FormatParams"];
         //Compression type
         fmtParams["COMP"].v = 5;                 //LZW compression
         //X DPI
         fmtParams["DPIX"].v = 150;
         //Y DPI
         fmtParams["DPIY"].v = 150;
         //Image format
         fmtParams["FMT"].v = 1414088262;         //TIFF
         //Image type
         fmtParams["ITYP"].v = 16;                //24 TrueColor
         //Use Predictor
         fmtParams["PRED"].v = 1;                 //Yes
         //Thumbnail
         fmtParams["ITYP"].v = 0;                 //No
         Op.Do();
         Doc.Close();
         m_nSavedFilesCount++;
         if (m_nSavedFilesCount == m_aFiles.Count)
         {
             MessageBox.Show("Export completed");
         }
     }
     catch (System.Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Exemplo n.º 4
0
        public virtual bool Run(MainFrm mainFrm, bool bShowOpDlg, bool bAllowOpUI)
        {
            PDFXEdit.IOperation op = null;
            try
            {
                op = mainFrm.pdfCtl.Inst.CreateOp(ID);
            }
            catch
            {
                return(false);
            }

            if (op == null)
            {
                return(false);
            }

            Form ui = UI;

            if (ui != null)
            {
                IFormHelper hlp = (IFormHelper)ui;
                if (hlp != null)
                {
                    hlp.OnSerialize(op);
                }
            }

            uint flags = Flags;

            if ((flags & (uint)DemoFlags.Input_Doc) != 0)
            {
                PDFXEdit.IPXV_Document doc = mainFrm.pdfCtl.Doc;
                if (doc == null)
                {
                    return(false);
                }
                PDFXEdit.ICabNode input = op.Params.Root["Input"];
                if (input.Type == PDFXEdit.CabDataTypeID.dt_Array)
                {
                    input.Add().v = doc;
                }
                else
                {
                    input.v = doc;
                }
            }
            else if (!bShowOpDlg && ((flags & (uint)DemoFlags.Input_Mask) != 0))
            {
                string fileFilter = "";
                if ((flags & (uint)DemoFlags.Input_AllSupp) != 0)
                {
                    fileFilter = "<allSupp>";
                }
                else if ((flags & (uint)DemoFlags.Input_AllSuppImg) != 0)
                {
                    fileFilter = "<allSuppImg>";
                }
                else if ((flags & (uint)DemoFlags.Input_AllSuppRasterImg) != 0)
                {
                    fileFilter = "<allSuppRasterImg>";
                }
                else if ((flags & (uint)DemoFlags.Input_PdfFile) != 0)
                {
                    fileFilter = "PDF Documents (*.pdf)|*.pdf";
                }
                else if ((flags & (uint)DemoFlags.Input_TxtFile) != 0)
                {
                    fileFilter = "Plain Text Documents (*.txt)|*.txt";
                }
                else if ((flags & (uint)DemoFlags.Input_RtfFile) != 0)
                {
                    fileFilter = "RTF Files (*.rtf)|*.rtf";
                }

                PDFXEdit.IAFS_NamesCollection fileNames = mainFrm.ShowOpenFilesDlg((flags & (uint)DemoFlags.Input_MultFiles) != 0, fileFilter);
                if (fileNames == null || (fileNames.Count == 0))
                {
                    return(false);
                }

                PDFXEdit.ICabNode input = op.Params.Root["Input"];
                if (input.Type == PDFXEdit.CabDataTypeID.dt_Array)
                {
                    for (uint i = 0; i < fileNames.Count; i++)
                    {
                        input.Add().v = fileNames[i];
                    }
                }
                else
                {
                    input.v = fileNames[0];
                }
            }

            if (bShowOpDlg)
            {
                try
                {
                    op.ShowSetupUI((uint)mainFrm.Handle);
                }
                catch (Exception ex)
                {
                    int hr = Marshal.GetHRForException(ex);
                    if (hr != HResults.E_NOTIMPL)
                    {
                        return(false);
                    }
                }
            }

            if (!OnBeforeRun(mainFrm, op))
            {
                return(false);
            }


            int opExecFlags = 0;

            if (!bAllowOpUI)
            {
                opExecFlags |= (int)PDFXEdit.OpExecFlags.OpExecFlag_NoUI;
            }

            try
            {
                if ((flags & (int)DemoFlags.SyncDo) != 0)
                {
                    op.Do(opExecFlags);
                }
                else
                {
                    mainFrm.pdfCtl.Inst.AsyncDoAndWaitForFinish(op, (uint)opExecFlags);
                }
            }
            catch (Exception ex)
            {
                int hr = Marshal.GetHRForException(ex);
                mainFrm.ShowErrMsg(hr);

                return(false);
            }

            if ((flags & (int)DemoFlags.Output_Doc) != 0)
            {
                PDFXEdit.ICabNode      output     = op.Params.Root["Output"];
                PDFXEdit.IPXC_Document newCoreDoc = null;
                try
                {
                    if (output.Type == PDFXEdit.CabDataTypeID.dt_Array)
                    {
                        if (output.Count != 0)
                        {
                            newCoreDoc = (PDFXEdit.IPXC_Document)output[0].Unknown;
                        }
                    }
                    else
                    {
                        newCoreDoc = (PDFXEdit.IPXC_Document)output.Unknown;
                    }

                    if (newCoreDoc != null)
                    {
                        mainFrm.pdfCtl.OpenDocFrom(newCoreDoc);
                    }
                }
                catch { }
            }

            return(true);
        }
Exemplo n.º 5
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            PDFXEdit.IPXV_Document doc = pdfCtl.Doc;
            if (doc == null)
            {
                return;
            }

            PDFXEdit.IPXC_Document cdoc = doc.CoreDoc;

            do
            {
                bool newPage = curPage < 0;
                bool newWord = true;
                if (!newPage)
                {
                    uint wordsCnt = wordsRanges.Count / 2;

                    if (smoothHighlight && (curWord >= 0) && ((uint)curWord < wordsCnt))
                    {
                        int wl = wordsRanges[(uint)curWord * 2 + 1];
                        if ((curWordLen + 1) <= wl)
                        {
                            newWord = false;
                        }
                    }

                    if (newWord && ((uint)(curWord + 1) >= wordsCnt))
                    {
                        newPage = true;
                    }
                }

                if (newPage)
                {
                    if ((uint)(curPage + 1) >= cdoc.Pages.Count)
                    {
                        timer1.Stop();
                        endReached = true;
                        UpdateStartBtn();
                        return;
                    }

                    endReached = false;
                    curPage++;

                    PDFXEdit.IPXC_Page page = cdoc.Pages[(uint)curPage];

                    PDFXEdit.IPXC_PageText pageText = page.GetText(null);

                    pageSolidHighlight = null;
                    if (docHighlighter == null)
                    {
                        docHighlighter = doc.AddNewHighlighter(PDFXEdit.PXV_DocHighlightType.PXV_DocHighlight_Page);
                    }
                    else
                    {
                        docHighlighter.Clear();
                    }

                    wordsRanges.Clear();

                    uint charsCnt = pageText.CharsCount;
                    int  wb       = -1;
                    int  we       = 0;
                    for (uint i = 0; i < charsCnt; i++)
                    {
                        ushort ch        = pageText.CharCode[i];
                        uint   flg       = pageText.CharFlags[i];
                        bool   lineBegin = ((flg & (uint)(PDFXEdit.PXC_TextCharFlags.TCF_LineBegin)) != 0);
                        // bool wordSep = ((flg & (uint)(PDFXEdit.PXC_TextCharFlags.TCF_SearchWordSeparator)) != 0);
                        bool wordSep = ch <= 32 || ch == 160;
                        if (!wordSep && !lineBegin)
                        {
                            if (wb < 0)
                            {
                                wb = (int)i;
                            }
                            we = (int)i;
                        }
                        else
                        {
                            if (wb >= 0)
                            {
                                wordsRanges.Insert(wb);
                                wordsRanges.Insert(we - wb + 1);
                            }
                            if (wordSep)
                            {
                                wb = -1;
                            }
                            else                             // lineBegin==true
                            {
                                wb = we = (int)i;
                            }
                        }
                    }
                    if (wb >= 0)
                    {
                        wordsRanges.Insert(wb);
                        wordsRanges.Insert(we - wb + 1);
                    }

                    curWord    = -1;
                    curWordLen = 0;
                    continue;
                }

                if (newWord)
                {
                    curWord++;
                    curWordLen = 0;
                }

                int wordBegin = wordsRanges[(uint)curWord * 2];
                int wordLen   = wordsRanges[(uint)curWord * 2 + 1];

                if (smoothHighlight)
                {
                    curWordLen++;
                }
                else
                {
                    curWordLen = wordLen;
                }

                {
                    int wb = wordBegin;
                    int wl = curWordLen;

                    if (solidHighlight)
                    {
                        wb = 0;
                        wl = wordBegin + curWordLen;
                    }

                    if (useDocHighlighter)
                    {
                        wordRange.Clear();
                        wordRange.Insert(wb);
                        wordRange.Insert(wl);

                        if (pageSolidHighlight != null)
                        {
                            pageSolidHighlight.Remove();
                            pageSolidHighlight = null;
                        }

                        PDFXEdit.IUIX_Brush br = null;
                        PDFXEdit.IUIX_Pen   pn = null;

                        if (blueHighlight)
                        {
                            br = brush;
                            pn = pen;
                        }

                        PDFXEdit.IPXC_Page     pg     = cdoc.Pages[(uint)curPage];
                        PDFXEdit.IPXC_PageText pgText = pg.GetText(null);

                        PDFXEdit.IPXV_DocHighlightItem itm = docHighlighter.Add(pg, wordRange, br, pn, ref dha, (uint)(PDFXEdit.PXV_DocHighlightFlags.PXV_DocHighlightFlag_ShareBrush | PDFXEdit.PXV_DocHighlightFlags.PXV_DocHighlightFlag_SharePen));

                        // doc.ActiveView.PagesView.Obj.Redraw(); // this line is required for build <= 6.0.322.3. Look for actual dev. build: http://docu-track.co.uk/devbuilds/latest/DevRelease.x32.zip

                        if (solidHighlight || smoothHighlight)
                        {
                            pageSolidHighlight = itm;
                        }
                    }
                    else
                    {
                        HighlightQuads(doc, curPage, wb, wl);
                    }

                    // ensure visible last selected symbol
                    EnsureVisibleChar(doc, (uint)curPage, (uint)(wb + wl - 1));
                }

                break;
            }while (true);
        }