예제 #1
0
        private void Redraw_PDF()
        {
            ProgressBar1 prBar = new ProgressBar1();
            try
            {
                prBar.Show();
                prBar.Refresh();
                int Rect_size_for_20 = page_Width / 22;
                if (workspace_ob.op.orientation_of_document == 0)
                    Rect_size = (page_Width) / (workspace_ob.field_ex.width + 2);
                else
                    Rect_size = (page_Height) / (workspace_ob.field_ex.heigth + 2);
                height = workspace_ob.field_ex.heigth;
                width = workspace_ob.field_ex.width;
                keys_count = workspace_ob.keys.Count;

                int nID = axPXV_Control1.Inst.Str2ID("op.document.insertEmptyPages", false); //Create new "InsertEmptyPages" operation iD
                PDFXEdit.IOperation pOp = axPXV_Control1.Inst.CreateOp(nID); //Create new operation
                PDFXEdit.ICabNode input = pOp.Params.Root["Input"]; //Create "Input" id to current operation
                IPXC_Document pDoc = axPXV_Control1.Doc.CoreDoc;

                input.v = pDoc; //Specify that working with current document
                PDFXEdit.ICabNode options = pOp.Params.Root["Options"]; //Create "Option" id to current operation
                options["PaperType"].v = 2; //Apply custom paper type

                if (workspace_ob.op.orientation_of_document == 0)
                {
                    options["Width"].v = 800;
                    options["Height"].v = 1200;
                }
                else
                {
                    options["Width"].v = 1200;
                    options["Height"].v = 800;
                }
                pOp.Do(); //Applying creation new pages
                nID = axPXV_Control1.Inst.Str2ID("op.document.deletePages", false); //Create new "deletePages" operation id
                pOp = axPXV_Control1.Inst.CreateOp(nID); //Create new operation
                input = pOp.Params.Root["Input"];  //Create "Input" id to current operation
                input.v = pDoc; //Specify that working with current document
                options = pOp.Params.Root["Options"]; //Create "Option" id to current operation
                options["PagesRange.Custom"].v = 0; //Specify range of deleting pages. In this case it is just one zeroth page
                pOp.Do();//Applying deletion range of pages

                var page = axPXV_Control1.Doc.CoreDoc.Pages[0]; //Create handler to first page
                var CC = axPXV_Control1.Doc.CoreDoc.CreateContentCreator(); //Create "Content Creator" for drawing on page.

                if (workspace_ob.op.orientation_of_document == 0)
                {
                    Redraw_field_vertical(width, height, CC, page);
                    Draw_Keys_Vartical(ref CC, ref page);
                }
                else if (workspace_ob.op.orientation_of_document == 1)
                {
                    Redraw_field_horisontal(width, height, CC, page);
                    Draw_Keys_Horisontal(ref CC, ref page);
                }
                CC.SetLineWidth(0.5); //Set line  width
                CC.StrokePath(true); //Set end of drawing current element

                nID = axPXV_Control1.Inst.Str2ID("op.document.resizePages", false);
                pOp = axPXV_Control1.Inst.CreateOp(nID);
                input = pOp.Params.Root["Input"];
                input.v = pDoc;
                options = pOp.Params.Root["Options"];
                options["PaperType"].v = 2; //Document values table
                options["StdPaperIndex"].v = 4; //A2
                options["ScalePage"].v = true;
                options["ConstraintProportions"].v = true;
                options["PagesRange.Filter"].v = 1;
                if (workspace_ob.op.orientation_of_document == 1)
                {
                    options["Width"].v = 841.89;
                    options["Height"].v = 595.276;
                }
                pOp.Do();
                prBar.Hide();
                prBar.Refresh();
            }
            catch 
            {
                MessageBox.Show("Generate PDF again.");
                prBar.Hide();
                prBar.Refresh();
                return;
            }
            prBar.Hide();
            prBar.Refresh();
        }
