🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.scripting.indesign
Article #8236

Re: replace missing fonts

#8236
From: bobac
Date: Wed, 25 Oct 2006 09:56
49 lines
2562 bytes
Peter's solution is very helpful but I found it difficult to use with 'fontStyle' in addition in my case. So I try to do it like this:

var inputFilePathName = "/c/fileWithMissingFonts.inx";
var outputFilePathName = "/c/fileWithOutMissingFonts.inx";

// open document
var myFile = File(inputFilePathName);
var myDocument = app.open(myFile);

var defFont = app.fonts.item("Arial");
ReplaceMissingFont(myDocument, pageN, defFont);	

// save new doc
myDocument.exportFile(ExportFormat.indesignInterchange, new File(outputFilePathName));
myDocument.close(SaveOptions.no);

//-----------------------------------------------------
function ReplaceMissingFont(doc, defFont)
{
  with(doc)
  {		
    try
    {
      if(textDefaults.appliedFont.status == FontStatus.notAvailable)
        textDefaults.font = defFont;
    }
    catch(error)
    {
      textDefaults.font = defFont;
    }

ItemsChangeFont(paragraphStyles, defFont);
    ItemsChangeFont(characterStyles, defFont);

for (j=0; j < masterSpreads.length; j++) { ReplaceTextMissingFont(masterSpreads[j], defFont);	 } } ReplaceTextMissingFont(doc, defFont);	 }

function ReplaceTextMissingFont(doc, defFont)
{
  //document or masterSpread
  with(doc)
  {		
    for (i=0; i < allPageItems.length; i++) { if (allPageItems[i] == "[object TextFrame]") { with (allPageItems[i]) { ItemsChangeFont(paragraphs, defFont);	 ItemsChangeFont(textStyleRanges, defFont); } } } }

function ItemsChangeFont(items, defFont)
{	
  //Paragraphs or TextStyleRanges
  for (k=0; k < items.length ; k++) {	 with(items[k]) { //apply default font try { if (appliedFont && appliedFont.status == FontStatus.notAvailable) { appliedFont = defFont; appliedFont.fontStyle = "Regular"; }	 } catch(error){} } } }

Hope it may help somebody :)
Technical Details
Message-ID: <3bc20f96.2@webcrossing.la2eafNXanI>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx01.iad01.newshosting.com!newshosting.com!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.freenet.de!news.osn.de!diablo1.news.osn.de!news2.arglkargh.de!news.ecp.fr!news.stben.net!webcrossing
References: <3bc20f96.-1@webcrossing.la2eafNXanI>

Show Full Headers
Complete Article Headers
X-Google-Thread: f939a,4f6931a7ba7f9b09
X-Google-Attributes: gidf939a,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: bobac@adobeforums.com
Newsgroups: adobe.scripting.indesign
Subject: Re: replace missing fonts
Message-ID: <3bc20f96.2@webcrossing.la2eafNXanI>
Date: Wed, 25 Oct 2006 02:56:19 -0700
References: <3bc20f96.-1@webcrossing.la2eafNXanI>
Lines: 85
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx01.iad01.newshosting.com!newshosting.com!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.freenet.de!news.osn.de!diablo1.news.osn.de!news2.arglkargh.de!news.ecp.fr!news.stben.net!webcrossing