Ejemplo n.º 1
0
        private void GenXslForPdh(string key)
        {
            ServicesProfile srvPro = Wkl.MainCtrl.ServiceCtrl.GetProfile(key);

            // create new docx file path
            string folderPath  = Path.GetDirectoryName(srvPro.FullDocName);
            string fileName    = System.Guid.NewGuid().ToString();
            string newDocxPath = string.Format(PathFormat, folderPath, fileName, FileExtension.Docx);

            // copy docx file
            File.Copy(srvPro.FullDocName, newDocxPath, true);

            // save as word xml document (xml 2007)
            string firstDomainName = Wkl.MainCtrl.CommonCtrl.CommonProfile.CurrentTemplateInfo.FirstDomain;

            Core.InternalBookmarkDomain firstDomain = srvPro.Ibm.GetInternalBookmarkDomain(firstDomainName);
            string xmlFilePath = SaveAsMhtForPdh(newDocxPath, firstDomain);

            try
            {
                srvPro.IsXsl2007Format = true;
                Mht.XslGenerator xslGenerator = new Mht.XslGenerator(xmlFilePath);
                srvPro.XsltString = xslGenerator.GenXsl(key);
            }
            catch (System.Exception ex) { Core.LogUtils.Log("GenXsl", ex); }
            finally
            {
                // remove temp file
                System.IO.File.Delete(xmlFilePath);
                System.IO.File.Delete(newDocxPath);
            }
        }
