נכתב ע"י 5127109;2099272:
זה לא ממש סקריפט לאינדי כמו שאנחנו מכירים אלא באמת תכנית חיצונית שמסמנת את המסמך הנוכחי כמטרה ושם עושה כל מיני דברים. אפשר לשלב טפסים ופקדים שאליהם אנו רגילים מהVS. אין בזה שום חסרון אלא נוחות והרגל.
אכן.
בנתיים לקחתי מה שהעלתם ופישטתי אותו מעט, מצורף טקסט שלם של תוכנית קונסול.
כדי להפעיל אותו יש מקודם ליצור רפרנס לCOM בשם אינדזיין.
using InDesign;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace onindesign
{
class Program
{
static void Main(string[] args)
{
Type type = Type.GetTypeFromProgID("InDesign.Application");
InDesign.Application application = (InDesign.Application)Activator.CreateInstance(type);
// Set unit type
application.ViewPreferences.HorizontalMeasurementUnits = idMeasurementUnits.idMillimeters;
application.ViewPreferences.VerticalMeasurementUnits = idMeasurementUnits.idMillimeters;
// Create new document
application.Documents.Add(true, application.DocumentPresets.FirstItem());
// Get active document and change some settings
Document document = application.ActiveDocument;
document.DocumentPreferences.FacingPages = false;
document.DocumentPreferences.PageWidth = 210;
document.DocumentPreferences.PageHeight = 297;
// Get first page (already created) and set margins
Page page = (Page)document.Pages[1];
page.MarginPreferences.Top = 10;
page.MarginPreferences.Bottom = 10;
page.MarginPreferences.Left = 20;
page.MarginPreferences.Right = 10;
// Create rectangle and fit an image into it
InDesign.Rectangle rectangle = page.Rectangles.Add(document.Layers.FirstItem(), idLocationOptions.idUnknown, page);
rectangle.GeometricBounds = new[] { 20, 30, 120, 130 };
//rectangle.Place(@"c:\temp\sample.png", false);
rectangle.Fit(idFitOptions.idContentToFrame);
// Create second page and set margins
page = document.Pages.Add(idLocationOptions.idUnknown, document);
page.MarginPreferences.Top = 10;
page.MarginPreferences.Bottom = 10;
page.MarginPreferences.Left = 20;
page.MarginPreferences.Right = 10;
// Create a text frame and add some text
TextFrame textFrame = page.TextFrames.Add(document.Layers.FirstItem(), idLocationOptions.idUnknown, page);
textFrame.GeometricBounds = new[] { 20, 30, 120, 130 };
textFrame.Contents = "line1\rline2\rline3";
IEnumerator paragraphs = textFrame.Paragraphs.GetEnumerator();
for (int j = 0; j < textFrame.Paragraphs.Count; j++)
{
paragraphs.MoveNext();
Paragraph paragraph = ((Paragraph)paragraphs.Current);
paragraph.Justification = idJustification.idCenterAlign;
paragraph.PointSize = 15 - j;
paragraph.FontStyle = "Regular";
paragraph.AppliedFont = "Verdana";
}
}
}
}