Opciones de conversión comunes

En este artículo vamos a describir opciones que son comunes para las conversiones de los archivos MPP de Microsoft Project a formatos gráficos (PDF, TIFF, PNG, SVG, HTML). Aspose.Tasks para .NET API se puede utilizar para convertir el proyecto cargado de MS Project MPP, Primavera P6 XML, Primavera Xer u otros formatos de entrada compatibles en PDF o formatos gráficos. En este caso, la opinión de un proyecto específico se representa en formato especificado.

especificando una vista para guardar

Microsoft Project admite diferentes vistas, como ‘Gantt Chart’, ‘Uso de tareas’, ‘uso de recursos’, etc. Cada vista se puede personalizar y estas configuraciones se almacenan en el archivo MPP. Aspose.Tasks para .NET permite al usuario examinar y cambiar estas configuraciones usando Project.Views Colección.

Hay 3 formas de especificar la vista que se exportará cuando el proyecto se guarde a formatos gráficos.

  1. No especifique una vista explícitamente. En este caso, el proyecto. DefaultView se presentará. Si falta la vista predeterminada, se representará la vista del gráfico Gantt.
  2. Use SavePtions.PresentationFormat para especificar el valor de PresentationFormat Enumeración. En este caso, la vista con la propiedad de pantalla corresponsal se seleccionará de Project.Views Collection. Si falta la vista, se utilizará la vista de ganttchart predeterminada con formato estándar.
  3. Use la propiedad Saveoptions.ViewSettings para especificar explícitamente el objeto de vista para renderizar. Si se especifica el objeto de vista, se ignora el valor de SaveOptions.PresentationFormat.

Especificar un tamaño de página

Al representar archivos del proyecto de Microsoft a PDF, imagen o XPS, es importante especificar el tamaño de página apropiado. Esto garantiza la escala correcta del gráfico, reduce el riesgo de datos truncados y permite una mejor integración del documento en los procesos comerciales. Aspose.Tasks le permite especificar los tamaños de página estándar y personalizados, así como usar la configuración guardada de un archivo MPP.

El tamaño de la página se puede especificar de las siguientes maneras:

  1. No especifique el tamaño de la página. En este caso, se utilizará la página. A4.
  2. Especifique la página predefinida a través de SaveOptions.pageSize Propiedad:
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);
  1. 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);
  1. Specify PageSize.DefinedInView to use page size saved in MS Project’s Page Setup dialog:

MS Project 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.

1Project project = new Project("New Project.mpp");
2SaveOptions options = new PdfSaveOptions();
3
4// Set option fit content to true
5options.FitContent = true;
6options.Timescale = Timescale.Months;
7options.PresentationFormat = PresentationFormat.TaskUsage;
8project.Save("FitContentsToCellSize_out.pdf", options);

Here is an examples of an output file without and with FitContent option:

Without FitContent With FitContent

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.

1Project project = new Project("New Project.mpp");
2PdfSaveOptions options = new PdfSaveOptions();
3options.SaveToSeparateFiles = true;
4options.Pages = new List<int>();
5options.Pages.Add(1);
6options.Pages.Add(4);
7project.Save("SaveToMultiplePDFFiles_out.pdf", (SaveOptions)options);
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.