Cómo convertir los datos del proyecto a PDF
Este artículo muestra cómo representar los datos del proyecto a PDF utilizando Aspose.Tasks para Java. La API proporciona las siguientes capacidades al tiempo que representa datos del proyecto a varios formatos de salida, incluido PDF.
Información del creador PDF
- Tenga en cuenta que no puede establecer valores en la aplicación **** y Productor Los campos, debido a Aspose Ltd. y Aspose.Tasks para Java X.X.X se mostrarán en estos campos.
Guardar un proyecto como PDF
La clase Proyecto expone el método Guardar que se utiliza para guardar un proyecto en varios formatos. El método Guardar le permite representar datos del proyecto a PDF utilizando el tipo de enumeración SaveFileFormat.
Para guardar un proyecto en PDF:
- Cargue un archivo de proyecto de Microsoft.
- Guarde el proyecto en PDF usando SaveFileFormat.pdf.
Las siguientes líneas de código muestran cómo lograr esto.
1// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
2// The path to the documents directory.
3String dataDir = Utils.getDataDir(SaveAsPdf.class);
4
5// Read the input Project file
6Project project = new Project(dataDir + "project6.mpp");
7
8project.save(dataDir + "Project5.pdf", SaveFileFormat.PDF);
9
10// Fitting contents to cell size
11Project project1 = new Project(dataDir + "project6.mpp");
12SaveOptions o = new PdfSaveOptions();
13
14// Set the LegendOnEachPage property to false to hide legends
15
16// Set the row height to fit cell content
17o.setFitContent(true);
18o.setTimescale(Timescale.Months);
19o.setPresentationFormat(PresentationFormat.TaskUsage);
20project1.save("result_months.pdf", o);
21o.setLegendOnEachPage(false);
22project1.save(dataDir + "result_months_WithoutLegend.pdf", o);
23
24// Display result of conversion.
25System.out.println("Process completed Successfully");Supported Graphical Column Indicators
Aspose.Tasks draw graphical column indicators while rendering project data to PDF. The following are the graphical indicators supported by Aspose.Tasks.
| Indicator Type | Graphical Representation |
|---|---|
| Task Indicators | ![]() |
| Resource Indicators | ![]() |
| Assignment Indicators | ![]() |
Saving to Multiple PDF Files
To save the project data to multiple PDF files, set the SaveToSeparateFiles flag to true.
1// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
2Project project2 = new Project("RenderMe.mpp");
3PdfSaveOptions saveOptions = new PdfSaveOptions();
4saveOptions.setSaveToSeparateFiles(true);
5ArrayList<Integer> arl = new ArrayList<Integer>();
6saveOptions.setPages(arl);
7saveOptions.getPages().add(1);
8saveOptions.getPages().add(4);
9project2.save("result.pdf", saveOptions);Customizing TextStyle for Project Data
Aspose.Tasks allows you to customize the text style for overallocated resources. By default, the style for overallocated resources is similar to Microsoft Project (MSP), that is, it is red and bold. TextItemType.OverallocatedResources enables you to customize the color and style for overallocated resources. The example below shows how.
1// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
2Project project3 = new Project("Advanced Assignments A_Start.mpp");
3SaveOptions options = new PdfSaveOptions();
4options.setPresentationFormat(PresentationFormat.ResourceSheet);
5
6TextStyle style = new TextStyle();
7style.setColor(Color.ORANGE);
8style.setFontStyle(1);
9style.setItemType(TextItemType.OverallocatedResources);
10
11options.setTextStyles(new ArrayList<TextStyle>());
12options.getTextStyles().add(style);
13project3.save("temp.pdf", options);Customizing Date Format
Aspose.Tasks give developers control over date formatting when rendering project data to output. The following example shows how to use the DateFormat enumerator to specify the date format.
1Project project = new Project();
2Date date = new Date();
3project.setStartDate(date);
4// By default project.DateFormat == DateFormat.Date_ddd_mm_dd_yy (Mon 09/22/14)
5// customize DateFormat (September 22, 2014)
6project.setDateFormat(DateFormat.Date_mmmm_dd_yyyy);
7project.save("saved.pdf", SaveFileFormat.PDF);
8//Export to date format 19/07/2016
9project.setDateFormat(DateFormat.DateDdMmYyyy);
10project.save("p2.pdf", SaveFileFormat.PDF);

