Trabajar con encabezado y pie de página

Lectura de la información de encabezado y pie de página de un archivo MPP

Aspose.Tasks for .NET API ofrece la capacidad de leer la información de encabezado y pie de página de un archivo MPP. La API incluye clases dedicadas que corresponden a cada pestaña de Microsoft Project Page Setup cuadro de diálogo:

El siguiente ejemplo demuestra cómo leer la información de encabezado y pie de página de un archivo MPP:

 1static void Run()
 2{
 3    // Create project and project info instances
 4    Project project = new Project("New Project.mpp");
 5    PageInfo info = project.DefaultView.PageInfo;
 6
 7    Console.WriteLine("Page data cannot be null : {0} ", !info.Equals(null));
 8
 9    if (info != null)
10    {
11        AssertHeaderFooterCorrect(info);
12        AssertPageSettingsCorrect(info);
13        AssertPageViewSettingsCorrect(info);
14        AssertMarginsCorrect(info);
15        AssertLegendCorrect(info);
16    }
17 
18}
19
20static void AssertHeaderFooterCorrect(PageInfo info)
21{
22    Console.WriteLine("Header left text Equals LEFT HEADER : {0} ", info.Header.LeftText.Equals("LEFT HEADER"));
23    Console.WriteLine("Header center text Equals CENTER HEADER : {0} ", info.Header.CenteredText.Equals("CENTER HEADER"));
24    Console.WriteLine("Header right text Equals RIGHT HEADER : {0} ", info.Header.RightText.Equals("RIGHT HEADER"));
25
26    Console.WriteLine("Footer left text Equals LEFT FOOTER : {0} ", info.Footer.LeftText.Equals("LEFT FOOTER"));
27    Console.WriteLine("Footer center text Equals CENTER FOOTER : {0} ", info.Footer.CenteredText.Equals("CENTER FOOTER"));
28    Console.WriteLine("Footer right text Equals RIGHT FOOTER : {0} ", info.Footer.RightText.Equals("RIGHT FOOTER"));
29}
30
31static void AssertPageSettingsCorrect(PageInfo info)
32{
33    Console.WriteLine("Portrait Orientation is Portrait : {0} ", info.PageSettings.IsPortrait.Equals(true));
34    Console.WriteLine("AdjustToPercentOfNormalSize is enabled : {0} ", info.PageSettings.AdjustToPercentOfNormalSize.Equals(true));
35 
36    Console.WriteLine("PercentOfNormalSize Equals 150 : {0} ", info.PageSettings.PercentOfNormalSize.Equals(150));
37    Console.WriteLine("PagesInWidth Equals 3 : {0} ", info.PageSettings.PagesInWidth.Equals(3));
38    Console.WriteLine("PagesInHeight Equals 7 : {0} ", info.PageSettings.PagesInHeight.Equals(7));
39    Console.WriteLine("PaperSize Equals PaperA4 : {0} ", info.PageSettings.PaperSize.Equals(PrinterPaperSize.PaperA4));
40    Console.WriteLine("FirstPageNumber : {0} ", info.PageSettings.FirstPageNumber);
41}
42
43static void AssertPageViewSettingsCorrect(PageInfo info)
44{
45    Console.WriteLine("PrintAllSheetColumns is set to false : {0} ", info.PageViewSettings.PrintAllSheetColumns.Equals(false));
46    Console.WriteLine("PrintFirstColumnsCountOnAllPages is set to true : {0} ", info.PageViewSettings.PrintFirstColumnsCountOnAllPages.Equals(true));
47
48    Console.WriteLine("FirstColumnsCount Equals 3 : {0} ",  info.PageViewSettings.FirstColumnsCount.Equals(3));
49    Console.WriteLine("PrintNotes is set to true : {0} ", info.PageViewSettings.PrintNotes.Equals(true));
50    Console.WriteLine("PrintBlankPages is set to false : {0} ", info.PageViewSettings.PrintBlankPages.Equals(false));
51    Console.WriteLine("FitTimescaleToEndOfPage is set to true : {0} ", info.PageViewSettings.FitTimescaleToEndOfPage.Equals(true));
52}
53
54static void AssertMarginsCorrect(PageInfo info)
55{
56    Console.WriteLine("Margins.Left Equals 1 : {0} ", (info.Margins.Left - 1 <= 1e-5) ? true : false);
57    Console.WriteLine("Margins.Top Equals 1.1 : {0} ", (info.Margins.Top - 1.1 <= 1e-5) ? true : false);
58    Console.WriteLine("Margins.Right Equals 1.2 : {0} ", (info.Margins.Right - 1.2 <= 1e-5) ? true : false);
59    Console.WriteLine("Margins.Bottom Equals 1.2 : {0} ", (info.Margins.Bottom - 1.3 <= 1e-5) ? true : false);
60
61    Console.WriteLine("Margin.Borders Equals Border.AroundEveryPage : {0} ",info.Margins.Borders.Equals(Border.AroundEveryPage));
62}
63
64static void AssertLegendCorrect(PageInfo info)
65{
66    Console.WriteLine("Legend left text Equals LEFT LEGEND : {0} ", info.Legend.LeftText.Equals("LEFT LEGEND"));
67    Console.WriteLine("Legend center text Equals CENTER LEGEND : {0} ", info.Legend.CenteredText.Equals("CENTER LEGEND"));
68    Console.WriteLine("Legend right text Equals RIGHT LEGEND : {0} ", info.Legend.RightText.Equals("RIGHT LEGEND"));
69
70    Console.WriteLine("LegendOn Equals Legend.OnEveryPage : {0} ", info.Legend.LegendOn.Equals(Legend.OnEveryPage));
71    Console.WriteLine("Legend Width Equals 5 : {0} ", (info.Legend.Width - 5 <= 1e-5) ? true : false);
72}

Agregar imagen al encabezado/pie de página

Aspose.Tasks for .NET también ofrece la capacidad de manipular encabezados y pies de página, incluyendo la inserción de imágenes. El ejemplo a continuación muestra cómo agregar una imagen a un encabezado de página:

 1Project project = new Project("New Project.mpp");
 2
 3project.RootTask.Children.Add("Task1");
 4PageInfo pageInfo = project.DefaultView.PageInfo;
 5
 6using (Image image = Image.FromFile("Image1.png"))
 7{
 8    pageInfo.Header.CenteredImage = image;
 9    pageInfo.Legend.LeftImage = image;
10    pageInfo.Legend.LeftText = string.Empty;
11    MPPSaveOptions options = new MPPSaveOptions();
12    options.WriteViewData = true;
13    project.Save("AddImageToPageHeaderFooter_out.mpp", options);
14}

Al usar Aspose.Tasks for .NET, los desarrolladores obtienen control total sobre el configuración de página, incluyendo encabezados, pies de página, márgenes, leyendas y ajustes de vista.
Esta flexibilidad permite la creación de informes profesionales y diseños de impresión de forma programática, garantizando que la documentación del proyecto cumpla con los estándares organizacionales sin requerir ajustes manuales en Microsoft Project.

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.