Example #1
0
		bool HookDocumentClose(Pub.Document doc)
		{
			if (doc != null)
			{
				Pub.DocumentEvents_Event docEvents = (Pub.DocumentEvents_Event)doc;
				docEvents.BeforeClose += new Microsoft.Office.Interop.Publisher.DocumentEvents_BeforeCloseEventHandler(docEvents_BeforeClose);
				return true;
			}
			return false;
		}
		public PubDocument(Pub.Document doc, ProcessingType eType)
			: base(doc, eType)
		{
		}
		public PubRangeDocument(Pub.Document doc, OfficeTextDocument.ProcessingType eType)
			: base(doc, eType)
		{
		}
		protected bool ProcessStory(OfficeDocumentProcessor aWordProcessor, Pub.Story aStory)
		{
			PubStory aPubStory = new PubStory(aStory);
			foreach (PubRange aParagraphRange in aPubStory.Paragraphs)
			{
				// if we're picking up where we left off and we're not there yet...
				int nCharIndex = 0;
				if (aWordProcessor.AreLeftOvers)
				{
					if (aWordProcessor.LeftOvers.Start > aParagraphRange.End)
						continue;   // skip to the next paragraph

					nCharIndex = aWordProcessor.LeftOvers.StartIndex;
					aWordProcessor.LeftOvers = null; // turn off "left overs"
				}

				if (!ProcessRangeAsWords(aWordProcessor, aParagraphRange, nCharIndex))
					return false;
			}

			// see if the user would like us to adjust the size to make it fit.
			if (    !aWordProcessor.SuspendUI
				&&  (aStory.HasTextFrame == Office.MsoTriState.msoTrue)
				&&  (aStory.TextFrame.Overflowing == Office.MsoTriState.msoTrue))
			{
				if (MessageBox.Show("The story has overflowed the text frame. Would you like me to adjust the text size so it fits?", Connect.cstrCaption, MessageBoxButtons.YesNo) == DialogResult.Yes)
				{
					try
					{
						aStory.TextFrame.AutoFitText = Pub.PbTextAutoFitType.pbTextAutoFitShrinkOnOverflow;
					}
					catch (Exception ex)
					{
						// this error is occasionally thrown when we try to do the auto fit... if it happens, just ignore it.
						// (it's just to save the user from having to reformat)
						if (ex.Message != "Error HRESULT E_FAIL has been returned from a call to a COM component.")
							throw;
					}
				}
			}

			return true;
		}