歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Matlab,Visio等生成的圖片的字體嵌入問題解決方法

Matlab,Visio等生成的圖片的字體嵌入問題解決方法

日期:2017/3/1 9:55:31   编辑:Linux編程

確保所有字體嵌入,是生成高質量學術論文的必要條件。但是在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等軟件打開——文件——屬性——字體,如果所有字體都顯示“已嵌入子集”,則說明已經成功嵌入所有字體了。

Copyright © Linux教程網 All Rights Reserved