@@ -32,44 +32,8 @@ To convert a colored PDF file to black and white using Telerik Document Processi
3232Here is a complete code snippet that demonstrates how to achieve this conversion:
3333
3434``` csharp
35- using System ;
36- using System .Diagnostics ;
37- using System .Windows .Media ;
38- using System .Windows .Media .Imaging ;
39- using Telerik .Windows .Documents .Fixed .FormatProviders .Pdf ;
40- using Telerik .Windows .Documents .Fixed .Model ;
41- using Telerik .Windows .Documents .Fixed .Model .ColorSpaces ;
42- using Telerik .Windows .Documents .Fixed .Model .Common ;
43- using Telerik .Windows .Documents .Fixed .Model .Graphics ;
44- using Telerik .Windows .Documents .Fixed .Model .Objects ;
45- using Telerik .Windows .Documents .Fixed .Model .Text ;
46-
47- namespace _1675661GrayScalePDF
48- {
49- internal class Program
50- {
5135 static void Main (string [] args )
52- {
53- var reportProcessor = new Telerik .Reporting .Processing .ReportProcessor ();
54- var deviceInfo = new System .Collections .Hashtable ();
55- var reportSource = new Telerik .Reporting .UriReportSource ();
56- reportSource .Uri = " ConditionalReport.trdp" ;
57-
58- Telerik .Reporting .Processing .RenderingResult result = reportProcessor .RenderReport (" PDF" , reportSource , deviceInfo );
59-
60- if (! result .HasErrors )
61- {
62- string fileName = result .DocumentName + " ." + result .Extension ;
63- string path = System .IO .Path .GetTempPath ();
64- string filePath = System .IO .Path .Combine (path , fileName );
65-
66- using (System .IO .FileStream fs = new System .IO .FileStream (filePath , System .IO .FileMode .Create ))
67- {
68- fs .Write (result .DocumentBytes , 0 , result .DocumentBytes .Length );
69- }
70-
71- Process .Start (new ProcessStartInfo () { FileName = filePath , UseShellExecute = true });
72-
36+ {
7337 PdfFormatProvider provider = new PdfFormatProvider ();
7438 RadFixedDocument document = provider .Import (System .IO .File .ReadAllBytes (filePath ));
7539
@@ -89,9 +53,7 @@ namespace _1675661GrayScalePDF
8953 }
9054
9155 System .IO .File .WriteAllBytes (resultFile , provider .Export (document , TimeSpan .FromSeconds (10 )));
92- Process .Start (resultFile );
93-
94- }
56+ Process .Start (resultFile );
9557 }
9658 private static void MakeGrayscale (ContentElementBase element )
9759 {
@@ -231,8 +193,6 @@ namespace _1675661GrayScalePDF
231193 {
232194 return (byte )(0 . 2126 * r + 0 . 7152 * g + 0 . 0722 * b );
233195 }
234- }
235- }
236196```
237197
238198Ensure to adjust the ` MakeGrayscale ` methods for ` ColorBase ` , ` Path ` , and ` Image ` according to your specific needs. This sample demonstrates the basic approach to converting document elements to grayscale but might require adjustments for complex scenarios or specific color processing requirements.
0 commit comments