예제 #2
0
        private void openFile(bool dragAndDrop, int slIndex = 0, string path_in = "")
        {
            
            this.Enabled = false;
            ProgressBar1 prgBar = new ProgressBar1();
            string path = path_in;
            int selected = slIndex;
            if (dragAndDrop == false)
            {
                openFileDialog1.Filter = "Image Files(*.png; *.jpeg; *.gif; *bmp; *.jpg; *.ico; *.pcx; *.ppm; *.tiff; *.tif; *pbm; *.dcx; *.wmf)| *.png; *.jpeg; *.gif; *bmp; *.jpg; *.ico; *.pcx; *.ppm; *.tiff; *.tif; *pbm; *.dcx; *.wmf|Configuration Files(*.cnf)| *.cnf|All Files| *.*";
                openFileDialog1.DefaultExt = "";
                
                if(Directory.Exists(Application.StartupPath.ToString() + "\\samples\\")){
                    openFileDialog1.InitialDirectory = Application.StartupPath.ToString() + "\\samples\\";
                }
                openFileDialog1.FileName = "";
                openFileDialog1.RestoreDirectory = true;
                if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    selected = openFileDialog1.FilterIndex;
                    path = openFileDialog1.FileName;
                }
                else
                {
                    this.Enabled = true;
                    return;
                }
            }
            
            #region open_image
            if (selected == 1)
            {
                Bitmap temp = null;
                try
                {
                    prgBar.Show();
                    prgBar.Refresh();

                    OpenSaveImage.OpenImage(axPXV_Control1, out temp, path);
                    if(temp == null)
                    {
                        MessageBox.Show("File is incorrect.");
                        this.Enabled = true;
                        prgBar.Hide();
                        prgBar.Refresh();
                        return;
                    }
                    Image img = (Image)temp;
                    Graphics g = Graphics.FromImage(temp);
                    clean_keys();
                    img = ResizeOrigImg(img, workspace_ob.field_ex.width, workspace_ob.field_ex.heigth);


                    Bitmap bmp = new Bitmap(img);
                    for (int i = 0; i < workspace_ob.field_ex.width; i++)
                    {
                        for (int j = 0; j < workspace_ob.field_ex.heigth; j++)
                        {
                            bool ifColorExist = false;
                            for (int z = 0; z < workspace_ob.keys.Count; z++)
                            {
                                if (workspace_ob.keys[z].clr == bmp.GetPixel(i, j)) ifColorExist = true;
                            }
                            if (ifColorExist == false) workspace_ob.keys.Add(new Workspace.key("", bmp.GetPixel(i, j)));
                        }
                    }
                    
                    Minimize_All_Image_Colors();
                    for (int i = 0; i < workspace_ob.field_ex.width; i++)
                    {
                        for (int j = 0; j < workspace_ob.field_ex.heigth; j++)
                        {
                            workspace_ob.field_ex.clr_fild[i][j] = Minimize_Image_Colors(bmp.GetPixel(i, j));
                            bool ifColorExist = false;
                            for (int z = 0; z < workspace_ob.keys.Count; z++)
                            {
                                if (workspace_ob.keys[z].clr == workspace_ob.field_ex.clr_fild[i][j]) 
                                    ifColorExist = true;
                            }
                            if (ifColorExist == false) 
                                workspace_ob.keys.Add(new Workspace.key("", workspace_ob.field_ex.clr_fild[i][j]));
                        }
                    }
                    for (int i = 0; i <= workspace_ob.field_ex.width; i++)
                    {
                        for (int j = 0; j <= workspace_ob.field_ex.width; j++)
                            workspace_ob.field_ex.str_fild[i][j] = "";
                    }

                    GenerateNumbers();

                    UpdateDataGridView1();
                    if (workspace_ob.keys.Count >= 2)
                    {
                        optionsToolStripMenuItem1.Enabled = true;
                        button_options.Enabled = true;
                    }
                    else
                    {
                        optionsToolStripMenuItem1.Enabled = false;
                        button_options.Enabled = false;
                        MessageBox.Show("Please, add more keys.");
                    }
                    prgBar.Hide();
                    prgBar.Refresh();
                }
                catch(FormatException)
                {
                    textBox_info.Text = "File is incorrect.";
                    this.Enabled = true;
                    prgBar.Hide();
                    prgBar.Refresh();
                    return;
                }
                prgBar.Hide();
                prgBar.Refresh();
            }
            #endregion
            #region open template
            else if (selected == 2)
            {
                string input = path;
                string for_open;
                using (System.IO.StreamReader streamReader = new System.IO.StreamReader(@input, Encoding.UTF8))
                {
                    for_open = streamReader.ReadToEnd();
                }
                try
                {
                    OpenSave.opens_string_for_save_conf(for_open, workspace_ob);
                }
                catch (System.FormatException)
                {
                    textBox_info.Text = "File is incorrect. Please, delete it.";
                    MessageBox.Show("File is incorrect.");
                }
                GenerateNumbers();
            }
            
            #endregion  
            Refresh();
            this.Enabled = true;
            this.Activate(); 
        }
