Exemplo n.º 1
0
        private void ExportJPG(Page page)
        {
            if (page.Shapes.Count == 0)
            {
                return;
            }
            String namen;

            if (rbDocument.Checked)
            {
                namen = app.ActiveDocument.Name;
            }
            else
            {
                namen = outFileName;
            }
            String              DestDir, FileName;
            ExportFilter        ef;
            StructExportOptions seo = new StructExportOptions();

            seo.AntiAliasingType = cbSmooth.Checked ? cdrAntiAliasingType.cdrNormalAntiAliasing : cdrAntiAliasingType.cdrNoAntiAliasing;
            seo.ImageType        = (cdrImageType)cbCM.SelectedIndex;
            seo.Compression      = (cdrCompressionType)cbYSSF.SelectedIndex;
            seo.UseColorProfile  = cbUseColorProfile.Checked;
            int s = 72;

            if (cboFbl.Text != "")
            {
                int.TryParse(cboFbl.Text, out s);
            }
            seo.ResolutionX = s;
            seo.ResolutionY = s;
            DestDir         = tbPath.Text;
            if (!DestDir.EndsWith("\\"))
            {
                DestDir += "\\";
            }
            if (rbSelection.Checked)
            {
                FileName = DestDir + namen + getPageName(page) + getIndex() + getUnit(0, 0) + ".jpg";
                page.Activate();
                ef = app.ActiveDocument.ExportEx(FileName, cdrFilter.cdrJPEG, cdrExportRange.cdrSelection, seo);
                ef.Finish();
            }
            else if (cbPageScope.Checked)
            {
                Rect rct = new Rect();
                if (cbPageHalf.Checked)
                {
                    bool hz = cbHalfOp.SelectedIndex == 0 ? true : false;
                    rct.x = page.LeftX;
                    rct.y = page.BottomY;
                    if (hz)
                    {
                        rct.Width  = page.SizeWidth;
                        rct.Height = page.SizeHeight / 2;

                        rct.y = page.SizeHeight / 2;
                    }
                    else
                    {
                        rct.Width  = page.SizeWidth / 2;
                        rct.Height = page.SizeHeight;
                    }
                    seo.set_ExportArea(rct);
                    FileName = DestDir + namen + getPageName(page) + "-1前" + getIndex() + getUnit(0, 0) + ".jpg";
                    page.Activate();
                    ef = app.ActiveDocument.ExportEx(FileName, cdrFilter.cdrJPEG, cdrExportRange.cdrCurrentPage, seo);
                    ef.Finish();
                    if (hz)
                    {
                        rct.y = page.BottomY;
                    }
                    else
                    {
                        rct.x = page.SizeWidth / 2;
                    }
                    seo.set_ExportArea(rct);
                    FileName = DestDir + tbName.Text + getPageName(page) + "-2后" + getIndex() + getUnit(0, 0) + ".jpg";
                    page.Activate();
                    ef = app.ActiveDocument.ExportEx(FileName, cdrFilter.cdrJPEG, cdrExportRange.cdrCurrentPage, seo);
                    ef.Finish();
                    return;
                }
                else
                {
                    rct.x      = page.LeftX;
                    rct.y      = page.BottomY;
                    rct.Width  = page.SizeWidth;
                    rct.Height = page.SizeHeight;
                    seo.set_ExportArea(rct);
                    //MessageBox.Show("x:" + rct.x + ",y:" + rct.y + ",width:" + rct.Width + ",height" + rct.Height);
                }
            }
            FileName = DestDir + tbName.Text + getPageName(page) + getIndex() + getUnit(0, 0) + ".jpg";
            page.Activate();
            ef = app.ActiveDocument.ExportEx(FileName, cdrFilter.cdrJPEG, cdrExportRange.cdrCurrentPage, seo);
            ef.Finish();
        }
