Bonjour,

Je dois convertir un ensemble de documents Word en Pdf pour cela j'utilise le code ci-dessous qui fonctionne correctement.
Ces documents sont générés par un logiciel tiers et je n'ai donc pas le contrôle sur le document source.
Le problème c'est que certains champs de fusion s'affichent avec une police rouge,je cherche donc à les afficher
avec une police noire
plus classique.

Soit en sauvegardant mon document en noir et blanc ou niveau de gris
(ce qui serait dommage, parce que j'aimerai conserver les logos en couleur et j'ai peur que le rouge devienne un noir moins soutenu que le reste du texte)

Soit, et ce serait mieux, en modifiant la police des champs de fusion.

Je ne suis pas un spécialiste des fusions Word (et je ne souhaite pas le devenir ) mais je peux quand même préciser que les champs incriminés semblent être de type docvariable dès fois que ça soit utile à certains d'entre vous.

J'ai testé

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
                foreach (Field field in wordDocument.Fields)
                {
                    if (field.Type == WdFieldType.wdFieldDocVariable)
                    {
                        field.Code.Font.Color = WdColor.wdColorBlack;
                    }
                } 
 
 
                Range rng = wordDocument.Content;
                rng.Font.Color = WdColor.wdColorBlack;

mais cela reste sans effet.

Quelqu'un aurait une idée ?
Merci,

Vincent.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
      protected static void CONVERSION_AVEC_OFFICE(string VVST_FPATH)
        {
            Exception VLOB_EXCEP = null;
 
            ApplicationClass wordApplication = new ApplicationClass();
            Document wordDocument = null;
 
            object paramSourceDocPath = VVST_FPATH;
            object paramMissing = Type.Missing;
 
            string paramExportFilePath = VVST_FPATH.ToLower().Replace(".doc","-office.pdf");// 
            WdExportFormat paramExportFormat = WdExportFormat.wdExportFormatPDF;
            bool paramOpenAfterExport = false;
            WdExportOptimizeFor paramExportOptimizeFor = WdExportOptimizeFor.wdExportOptimizeForPrint;
            WdExportRange paramExportRange = WdExportRange.wdExportAllDocument;
            int paramStartPage = 0;
            int paramEndPage = 0;
            WdExportItem paramExportItem = WdExportItem.wdExportDocumentContent;
            bool paramIncludeDocProps = true;
            bool paramKeepIRM = true;
            WdExportCreateBookmarks paramCreateBookmarks = WdExportCreateBookmarks.wdExportCreateWordBookmarks;
            bool paramDocStructureTags = true;
            bool paramBitmapMissingFonts = true;
            bool paramUseISO19005_1 = false;
 
            try
            {
                // Open the source document.
                wordDocument = wordApplication.Documents.Open(
                    ref paramSourceDocPath, ref paramMissing, ref paramMissing,
                    ref paramMissing, ref paramMissing, ref paramMissing,
                    ref paramMissing, ref paramMissing, ref paramMissing,
                    ref paramMissing, ref paramMissing, ref paramMissing,
                    ref paramMissing, ref paramMissing, ref paramMissing,
                    ref paramMissing);
 
                Range rng = wordDocument.Content;
                rng.Font.Color = WdColor.wdColorBlack;
 
 
 
                foreach (Field field in wordDocument.Fields)
                {
                    if (field.Type == WdFieldType.wdFieldDocVariable)
                    {
                        field.Code.Font.Color = WdColor.wdColorBlueGray;
                    }
                }
 
 
	// à activer pour que les modifs du document soit sauvegardées ?
                wordDocument.Save();
 
 
                // Export it in the specified format.
                if (wordDocument != null)
                    wordDocument.ExportAsFixedFormat(paramExportFilePath,
                        paramExportFormat, paramOpenAfterExport,
                        paramExportOptimizeFor, paramExportRange, paramStartPage,
                        paramEndPage, paramExportItem, paramIncludeDocProps,
                        paramKeepIRM, paramCreateBookmarks, paramDocStructureTags,
                        paramBitmapMissingFonts, paramUseISO19005_1,
                        ref paramMissing);
            }
            catch (Exception ex)
            {
                VLOB_EXCEP = ex;
                //throw ex;
                // Respond to the error
            }
            finally
            {
                // Close and release the Document object.
                if (wordDocument != null)
                {
                    wordDocument.Close(ref paramMissing, ref paramMissing,
                        ref paramMissing);
                    wordDocument = null;
                }
 
                // Quit Word and release the ApplicationClass object.
                if (wordApplication != null)
                {
                    wordApplication.Quit(ref paramMissing, ref paramMissing,
                        ref paramMissing);
                    wordApplication = null;
                }
 
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
            if (VLOB_EXCEP != null)
                throw VLOB_EXCEP;
        }