예제 #3
0
파일: Pdf.cs 프로젝트: DCeres/smartcoloring
        private void Redraw_PDF()
        {
            ProgressBar1 prBar = new ProgressBar1();

            try
            {
                prBar.Show();
                prBar.Refresh();
                int Rect_size_for_20 = page_Width / 22;
                if (workspace_ob.op.orientation_of_document == 0)
                {
                    Rect_size = (page_Width) / (workspace_ob.field_ex.width + 2);
                }
                else
                {
                    Rect_size = (page_Height) / (workspace_ob.field_ex.heigth + 2);
                }
                height     = workspace_ob.field_ex.heigth;
                width      = workspace_ob.field_ex.width;
                keys_count = workspace_ob.keys.Count;

                int nID = axPXV_Control1.Inst.Str2ID("op.document.insertEmptyPages", false); //Create new "InsertEmptyPages" operation iD
                PDFXEdit.IOperation pOp   = axPXV_Control1.Inst.CreateOp(nID);               //Create new operation
                PDFXEdit.ICabNode   input = pOp.Params.Root["Input"];                        //Create "Input" id to current operation
                IPXC_Document       pDoc  = axPXV_Control1.Doc.CoreDoc;

                input.v = pDoc;                                         //Specify that working with current document
                PDFXEdit.ICabNode options = pOp.Params.Root["Options"]; //Create "Option" id to current operation
                options["PaperType"].v = 2;                             //Apply custom paper type

                if (workspace_ob.op.orientation_of_document == 0)
                {
                    options["Width"].v  = 800;
                    options["Height"].v = 1200;
                }
                else
                {
                    options["Width"].v  = 1200;
                    options["Height"].v = 800;
                }
                pOp.Do();                                                               //Applying creation new pages
                nID     = axPXV_Control1.Inst.Str2ID("op.document.deletePages", false); //Create new "deletePages" operation id
                pOp     = axPXV_Control1.Inst.CreateOp(nID);                            //Create new operation
                input   = pOp.Params.Root["Input"];                                     //Create "Input" id to current operation
                input.v = pDoc;                                                         //Specify that working with current document
                options = pOp.Params.Root["Options"];                                   //Create "Option" id to current operation
                options["PagesRange.Custom"].v = 0;                                     //Specify range of deleting pages. In this case it is just one zeroth page
                pOp.Do();                                                               //Applying deletion range of pages

                var page = axPXV_Control1.Doc.CoreDoc.Pages[0];                         //Create handler to first page
                var CC   = axPXV_Control1.Doc.CoreDoc.CreateContentCreator();           //Create "Content Creator" for drawing on page.

                if (workspace_ob.op.orientation_of_document == 0)
                {
                    Redraw_field_vertical(width, height, CC, page);
                    Draw_Keys_Vartical(ref CC, ref page);
                }
                else if (workspace_ob.op.orientation_of_document == 1)
                {
                    Redraw_field_horisontal(width, height, CC, page);
                    Draw_Keys_Horisontal(ref CC, ref page);
                }
                CC.SetLineWidth(0.5); //Set line  width
                CC.StrokePath(true);  //Set end of drawing current element

                nID     = axPXV_Control1.Inst.Str2ID("op.document.resizePages", false);
                pOp     = axPXV_Control1.Inst.CreateOp(nID);
                input   = pOp.Params.Root["Input"];
                input.v = pDoc;
                options = pOp.Params.Root["Options"];
                options["PaperType"].v             = 2; //Document values table
                options["StdPaperIndex"].v         = 4; //A2
                options["ScalePage"].v             = true;
                options["ConstraintProportions"].v = true;
                options["PagesRange.Filter"].v     = 1;
                if (workspace_ob.op.orientation_of_document == 1)
                {
                    options["Width"].v  = 841.89;
                    options["Height"].v = 595.276;
                }
                pOp.Do();
                prBar.Hide();
                prBar.Refresh();
            }
            catch
            {
                MessageBox.Show("Generate PDF again.");
                prBar.Hide();
                prBar.Refresh();
                return;
            }
            prBar.Hide();
            prBar.Refresh();
        }