Umwandeln Sie Projektdaten in PDF
Aspose.Tasks FÜR C ++ API bietet die Möglichkeit, Projektdaten für das PDF -Format zu rendern. Dieser Artikel gibt einen detaillierten Überblick über die Vielfalt der in Asposes verfügbaren Optionen zum Exportieren von Projekten nach PDF.
ein Projekt als pdf speichern
Die Projekt Klasse enthält die Speichernmethode, mit der ein Projekt in verschiedenen Formaten speichert wird. Mit der Speichernmethode können Sie Projektdaten mithilfe des SaveFileformat -Aufzählungsarts an PDF rendern.
Um ein Projekt vor PDF zu speichern:
- Laden Sie eine Microsoft -Projektdatei.
- Speichern Sie das Projekt in PDF mit SaveFileFormat.pdf.
Die folgenden Codezeilen zeigen, wie dies mit C ++ erreicht werden kann.
1// Read the input Project file
2System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"CreateProject2.mpp");
3
4// Save the Project as PDF
5project->Save(dataDir + u"SaveProjectAsPDF_out.pdf", Aspose::Tasks::Saving::SaveFileFormat::PDF);
Fitting Contents to Cell Size
It is common that a task (or resource) name is so long that it is truncated when project views are rendered. Aspose.Tasks for C++ API provides the FitContent property in the SaveOptions class to avoid truncation of task and resource names. The code example given below renders a project to PDF format with the FitContent property set to true.
1System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"CreateProject2.mpp");
2System::SharedPtr<SaveOptions> saveOptions = System::MakeObject<PdfSaveOptions>();
3
4// Set option fit content to true
5saveOptions->set_FitContent(true);
6saveOptions->set_Timescale(Aspose::Tasks::Visualization::Timescale::Months);
7saveOptions->set_PresentationFormat(Aspose::Tasks::Visualization::PresentationFormat::TaskUsage);
8project->Save(dataDir + u"FitContentsToCellSize_out.pdf", saveOptions);
Printing or Hiding Legends when Rendering
To let you print or hide the legends on each page, the SaveOptions class provides the LegendOnEachPage property. If this flag is set to true, legends are printed on each page in the output file.
1System::SharedPtr<SaveOptions> saveOptions = System::MakeObject<PdfSaveOptions>();
2
3// Set the LegendOnEachPage property to false to hide legends
4saveOptions->set_LegendOnEachPage(false);
Supported Graphical Column Indicators
Aspose.Tasks for C++ API draws graphical column indicators when rendering project data to output PDF. The following graphical indicators are supported by Aspose.Tasks:
Indicator Type | Graphical Indicator |
---|---|
Task Indicators | ![]() |
Resource Indicators | ![]() |
Assignment Indicators | ![]() |
Saving to Multiple PDF Files
To save project data to multiple PDF files, set the SaveToSeparateFiles flag to true.
1System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"Software Development Plan.mpp");
2System::SharedPtr<PdfSaveOptions> saveOptions = System::MakeObject<PdfSaveOptions>();
3saveOptions->set_SaveToSeparateFiles(true);
4saveOptions->set_Pages(System::MakeObject<System::Collections::Generic::List<int32_t>>());
5saveOptions->get_Pages()->Add(1);
6saveOptions->get_Pages()->Add(4);
7project->Save(dataDir + u"SaveToMultiplePDFFiles_out.pdf", System::StaticCast<Aspose::Tasks::Saving::SaveOptions>(saveOptions));
Customizing TextStyle for Project Data
Aspose.Tasks for C++ API allows developers to customize the text style for overallocated resources. By default, the style used for overallocated resources is similar to Microsoft Project (MSP), that is, red and bold. TextItemType.OverallocatedResources makes it possible to customize the color and style for the overallocated resources.
1System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"CreateProject2.mpp");
2System::SharedPtr<SaveOptions> options = System::MakeObject<PdfSaveOptions>();
3options->set_PresentationFormat(Aspose::Tasks::Visualization::PresentationFormat::ResourceSheet);
4
5System::SharedPtr<TextStyle> style = System::MakeObject<TextStyle>();
6style->set_Color(System::Drawing::Color::get_OrangeRed());
7style->set_FontStyle(System::Drawing::FontStyle::Bold);
8System::setter_or_wrap(style.GetPointer(), &TextStyle::get_FontStyle, &TextStyle::set_FontStyle, System::Drawing::FontStyle::Italic);
9style->set_ItemType(Aspose::Tasks::Visualization::TextItemType::OverallocatedResources);
10
11options->set_TextStyles(System::MakeObject<System::Collections::Generic::List<System::SharedPtr<TextStyle>>>());
12options->get_TextStyles()->Add(style);
13project->Save(dataDir + u"CustomizeTextStyle_out.pdf", options);
Customizing Date Formats
Aspose.Tasks for C++ API allows developers to customize the date format using the DateFormat enumerator when rendering project data.
1System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"CreateProject2.mpp");
2
3auto options = [&]{ auto tmp_0 = System::MakeObject<PdfSaveOptions>(); tmp_0->set_PresentationFormat(Aspose::Tasks::Visualization::PresentationFormat::GanttChart); tmp_0->set_FitContent(true); tmp_0->set_UseProjectDefaultFont(false); tmp_0->set_DefaultFontName(u"Segoe UI Black"); return tmp_0; }();
4project->Save(dataDir + u"CreateProject2_out.pdf", System::StaticCast<Aspose::Tasks::Saving::SaveOptions>(options));
Setting Default Font
Setting default font during rending of documents helps when a font is not found. In such a case, the default font replaces the missing font, and output is not affected. Aspose.Tasks for C++ API lets you specify the default font using the DefaultFontName property of the PdfSaveOptions as shown in the following code sample.
1System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"CreateProject2.mpp");
2project->Set(Prj::StartDate(), System::DateTime(2014, 9, 22));
3
4// By default project.DateFormat == DateFormat.Date_ddd_mm_dd_yy (Mon 09/22/14) customize DateFormat (September 22, 2014)
5project->Set<DateFormat>(Prj::DateFormat(), Aspose::Tasks::DateFormat::DateMmmmDdYyyy);
6project->Save(dataDir + u"CustomizeDateFormats1_out.pdf", Aspose::Tasks::Saving::SaveFileFormat::PDF);
7
8// Export to date format 19/07/2016
9project->Set<DateFormat>(Prj::DateFormat(), Aspose::Tasks::DateFormat::DateDdMmYyyy);
10project->Save(dataDir + u"CustomizeDateFormats2_out.pdf", Aspose::Tasks::Saving::SaveFileFormat::PDF);