一般的な変換オプション
この記事では、Microsoft Project MPPファイルをグラフィカル形式(PDF、TIFF、PNG、SVG、HTML)に変換するために一般的なオプションについて説明します。 .NET APIのAspose.Tasksを使用して、MS Project MPP、Primavera P6 XML、Primavera Xer、またはその他のサポートされた入力形式からPDFまたはグラフィカル形式にロードされたプロジェクトを変換できます。この場合、特定のプロジェクトのビューは指定された形式でレンダリングされます。
保存するビューを指定
Microsoft Projectは、「ガントチャート」、「タスク使用」、「リソース使用」など、さまざまなビューをサポートしています。各ビューをカスタマイズでき、これらの設定はMPPファイルに保存されます。 .NETのAspose.tasksを使用すると、 project.viewsコレクションを使用して、ユーザーがこれらの設定を調べて変更できます。
プロジェクトがグラフィカル形式に保存されたときにエクスポートされるビューを指定する3つの方法があります。
- ビューを明示的に指定しないでください。 この場合、project.defaultViewがレンダリングされます。デフォルトビューが欠落している場合、ガントチャートビューがレンダリングされます。
- saveoptions.presentationformatを使用して、 presentationformat列挙の値を指定します。 この場合、CRORRECTENTENT SCREANプロパティを使用したビューは、project.Viewsコレクションから選択されます。 ビューが欠落している場合、標準のフォーマットを使用したデフォルトのGanttchartビューが使用されます。
- saveoptions.viewsettingsプロパティを使用して、レンダリングするビューオブジェクトを明示的に指定します。 Viewオブジェクトが指定されている場合、saveoptions.presentationformatの値は無視されます。
ページサイズの指定
MicrosoftプロジェクトファイルをPDF、画像、またはXPSにレンダリングする場合、適切なページサイズを指定することが重要です。これにより、正しいチャートスケーリングが保証され、データの切り捨てられたデータのリスクが低下し、ドキュメントをビジネスプロセスに統合することができます。 Aspose.tasksを使用すると、標準とカスタムの両方のページサイズを指定したり、MPPファイルから保存された設定を使用できます。
ページサイズは、次の方法で指定できます。
- ページサイズを指定しないでください。 この場合、Pagesize.A4が使用されます。
- Saveoptions.Pagesizeプロパティを介して事前定義されたページサイズを指定します。
1 Project project = new Project("Project.mpp");
2 PdfSaveOptions saveOptions = new PdfSaveOptions()
3 {
4 PresentationFormat = PresentationFormat.GanttChart,
5 PageSize = PageSize.A2
6 };
7
8project.Save("OutputFitToA2.pdf", saveOptions);
- Specify custom PageSize via SaveOptions.CustomPageSize property:
1 Project project = new Project("Project.mpp");
2 PdfSaveOptions saveOptions = new PdfSaveOptions()
3 {
4 PresentationFormat = PresentationFormat.GanttChart,
5 CustomPageSize = new SizeF(700, 900),
6 };
7
8 project.Save("OutputFitToCustomPage.pdf", saveOptions);
- Specify PageSize.DefinedInView to use page size saved in MS Project’s Page Setup dialog:
The option is applicable when input file is in MS Project MPP format
1 Project project = new Project("Project.mpp");
2
3 var taskUsageView= project.Views.FirstOrDefault(v => v.Screen == ViewScreen.TaskUsage);
4 taskUsageView.PageInfo.PageSettings.PaperSize = PrinterPaperSize.PaperEnvelope10;
5
6 PdfSaveOptions saveOptions = new PdfSaveOptions()
7 {
8 ViewSettings = taskUsageView,
9 PageSize = PageSize.DefinedInView
10 };
11
12 project.Save("OutputToEnvelope.pdf", saveOptions);
Note: The PageSize.DefinedInView
option is only effective when the source file is an MPP file and contains a view with saved page setup settings. If the view does not contain page setup information or the input file format is not MPP (e.g., XML), this option will have no effect.
Fitting Contents to Cell Size
Commonly, a task (or resource) name is so long that it is truncated when project views are rendered. Aspose.Tasks for .NET provides the FitContent property in the SaveOptions class to avoid truncation of task and resource names. The code example below renders a project to PDF format with the FitContent property set to true.
Here is an examples of an output file without and with FitContent option:
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 out
1 SaveOptions options = new PdfSaveOptions();
2
3 // Set the LegendDrawingOptions property to NoLegend to hide legends
4 options.LegendDrawingOptions = LegendDrawingOptions.NoLegend;
Saving to Multiple PDF or graphical files
To save project data to multiple PDF files, set the SaveToSeparateFiles flag to true.