Skip to content
Mallikarjun H T edited this page Aug 13, 2021 · 1 revision

Welcome to the Csharp-Adobe-Automation with Mallikarjun!

Creating Document

// instance of application (InDesign)
Type t = Type.GetTypeFromProgID("InDesign.Application");
InDesign.Application application = (InDesign.Application)Activator.CreateInstance(t);
// Create a document 
Document doc = application.Documents.Add(false);

saving document

//savig document
doc.Save("Folder\\File_Name.indd", false, "Comments here", false);

Creating Text Frame

// add frame to page
page.TextFrames.Add();
InDesign.TextFrame frames = (InDesign.TextFrame)page.TextFrames.FirstItem();
// set x,y and width, height for box
frames.GeometricBounds = new string[4] { "4p", "4p", "62p", "47p" };

Import Word Document

//place document to page
page.Place("Folder\\File_Name.docx", page ,layer, false, true);
//place document to frame
frames.Place("file path of the document", false);

using in-built script FindChangeByList

application.DoScript(@"Path to script \scripts\FindChangeByList.jsx", InDesign.idScriptLanguage.idJavascript);

Apply Greh to find email and url's

// apply grep to document
InDesign.FindGrepPreference findGrepPreference = (InDesign.FindGrepPreference)application.FindGrepPreferences;
findGrepPreference.FindWhat = "([\\S]+[.][\\S]+)";
InDesign.ChangeGrepPreference changeText = (InDesign.ChangeGrepPreference)application.ChangeGrepPreferences;
changeText.AppliedCharacterStyle = "[No character style]";
var results = doc.FindGrep();
doc.ChangeGrep();

Apply Paragraph style

// creating style object
InDesign.ParagraphStyle paragraphStyle = paragraph.AppliedParagraphStyle;
paragraphStyle.Name = "Title Center";
paragraphStyle.AppliedFont = "Sans";
paragraphStyle.FontStyle = "Bold";
paragraphStyle.Justification = InDesign.idJustification.idCenterAlign;
paragraphStyle.PointSize = 7;
paragraphStyle.Leading = 8.4;
paragraphStyle.SpaceAfter = 0.05;
paragraphStyle.Hyphenation = false;
// apply para style
paragraph.AppliedParagraphStyle = paragraphStyle;

Apply Character Style

InDesign.Character characters = (InDesign.Character)paragraph.Characters[i];
if (characters.FontStyle == "Bold"){
      characters.FontStyle = "Bold";
      characters.AppliedFont = "Sans";
}