프로젝트 데이터를 PDF로 변환합니다
Aspose.Tasks for C ++ API는 프로젝트 데이터를 PDF 형식으로 렌더링하는 기능을 제공합니다. 이 기사는 PDF로 프로젝트를 내보내기위한 Aspose.task에서 사용할 수있는 다양한 옵션에 대한 자세한 개요를 제공합니다.
PDF로 프로젝트 저장
Project 클래스는 프로젝트를 다양한 형식으로 저장하는 데 사용되는 저장 메소드를 노출시킵니다. 저장 메소드를 사용하면 SaveFileFormat 열거 유형을 사용하여 프로젝트 데이터를 PDF로 렌더링 할 수 있습니다.
PDF에 프로젝트를 저장하려면 :
- Microsoft 프로젝트 파일을로드하십시오.
- savefileformat.pdf를 사용하여 프로젝트를 PDF에 저장하십시오.
다음 줄의 코드는 C ++를 사용하여이를 달성하는 방법을 보여줍니다.
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);