/// <summary>
        /// Sets the export options of the indesign document to HTML
        /// </summary>
        /// <param name="doc"></param>
        protected void SetInDesignHtmlExportOptions(InDesignDocument doc)
        {
            // General export options
            doc.HTMLExportPreferences.ExportSelection          = false;
            doc.HTMLExportPreferences.ExportOrder              = idExportOrder.idLayoutOrder;
            doc.HTMLExportPreferences.BulletExportOption       = idBulletListExportOption.idUnorderedList;
            doc.HTMLExportPreferences.NumberedListExportOption = idNumberedListExportOption.idOrderedList;
            doc.HTMLExportPreferences.ViewDocumentAfterExport  = true;

            // Image export options
            doc.HTMLExportPreferences.ImageExportOption        = idImageExportOption.idOptimizedImage;
            doc.HTMLExportPreferences.PreserveLayoutAppearence = true;
            doc.HTMLExportPreferences.ImageExportResolution    = idImageResolution.idPpi150;
            doc.HTMLExportPreferences.CustomImageSizeOption    = idImageSizeOption.idSizeFixed;
            doc.HTMLExportPreferences.ImageAlignment           = idImageAlignmentType.idAlignCenter;
            doc.HTMLExportPreferences.ImageSpaceBefore         = 0;
            doc.HTMLExportPreferences.ImageSpaceAfter          = 0;
            //doc.HTMLExportPreferences.ApplyImageAlignmentToAnchoredObjectSettings = true;
            doc.HTMLExportPreferences.ImageConversion                = idImageConversion.idJPEG;
            doc.HTMLExportPreferences.JPEGOptionsQuality             = idJPEGOptionsQuality.idMedium;
            doc.HTMLExportPreferences.JPEGOptionsFormat              = idJPEGOptionsFormat.idProgressiveEncoding;
            doc.HTMLExportPreferences.IgnoreObjectConversionSettings = false;

            // Advanced export options
            //doc.HTMLExportPreferences.CSSExportOption = idStyleSheetExportOption.idEmbeddedCSS;
            //doc.HTMLExportPreferences.IncludeCSSDefinition = true;
            doc.HTMLExportPreferences.PreserveLocalOverride = false;
        }
Пример #2
0
    public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
    {
        try
        {
            Type        type        = Type.GetTypeFromProgID("InDesign.Application");
            Application inDesignApp = (Application)Activator.CreateInstance(type);

            InDesign.Document inDesignDocument = inDesignApp.Documents.Add();

            //Create 5 new blank pages
            for (var i = 0; i < 5; i++)
            {
                inDesignDocument.Pages.Add(idLocationOptions.idAtBeginning);
            }

            return(Result.Succeeded);
        }
        catch (Exception ex)
        {
            message = ex.Message;
            return(Result.Failed);
        }
    }
        /// <summary>
        /// Converts the InDesign document input file into OneNote
        /// </summary>
        /// <param name="inputFile"></param>
        /// <param name="outputDir"></param>
        /// <returns></returns>
        public virtual bool ConvertInDesignToOneNote(string inputFile, string outputDir)
        {
#if INDESIGN_INSTALLED
            // get the file name
            string inputFileName = Path.GetFileNameWithoutExtension(inputFile);

            // gets the InDesign App
            Type inDesignAppType = Type.GetTypeFromProgID(ConfigurationManager.AppSettings.Get("InDesignProgId"));
            if (inDesignAppType == null)
            {
                throw new InvalidOperationException("Failed to find InDesign application. Please ensure that it is installed and is running on your machine.");
            }

            InDesignApplication app = (InDesignApplication)Activator.CreateInstance(inDesignAppType, true);

            // open the indd file
            try
            {
                app.Open(inputFile);
            }
            catch (Exception e)
            {
                Console.WriteLine(@"Error in ConvertInDesignToOneNote for file {0}: {1}", inputFile, e.Message);
                return(false);
            }
            InDesignDocument doc = app.ActiveDocument;

            // temp directory for html
            string htmlDir = Utility.CreateDirectory(Utility.NewFolderPath(outputDir, "html"));

            // Get the file name
            string htmlFile = Utility.NewFilePath(htmlDir, inputFileName, HtmlFileExtension);

            // Save the html file
            SetInDesignHtmlExportOptions(doc);
            doc.Export(idExportFormat.idHTML, htmlFile);

            // Create a new OneNote Notebook
            var    note       = new OneNoteGenerator(outputDir);
            string notebookId = note.CreateNotebook(GetSupportedInputFormat());
            string sectionId  = note.CreateSection(inputFileName, notebookId);


            // get the html
            var htmlDoc = new HtmlDocument();
            htmlDoc.Load(htmlFile);

            // change the links to have the full path
            ModifyInDesignHtmlLinks(htmlDoc, htmlDir);

            // get the title
            string title = GetInDesignTitle(htmlDoc);

            string pageId = note.CreatePage(title, sectionId);
            note.AddPageContentAsHtmlBlock(pageId, htmlDoc.DocumentNode.OuterHtml);

            return(true);
#else
            throw new NotImplementedException();
#endif
        }
		/// <summary>
		/// Sets the export options of the indesign document to HTML
		/// </summary>
		/// <param name="doc"></param>
		protected void SetInDesignHtmlExportOptions(InDesignDocument doc)
		{
			// General export options
			doc.HTMLExportPreferences.ExportSelection = false;
			doc.HTMLExportPreferences.ExportOrder = idExportOrder.idLayoutOrder;
			doc.HTMLExportPreferences.BulletExportOption = idBulletListExportOption.idUnorderedList;
			doc.HTMLExportPreferences.NumberedListExportOption = idNumberedListExportOption.idOrderedList;
			doc.HTMLExportPreferences.ViewDocumentAfterExport = true;

			// Image export options
			doc.HTMLExportPreferences.ImageExportOption = idImageExportOption.idOptimizedImage;
			doc.HTMLExportPreferences.PreserveLayoutAppearence = true;
			doc.HTMLExportPreferences.ImageExportResolution = idImageResolution.idPpi150;
			doc.HTMLExportPreferences.CustomImageSizeOption = idImageSizeOption.idSizeFixed;
			doc.HTMLExportPreferences.ImageAlignment = idImageAlignmentType.idAlignCenter;
			doc.HTMLExportPreferences.ImageSpaceBefore = 0;
			doc.HTMLExportPreferences.ImageSpaceAfter = 0;
			//doc.HTMLExportPreferences.ApplyImageAlignmentToAnchoredObjectSettings = true;
			doc.HTMLExportPreferences.ImageConversion = idImageConversion.idJPEG;
			doc.HTMLExportPreferences.JPEGOptionsQuality = idJPEGOptionsQuality.idMedium;
			doc.HTMLExportPreferences.JPEGOptionsFormat = idJPEGOptionsFormat.idProgressiveEncoding;
			doc.HTMLExportPreferences.IgnoreObjectConversionSettings = false;

			// Advanced export options
			//doc.HTMLExportPreferences.CSSExportOption = idStyleSheetExportOption.idEmbeddedCSS;
			//doc.HTMLExportPreferences.IncludeCSSDefinition = true;
			doc.HTMLExportPreferences.PreserveLocalOverride = false;
		}