Matlab,Visio等生成的图片的字体嵌入问题解决方法

确保所有字体嵌入,是生成高质量学术论文的必要条件。但是在Windows下,总会遇到Matlab或Visio生成字体没有嵌入的问题,当然这个问题的解决办法有很多(例如,对于Visio可以这样做:直接拷贝到Adobe Illustrator(AI)中,另存为eps(选择为“为其他程序嵌入字体”)),这里介绍一种批量式的解决方法。看到有网友介绍,可以用GhostScript来进行来回转换。安装好GhostScript后,在其安装文件夹下的bin目录下,会有gswin64c.exe这个可执行程序(我这里是64位系统,32位系统对应的就是gswin32c.exe),把没有字体嵌入的eps文件拷贝至该目录下,运行:

 

gswin64c.exe -dNOPAUSE -dBATCH -dEPSCrop -q -sDEVICE=pdfwrite -dCompatibilityLevel#1.3 -dPDFSETTINGS=/prepress -dSubsetFonts=true -dEmbedAllFonts=true -sOutputFile=temp.pdf xxxx.eps


其中xxxx.eps就是需要转换的eps文件,这样生成了一个临时的temp.pdf文件,我们再运行下面的命令将临时pdf文件转为eps文件:

 

 

gswin64c.exe -q -dNOPAUSE -dBATCH -dNOCACHE -sDEVICE=epswrite -sOutputFile=yyyy.eps temp.pdf


其中yyyy.eps就是嵌入字体后的eps文件,通过这种方法,就可以将所有eps实现字体嵌入了。这样做固然方便,但是如果有很多文件需要处理,那手工运行命令还是挺复杂的。这里我提供一段简单的Java代码,我们可以将需要处理的eps文件都放在一个文件夹内,将文件夹拷贝到刚才说的bin目录下,在cmd方式下运行这段Java代码,可以批量实现转换(转换后的eps文件就在bin目录下,和原始文件文件名相同,但位置不同,这样可以方便LaTeX不进行任何修改就可以重新生成PDF)

 

 

import java.io.File;

import java.io.IOException;

 

public class gsBatch {

    public static void main(String[] args) {

        if(args.length!=1)

        {

            System.out.println("Usage: java gsBatch *Floder-to-handle*");

            System.exit(0);

        }

        String absoluteStartPath = System.getProperty("user.dir");

        File file = new File(absoluteStartPath+"\\"+args[0]);

        gsBatch t = new gsBatch();

        t.dotGenerator(file);

    }

 

    private void dotGenerator(File file) {

        // TODO Auto-generated method stub

        File[] fileList = file.listFiles();

        int i=0;

        while(i<fileList.length){

            if (fileList[i].isDirectory()==true){

                dotGenerator(fileList[i]);//使用递归方法对所有子目录分析

            }

            else if (fileList[i].getName().contains(".eps")){

                String relativePath = file.getPath();

                String commandConvertPDF = new String("cmd /c gswin64c.exe -dNOPAUSE -dBATCH -dEPSCrop -q -sDEVICE=pdfwrite -dCompatibilityLevel#1.3 -dPDFSETTINGS=/prepress -dSubsetFonts=true -dEmbedAllFonts=true -sOutputFile=temp.pdf  \""+relativePath+"\"\\"+fileList[i].getName());

                System.out.println(commandConvertPDF);

                String commandConvertEPS = new String("cmd /c gswin64c.exe -q -dNOPAUSE -dBATCH -dNOCACHE -sDEVICE=epswrite -sOutputFile="+fileList[i].getName()+" temp.pdf");

 

                try {

                    Runtime.getRuntime().exec(commandConvertPDF);

                } catch (IOException e) {

                    // TODO Auto-generated catch block

                    e.printStackTrace();

                }

 

                try{Thread.sleep(1000);}

                catch(Exception e){}

 

                try {

                    Runtime.getRuntime().exec(commandConvertEPS);

                } catch (IOException e) {

                    // TODO Auto-generated catch block

                    e.printStackTrace();

                }

 

                try{Thread.sleep(1000);}

                catch(Exception e){}

            }

            i++;

        }

    }

}


通过这种方法,就可以批量处理eps文件了(如果不会编译Java,则不用去考虑这种方法),最终生成的PDF文件可以用Acrobat等软件打开——文件——属性——字体,如果所有字体都显示“已嵌入子集”,则说明已经成功嵌入所有字体了。

 




 

你可能感兴趣的:(matlab)