Ejemplo n.º 2
0
        private string SaveAsHtmlForPdm(string filePath, Core.InternalBookmarkDomain firstDomain)
        {
            string tempCopyFileName = Path.ChangeExtension(Path.GetTempFileName(), FileExtension.Docx);
            string tempHtmlName     = Path.ChangeExtension(Path.GetTempFileName(), FileExtension.Html);

            Word.Application word   = null;
            Word.Document    newDoc = null;

            File.Copy(filePath, tempCopyFileName, true);

            try
            {
                word = new Microsoft.Office.Interop.Word.Application();

                word.DefaultWebOptions().Encoding = MsoEncoding.msoEncodingUTF8;

                newDoc = word.Documents.Open(tempCopyFileName, Visible: false, AddToRecentFiles: false, Encoding: MsoEncoding.msoEncodingUTF8);

                RemoveCustomXmlParts(newDoc);
                MakePdwWatermark(word, TemplateType.Pdm, firstDomain);

                newDoc.SaveAs(tempHtmlName, Word.WdSaveFormat.wdFormatFilteredHTML, AddToRecentFiles: false, Encoding: MsoEncoding.msoEncodingUTF8);
                ((Word._Document)newDoc).Close();
            }
            finally
            {
                ((Word._Application)word).Quit(Type.Missing, Type.Missing, Type.Missing);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(word);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(newDoc);

                File.Delete(tempCopyFileName);
            }

            return(tempHtmlName);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// HACK:FORM CONTROLS - GenXslForPdm
        /// </summary>
        /// <param name="key"></param>
        private void GenXslForPdm(string key)
        {
            ServicesProfile srvPro = Wkl.MainCtrl.ServiceCtrl.GetProfile(key);

            string firstDomainName = Wkl.MainCtrl.CommonCtrl.CommonProfile.CurrentTemplateInfo.FirstDomain;

            Core.InternalBookmarkDomain firstDomain = srvPro.Ibm.GetInternalBookmarkDomain(firstDomainName);
            string htmlFileName = SaveAsHtmlForPdm(srvPro.FullDocName, firstDomain);

            try
            {
                srvPro.IsXsl2007Format = true;

                Pdm.XslGenerator generator = new Pdm.XslGenerator(srvPro.Ibm, htmlFileName);

                srvPro.XsltString = generator.GenXsl();
            }
            catch (System.Exception ex)
            {
                //TODO:FORM CONTROLS - EXCEPTION
                Core.LogUtils.Log("GenXsl", ex);
                throw ex;
            }
            finally
            {
                File.Delete(htmlFileName);
            }
        }
Ejemplo n.º 4
0
        private void MakePdwWatermark(Microsoft.Office.Interop.Word.Application wApp, TemplateType templateType,
                                      Core.InternalBookmarkDomain firstDomain)
        {
            try
            {
                Microsoft.Office.Interop.Word.Selection Selection = wApp.Selection;
                Microsoft.Office.Interop.Word.Shape     wmShape;
                Selection.Select();

                // set focus on header to put watermark
                wApp.ActiveWindow.ActivePane.View.SeekView = Microsoft.Office.Interop.Word.WdSeekView.wdSeekCurrentPageHeader;

                //Create the watermar shape
                wmShape = Selection.HeaderFooter.Shapes.AddTextEffect(
                    Microsoft.Office.Core.MsoPresetTextEffect.msoTextEffect1,
                    GenPdwWatermarkValue(templateType, firstDomain),
                    "Times New Roman", 1,
                    Microsoft.Office.Core.MsoTriState.msoFalse,
                    Microsoft.Office.Core.MsoTriState.msoFalse,
                    0, 0);

                //Set all of the attributes of the watermark
                wmShape.Select();
                wmShape.Name = PdwWaterMarkName;
                wmShape.TextEffect.NormalizedHeight = Microsoft.Office.Core.MsoTriState.msoFalse;
                wmShape.Line.Visible = Microsoft.Office.Core.MsoTriState.msoFalse;
                wmShape.Fill.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;
                wmShape.Fill.Solid();
                wmShape.Fill.ForeColor.RGB = (int)Microsoft.Office.Interop.Word.WdColor.wdColorGray25;
                wmShape.Fill.Transparency  = 0.5f;
                wmShape.Rotation           = GenPdwWatermarkRotation(templateType);
                wmShape.LockAspectRatio    = Microsoft.Office.Core.MsoTriState.msoTrue;
                wmShape.Height             = GenPdwWatermarkHeight(wApp, templateType);
                wmShape.Width = wApp.InchesToPoints(7.64f);
                wmShape.WrapFormat.AllowOverlap    = -1;                                                  //true
                wmShape.WrapFormat.Side            = Microsoft.Office.Interop.Word.WdWrapSideType.wdWrapBoth;
                wmShape.WrapFormat.Type            = Microsoft.Office.Interop.Word.WdWrapType.wdWrapNone; //3
                wmShape.RelativeHorizontalPosition =
                    Microsoft.Office.Interop.Word.WdRelativeHorizontalPosition.wdRelativeHorizontalPositionMargin;
                wmShape.RelativeVerticalPosition =
                    Microsoft.Office.Interop.Word.WdRelativeVerticalPosition.wdRelativeVerticalPositionMargin;
                wmShape.Left = (float)Microsoft.Office.Interop.Word.WdShapePosition.wdShapeCenter;
                wmShape.Top  = (float)Microsoft.Office.Interop.Word.WdShapePosition.wdShapeCenter;

                //set focus back to document
                wApp.ActiveWindow.ActivePane.View.SeekView = Microsoft.Office.Interop.Word.WdSeekView.wdSeekMainDocument;
            }
            catch { }
        }
Ejemplo n.º 5
0
        private string SaveAsMhtForPdh(string docxFilePath, Core.InternalBookmarkDomain firstDomain)
        {
            object missing = System.Type.Missing;

            Microsoft.Office.Interop.Word.Application wApp = new Microsoft.Office.Interop.Word.Application();
            Microsoft.Office.Interop.Word.Document    wDoc = null;

            string xmlFilePath = Path.ChangeExtension(docxFilePath, FileExtension.Xml);

            try
            {
                // open word document
                wApp.Visible = false;
                wDoc         = wApp.Documents.Open(docxFilePath, AddToRecentFiles: false);

                // remove custom xml part
                RemoveCustomXmlParts(wDoc);

                // put watermark tag
                MakePdwWatermark(wApp, TemplateType.Pdh, firstDomain);

                // pre-process
                ProcessHeaderFooter(wApp, wDoc);
                ProcessWaterMark(wDoc);
                ProcessBookmarkForMhtFile(wDoc);

                // save as word xml document
                Microsoft.Office.Interop.Word.WdSaveFormat fileFormat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatFlatXML;
                xmlFilePath = Path.ChangeExtension(xmlFilePath, FileExtension.Mht);
                fileFormat  = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatWebArchive;

                wDoc.WebOptions.Encoding = Microsoft.Office.Core.MsoEncoding.msoEncodingUTF8;
                wDoc.SaveAs(FileName: xmlFilePath, FileFormat: fileFormat,
                            Encoding: Microsoft.Office.Core.MsoEncoding.msoEncodingUTF8, AddToRecentFiles: false);

                // close document
                ((Microsoft.Office.Interop.Word._Document)wDoc).Close();
            }
            catch { }
            finally
            {
                ((Microsoft.Office.Interop.Word._Application)wApp).Quit(missing, missing, missing);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(wDoc);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(wApp);
            }

            return(xmlFilePath);
        }
Ejemplo n.º 6
0
        private string GenPdwWatermarkValue(TemplateType templateType, Core.InternalBookmarkDomain firstDomain)
        {
            switch (templateType)
            {
            case TemplateType.Pdw:
                return("{" + firstDomain.RootTablePath + "/@" + ProntoDoc.Framework.CoreObject.FrameworkConstants.PdwWatermark + "}");

            case TemplateType.Pdh:     // update XslGenerator
                string bmName = System.DateTime.Now.ToString(Pdw.Core.ProntoMarkup.BookmarkKeyFormat);
                bmName = Core.MarkupUtilities.GenKeyForXslTag(bmName, Core.XsltType.Select, true);
                string bmValue = ProntoDoc.Framework.CoreObject.FrameworkConstants.PdwWatermark;
                firstDomain.InternalBookmarkItems.Add(new Core.InternalBookmarkItem(bmName, bmValue, bmValue, string.Empty));
                return(GenBookmarkText(bmName, bmValue));

            default:
                return("");
            }
        }
Ejemplo n.º 7
0
        private void GenXslForPdw(string key)
        {
            ServicesProfile srvPro = Wkl.MainCtrl.ServiceCtrl.GetProfile(key);

            // create new docx file path
            string folderPath  = Path.GetDirectoryName(srvPro.FullDocName);
            string fileName    = System.Guid.NewGuid().ToString();
            string newDocxPath = string.Format(PathFormat, folderPath, fileName, FileExtension.Docx);

            // copy docx file
            File.Copy(srvPro.FullDocName, newDocxPath, true);

            // save as word xml document (xml 2007)
            string firstDomainName = Wkl.MainCtrl.CommonCtrl.CommonProfile.CurrentTemplateInfo.FirstDomain;

            Core.InternalBookmarkDomain firstDomain = srvPro.Ibm.GetInternalBookmarkDomain(firstDomainName);
            string xmlFilePath = SaveAsWordXmlForPdw(newDocxPath, firstDomain);

            try
            {
                // get word xml document (xml 2007)
                string xmlContent = GetWordXmlDocument(xmlFilePath);

                // get xslt
                Wkl.MainCtrl.CommonCtrl.CommonProfile.CurrentTemplateInfo.XmlContent = xmlContent;
                srvPro.IsXsl2007Format = true;

                MainManager mainManager = new MainManager();
                mainManager.RegisterEvents();
                mainManager.MainService.TemplateService.GetXslContent(key);

                // correct xsl content
                srvPro.XsltString = CorrectXslContent(srvPro.XsltString);
            }
            catch (System.Exception ex) { Core.LogUtils.Log("GenXsl", ex); }
            finally
            {
                // remove temp file
                System.IO.File.Delete(xmlFilePath);
                System.IO.File.Delete(newDocxPath);
            }
        }
Ejemplo n.º 8
0
        private string SaveAsWordXmlForPdw(string docxFilePath, Core.InternalBookmarkDomain firstDomain)
        {
            object missing = System.Type.Missing;

            Microsoft.Office.Interop.Word.Application wApp = new Microsoft.Office.Interop.Word.Application();
            Microsoft.Office.Interop.Word.Document    wDoc = null;

            string xmlFilePath = Path.ChangeExtension(docxFilePath, FileExtension.Xml);

            try
            {
                // open word document
                wApp.Visible = false;
                wDoc         = wApp.Documents.Open(docxFilePath, AddToRecentFiles: false);

                // remove custom xml part
                RemoveCustomXmlParts(wDoc);

                // save as word xml document
                Microsoft.Office.Interop.Word.WdSaveFormat fileFormat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatFlatXML;
                MakePdwWatermark(wApp, TemplateType.Pdw, firstDomain);
                wDoc.SaveAs(FileName: xmlFilePath, FileFormat: fileFormat, AddToRecentFiles: false);

                // close document
                ((Microsoft.Office.Interop.Word._Document)wDoc).Close();
            }
            catch { }
            finally
            {
                ((Microsoft.Office.Interop.Word._Application)wApp).Quit(missing, missing, missing);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(wDoc);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(wApp);
            }

            return(xmlFilePath);
        }