public void ProcessFileMargins(BindingAssembly.Settings settings, BindingAssembly.File file, Document wordDoc) { if (!settings.Margins.Perform) { return; } if (file != null) { file.SetStatus("Adjusting margins..."); } try { wordDoc.PageSetup.TopMargin = (float)InchesToPoints(settings.Margins.Top); wordDoc.PageSetup.BottomMargin = (float)InchesToPoints(settings.Margins.Bottom); wordDoc.PageSetup.LeftMargin = (float)InchesToPoints(settings.Margins.Left); wordDoc.PageSetup.RightMargin = (float)InchesToPoints(settings.Margins.Right); wordDoc.PageSetup.Gutter = (float)InchesToPoints(settings.Margins.Gutter); wordDoc.PageSetup.GutterPos = WdGutterStyle.wdGutterPosLeft; // TODO make configurable if (file != null) { file.SetStatus("Finished adjusting margins..."); } } catch (Exception ex) { if (file != null) { file.SetStatus($"Unable to adjust margins. Exception {ex.ToString()}"); } } }
public void ScreenToSettings(BindingAssembly.Settings settings) { ScreenToPage(settings.Page); ScreenToMargins(settings.Margins); ScreenToImages(settings.Images); ScreenToText(settings.Text); ScreenToAssembly(settings.Assembly); }
public void SettingsToScreen(BindingAssembly.Settings settings) { PageToScreen(settings.Page); MarginsToScreen(settings.Margins); ImagesToScreen(settings.Images); TextToScreen(settings.Text); AssemblyToScreen(settings.Assembly); }
public void ProcessFilePage(BindingAssembly.Settings settings, BindingAssembly.File file, Document wordDoc) { if (!settings.Page.Perform) { return; } if (file != null) { file.SetStatus("Adjusting page size..."); } try { wordDoc.PageSetup.PageHeight = (float)InchesToPoints(settings.Page.Height); wordDoc.PageSetup.PageWidth = (float)InchesToPoints(settings.Page.Width); switch (settings.Page.Orientation) { case BindingAssembly.PageOrientation.Landscape: wordDoc.PageSetup.Orientation = WdOrientation.wdOrientLandscape; break; case BindingAssembly.PageOrientation.Portrait: wordDoc.PageSetup.Orientation = WdOrientation.wdOrientPortrait; break; } if (file != null) { file.SetStatus("Finshed adjusting page size..."); } } catch (Exception ex) { if (file != null) { file.SetStatus($"Unable to set page size. Exception {ex.ToString()}"); } } }
public SettingsForm(BindingAssembly.Settings settings) { InitializeComponent(); Settings = settings; ctlSettings.SettingsToScreen(settings); }
public static BindingAssembly GetAssembly(string fileName, BindingAssembly.Settings defaultSettings) { BindingAssembly assembly = new BindingAssembly(defaultSettings); return(GetAssembly(fileName, assembly)); }
public void ProcessFileImages(BindingAssembly.Settings settings, BindingAssembly.File file, Document wordDoc) { if (!settings.Images.Perform) { return; } if (file != null) { file.SetStatus("Adjusting Images..."); } // Get Maximum Height / Width double maxHeight = 0.0, maxWidth = 0.0; if (settings.Images.MaximumHeight != 0.0) { maxHeight = InchesToPoints(settings.Images.MaximumHeight); } else // No taller than page { maxHeight = wordDoc.PageSetup.PageHeight - wordDoc.PageSetup.TopMargin - wordDoc.PageSetup.BottomMargin; if (wordDoc.PageSetup.GutterPos == WdGutterStyle.wdGutterPosTop) { maxHeight -= wordDoc.PageSetup.Gutter; } } if (settings.Images.MaximumWidth != 0.0) { maxWidth = InchesToPoints(settings.Images.MaximumWidth); } else // No wider than page { maxWidth = wordDoc.PageSetup.PageWidth - wordDoc.PageSetup.LeftMargin - wordDoc.PageSetup.RightMargin; if (wordDoc.PageSetup.GutterPos != WdGutterStyle.wdGutterPosTop) { maxWidth -= wordDoc.PageSetup.Gutter; } } int currentImage = 0; while (currentImage < file.Images) { ++currentImage; if (file != null) { file.SetStatus($"Processing image {currentImage}..."); } InlineShape curShape = wordDoc.InlineShapes[currentImage]; if (curShape.Type == WdInlineShapeType.wdInlineShapePicture) { // If it's a picture we can do fixup with it if (curShape.Width > maxWidth) // Too Big, must horizontally { float scaling = (float)maxWidth / curShape.Width; curShape.Width = (float)maxWidth; curShape.Height = curShape.Height * scaling; } if (curShape.Height > maxHeight) { float scaling = (float)maxHeight / curShape.Height; curShape.Height = (float)maxHeight; curShape.Width = curShape.Width * scaling; } if (curShape.Height > settings.Images.MinimumAdjustmentHeight) { // Adjust/Set Brightness/Contrast curShape.PictureFormat.Brightness = .5F + ((float)settings.Images.Brightness / 200F); curShape.PictureFormat.Contrast = .5F + ((float)settings.Images.Contrast / 200F); // Clear Indent/Set Centered // TODO: Evaluate for later //curShape.Range.ParagraphFormat.LeftIndent = 0; //curShape.Range.ParagraphFormat.RightIndent = 0; //curShape.Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter; } } } if (file != null) { file.SetStatus("Finished adjusting images..."); } }
public void ProcessFileText(BindingAssembly.Settings settings, BindingAssembly.File file, Document wordDoc) { if (file != null) { file.SetStatus("Adjusting text..."); } // -- Fields to Text if (settings.Text.FieldsToText) { if (file != null) { file.SetStatus("Converting fields to text"); } try { int fieldIndex = wordDoc.Fields.Count; while (fieldIndex > 0) { Field thisField = wordDoc.Fields[fieldIndex]; if (thisField.Kind != WdFieldKind.wdFieldKindCold) { try { thisField.Update(); thisField.Unlink(); } catch (COMException cEx) { if (string.Compare(cEx.Message, "Object has been deleted.") != 0) { throw cEx; } } fieldIndex--; } else { fieldIndex--; } } } catch (Exception ex) { if (file != null) { file.SetStatus($"Failed to convert fields to text. Exception {ex.ToString()}"); } } } // -- Numbers to Text if (settings.Text.NumbersToText) { if (file != null) { file.SetStatus("Converting numbers to text..."); } try { wordDoc.ConvertNumbersToText(Missing.Value); } catch (Exception ex) { file.SetStatus($"Filed to convert numbers to text. Exception {ex.ToString()}"); } } // -- Clear Comments if (settings.Text.ClearComments) { if (file != null) { file.SetStatus($"Clearing comments..."); } try { while (wordDoc.Comments.Count > 0) { wordDoc.Comments[1].DeleteRecursively(); } } catch (Exception ex) { if (file != null) { file.SetStatus($"Failed to clear comments. Exception {ex.ToString()}"); } } } // -- Accept Revisions if (settings.Text.AcceptRevisions) { if (file != null) { file.SetStatus("Accepting revisions..."); } try { wordDoc.Revisions.AcceptAll(); wordDoc.TrackRevisions = false; } catch (Exception ex) { if (file != null) { file.SetStatus($"Failed to accept revisions. Exception {ex.ToString()}"); } } } if (file != null) { file.SetStatus("Finished adjusting text..."); } }