Exemplo n.º 2
0
        private void ExportJPG(Page page)
        {
            if (page.Shapes.Count == 0)
            {
                addMessage("页面无对象");
                return;
            }
            page.Activate();
            String namen;

            if (rbDocument.Checked)
            {
                namen = application.ActiveDocument.Name;
            }
            else
            {
                namen = outFileName;
            }
            application.ActiveDocument.Unit = cdrUnit.cdrPixel;
            cdrFilter           filter = getFilter();
            String              ext = getExt();
            String              DestDir, FileName;
            ExportFilter        ef;
            StructExportOptions seo = application.CreateStructExportOptions();

            seo.AntiAliasingType = cbSmooth.Checked ? cdrAntiAliasingType.cdrSupersampling : cdrAntiAliasingType.cdrNoAntiAliasing;
            seo.ImageType        = (cdrImageType)cbCM.SelectedIndex;
            seo.Compression      = (cdrCompressionType)cbYSSF.SelectedIndex;
            seo.UseColorProfile  = cbUseColorProfile.Checked;

            //特别注意,透明度在jpg等无透明的格式的时候不能为True,不然光滑处理将会失效
            seo.Transparent          = checkBox_trans.Checked;
            seo.AlwaysOverprintBlack = checkBox_OverPrintBlack.Checked;
            seo.MaintainLayers       = checkBox_MaintainLayers.Checked;


            int s = 72;

            if (cboFbl.Text != "")
            {
                int.TryParse(cboFbl.Text, out s);
            }
            seo.ResolutionX = s;
            seo.ResolutionY = s;

            double sc = 1;

            if (comboBox_SC.Text != "")
            {
                double.TryParse(comboBox_SC.Text, out sc);
            }
            if (sc == 0)
            {
                addMessage("放大部数不能为0,取消。。");
                return;
            }
            if (sc != 1)
            {
                double[] dt = getSize(page);

                seo.SizeX = (int)(dt[0] * sc * (s / 300.0));
                seo.SizeY = (int)(dt[1] * sc * (s / 300.0));
            }

            DestDir = tbPath.Text;
            if (!DestDir.EndsWith("\\"))
            {
                DestDir += "\\";
            }
            if (rbSelection.Checked)
            {
                FileName = DestDir + namen + getPageName(page) + getIndex() + getUnit(0, 0) + ext;
                if (CheckFilExists(FileName))
                {
                    addMessage("文件已存在,取消");
                    return;
                }
                page.Activate();
                ef = application.ActiveDocument.ExportEx(FileName, filter, cdrExportRange.cdrSelection, seo);
                ef.Finish();
                return;
            }
            else if (rbSelRge.Checked)
            {
                Rect       rct = application.CreateRect();
                ShapeRange sr  = application.ActiveSelectionRange;
                rct.x      = sr.LeftX;
                rct.y      = sr.BottomY;
                rct.Width  = sr.SizeWidth;
                rct.Height = sr.SizeHeight;
                seo.set_ExportArea(ref rct);
                FileName = DestDir + namen + getPageName(page) + getIndex() + getUnit(0, 0) + ext;
                if (CheckFilExists(FileName))
                {
                    addMessage("文件已存在,取消");
                    return;
                }
                page.Activate();
                ef = application.ActiveDocument.ExportEx(FileName, filter, cdrExportRange.cdrCurrentPage, seo);
                ef.Finish();
                return;
            }
            else if (cbPageScope.Checked)
            {
                Rect rct = application.CreateRect();
                if (cbPageHalf.Checked)
                {
                    bool hz = cbHalfOp.SelectedIndex == 0 ? true : false;
                    rct.x = page.LeftX;
                    rct.y = page.BottomY;
                    if (hz)
                    {
                        rct.Width  = page.SizeWidth;
                        rct.Height = page.SizeHeight / 2;

                        rct.y = page.SizeHeight / 2;
                    }
                    else
                    {
                        rct.Width  = page.SizeWidth / 2;
                        rct.Height = page.SizeHeight;
                    }
                    seo.set_ExportArea(rct);
                    FileName = DestDir + namen + getPageName(page) + "-1前" + getIndex() + getUnit(0, 0) + ext;
                    if (CheckFilExists(FileName))
                    {
                        addMessage("文件已存在,取消");
                        return;
                    }
                    ef = application.ActiveDocument.ExportEx(FileName, filter, cdrExportRange.cdrCurrentPage, seo);
                    ef.Finish();
                    if (hz)
                    {
                        rct.y = page.BottomY;
                    }
                    else
                    {
                        rct.x = page.SizeWidth / 2;
                    }
                    seo.set_ExportArea(rct);
                    FileName = DestDir + namen + getPageName(page) + "-2后" + getIndex() + getUnit(0, 0) + ext;
                    if (CheckFilExists(FileName))
                    {
                        addMessage("文件已存在,取消");
                        return;
                    }
                    ef = application.ActiveDocument.ExportEx(FileName, filter, cdrExportRange.cdrCurrentPage, seo);
                    ef.Finish();
                    return;
                }
                else
                {
                    rct = application.CreateRect(page.LeftX, page.BottomY, page.SizeWidth, page.SizeHeight);
                    //rct.x = page.LeftX;
                    //rct.y = page.BottomY;
                    //rct.Width = page.SizeWidth;
                    //rct.Height = page.SizeHeight;
                    seo.set_ExportArea(rct);
                    //MessageBox.Show("x:" + rct.x + ",y:" + rct.y + ",width:" + rct.Width + ",height" + rct.Height);
                }
            }
            FileName = DestDir + namen + getPageName(page) + getIndex() + getUnit(0, 0) + ext;
            if (CheckFilExists(FileName))
            {
                addMessage("文件已存在,取消");
                return;
            }
            ef = application.ActiveDocument.ExportEx(FileName, filter, cdrExportRange.cdrCurrentPage, seo);
            ef.Finish();
        }