Working with Page Header Footer
Contents
[
Hide
Show
]Reading Header and Footer Information from MPP file
Aspose.Tasks for C++ API provides the capability to read the Header and Footer information from MPP file. The API has classes mapped to each tab of Microsoft Project Page Setup dialog as detailed in the section below.
- Microsoft Project Page Setup dialog box has 6 tabs (see screenshot). These tabs are mapped to new classes:
- Page tab -> Aspose.Tasks.Visualization .PageSettings class
- Margins tab -> Aspose.Tasks.Visualization.PageMargins class
- Header, footer tabs -> Aspose.Tasks.Visualization.HeaderFooterInfo class
- Legend tab -> Aspose.Tasks.Visualization.PageLegend class
- View tab -> Aspose.Tasks.Visualization.PageViewSettings class
1void ReadHeaderFooterInfo::Run()
2{
3 // The path to the documents directory.
4 System::String dataDir = RunExamples::GetDataDir(System::Reflection::MethodBase::GetCurrentMethod(ASPOSE_CURRENT_FUNCTION)->get_DeclaringType().get_FullName());
5
6 // Create project and project info instances
7 System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"Blank2010.mpp");
8 System::SharedPtr<PageInfo> info = project->get_DefaultView()->get_PageInfo();
9
10 System::Console::WriteLine(u"Page data cannot be null : {0} ", System::ObjectExt::Box<bool>(!System::ObjectExt::Equals(info, nullptr)));
11
12 if (info != nullptr)
13 {
14 AssertHeaderFooterCorrect(info);
15 AssertPageSettingsCorrect(info);
16 AssertPageViewSettingsCorrect(info);
17 AssertMarginsCorrect(info);
18 AssertLegendCorrect(info);
19 }
20
21}
22
23void ReadHeaderFooterInfo::AssertHeaderFooterCorrect(System::SharedPtr<Aspose::Tasks::Visualization::PageInfo> info)
24{
25 System::Console::WriteLine(u"Header left text Equals LEFT HEADER : {0} ", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(info->get_Header()->get_LeftText(), u"LEFT HEADER")));
26 System::Console::WriteLine(u"Header center text Equals CENTER HEADER : {0} ", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(info->get_Header()->get_CenteredText(), u"CENTER HEADER")));
27 System::Console::WriteLine(u"Header right text Equals RIGHT HEADER : {0} ", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(info->get_Header()->get_RightText(), u"RIGHT HEADER")));
28
29 System::Console::WriteLine(u"Footer left text Equals LEFT FOOTER : {0} ", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(info->get_Footer()->get_LeftText(), u"LEFT FOOTER")));
30 System::Console::WriteLine(u"Footer center text Equals CENTER FOOTER : {0} ", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(info->get_Footer()->get_CenteredText(), u"CENTER FOOTER")));
31 System::Console::WriteLine(u"Footer right text Equals RIGHT FOOTER : {0} ", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(info->get_Footer()->get_RightText(), u"RIGHT FOOTER")));
32}
33
34void ReadHeaderFooterInfo::AssertPageSettingsCorrect(System::SharedPtr<Aspose::Tasks::Visualization::PageInfo> info)
35{
36 System::Console::WriteLine(u"Portrait Orientation is Portrait : {0} ", System::ObjectExt::Box<bool>(System::Equals(info->get_PageSettings()->get_IsPortrait(), true)));
37 System::Console::WriteLine(u"AdjustToPercentOfNormalSize is enabled : {0} ", System::ObjectExt::Box<bool>(System::Equals(info->get_PageSettings()->get_AdjustToPercentOfNormalSize(), true)));
38
39 System::Console::WriteLine(u"PercentOfNormalSize Equals 150 : {0} ", System::ObjectExt::Box<bool>(System::Equals(info->get_PageSettings()->get_PercentOfNormalSize(), 150)));
40 System::Console::WriteLine(u"PagesInWidth Equals 3 : {0} ", System::ObjectExt::Box<bool>(System::Equals(info->get_PageSettings()->get_PagesInWidth(), 3)));
41 System::Console::WriteLine(u"PagesInHeight Equals 7 : {0} ", System::ObjectExt::Box<bool>(System::Equals(info->get_PageSettings()->get_PagesInHeight(), 7)));
42 System::Console::WriteLine(u"PaperSize Equals PaperA4 : {0} ", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(info->get_PageSettings()->get_PaperSize(), Aspose::Tasks::Visualization::PrinterPaperSize::PaperA4)));
43 System::Console::WriteLine(u"FirstPageNumber : {0} ", System::ObjectExt::Box<int16_t>(info->get_PageSettings()->get_FirstPageNumber()));
44}
45
46void ReadHeaderFooterInfo::AssertPageViewSettingsCorrect(System::SharedPtr<Aspose::Tasks::Visualization::PageInfo> info)
47{
48 System::Console::WriteLine(u"PrintAllSheetColumns is set to false : {0} ", System::ObjectExt::Box<bool>(System::Equals(info->get_PageViewSettings()->get_PrintAllSheetColumns(), false)));
49 System::Console::WriteLine(u"PrintFirstColumnsCountOnAllPages is set to true : {0} ", System::ObjectExt::Box<bool>(System::Equals(info->get_PageViewSettings()->get_PrintFirstColumnsCountOnAllPages(), true)));
50
51 System::Console::WriteLine(u"FirstColumnsCount Equals 3 : {0} ", System::ObjectExt::Box<bool>(System::Equals(info->get_PageViewSettings()->get_FirstColumnsCount(), 3)));
52 System::Console::WriteLine(u"PrintNotes is set to true : {0} ", System::ObjectExt::Box<bool>(System::Equals(info->get_PageViewSettings()->get_PrintNotes(), true)));
53 System::Console::WriteLine(u"PrintBlankPages is set to false : {0} ", System::ObjectExt::Box<bool>(System::Equals(info->get_PageViewSettings()->get_PrintBlankPages(), false)));
54 System::Console::WriteLine(u"FitTimescaleToEndOfPage is set to true : {0} ", System::ObjectExt::Box<bool>(System::Equals(info->get_PageViewSettings()->get_FitTimescaleToEndOfPage(), true)));
55}
56
57void ReadHeaderFooterInfo::AssertMarginsCorrect(System::SharedPtr<Aspose::Tasks::Visualization::PageInfo> info)
58{
59 System::Console::WriteLine(u"Margins.Left Equals 1 : {0} ", System::ObjectExt::Box<bool>((info->get_Margins()->get_Left() - 1 <= 1e-5) ? true : false));
60 System::Console::WriteLine(u"Margins.Top Equals 1.1 : {0} ", System::ObjectExt::Box<bool>((info->get_Margins()->get_Top() - 1.1 <= 1e-5) ? true : false));
61 System::Console::WriteLine(u"Margins.Right Equals 1.2 : {0} ", System::ObjectExt::Box<bool>((info->get_Margins()->get_Right() - 1.2 <= 1e-5) ? true : false));
62 System::Console::WriteLine(u"Margins.Bottom Equals 1.2 : {0} ", System::ObjectExt::Box<bool>((info->get_Margins()->get_Bottom() - 1.3 <= 1e-5) ? true : false));
63
64 System::Console::WriteLine(u"Margin.Borders Equals Border.AroundEveryPage : {0} ", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(info->get_Margins()->get_Borders(), Aspose::Tasks::Visualization::Border::AroundEveryPage)));
65}
66
67void ReadHeaderFooterInfo::AssertLegendCorrect(System::SharedPtr<Aspose::Tasks::Visualization::PageInfo> info)
68{
69 System::Console::WriteLine(u"Legend left text Equals LEFT LEGEND : {0} ", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(info->get_Legend()->get_LeftText(), u"LEFT LEGEND")));
70 System::Console::WriteLine(u"Legend center text Equals CENTER LEGEND : {0} ", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(info->get_Legend()->get_CenteredText(), u"CENTER LEGEND")));
71 System::Console::WriteLine(u"Legend right text Equals RIGHT LEGEND : {0} ", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(info->get_Legend()->get_RightText(), u"RIGHT LEGEND")));
72
73 System::Console::WriteLine(u"LegendOn Equals Legend.OnEveryPage : {0} ", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(info->get_Legend()->get_LegendOn(), Aspose::Tasks::Visualization::Legend::OnEveryPage)));
74 System::Console::WriteLine(u"Legend Width Equals 5 : {0} ", System::ObjectExt::Box<bool>((info->get_Legend()->get_Width() - 5 <= 1e-5) ? true : false));
75}
Adding Image to Page Header/Footer
Aspose.Tasks for C++ API provides the capability to manipulate the document’s page header and footer information. The code example given below demonstrates how to add image to page’s header.
1System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"AddImageToPageHeaderFooter.mpp");
2
3project->get_RootTask()->get_Children()->Add(u"Task1");
4System::SharedPtr<PageInfo> pageInfo = project->get_DefaultView()->get_PageInfo();
5
6{
7 System::SharedPtr<System::Drawing::Image> image = System::Drawing::Image::FromFile(dataDir + u"Image1.png");
8 // Clearing resources under 'using' statement
9 System::Details::DisposeGuard<1> __dispose_guard_0({ image});
10 // ------------------------------------------
11
12 try
13 {
14 pageInfo->get_Header()->set_CenteredImage(image);
15 pageInfo->get_Legend()->set_LeftImage(image);
16 pageInfo->get_Legend()->set_LeftText(System::String::Empty);
17 System::SharedPtr<MPPSaveOptions> saveOptions = System::MakeObject<MPPSaveOptions>();
18 saveOptions->set_WriteViewData(true);
19 project->Save(dataDir + u"AddImageToPageHeaderFooter_out.mpp", saveOptions);
20 }
21 catch(...)
22 {
23 __dispose_guard_0.SetCurrentException(std::current_exception());
24 }
25}