Skip to content

Commit 3202458

Browse files
Merge pull request #2 from saqibmasood/master
Add examples
2 parents 5a94d48 + fec206b commit 3202458

File tree

13 files changed

+300
-27
lines changed

13 files changed

+300
-27
lines changed

Examples/pom.xml

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3-
<modelVersion>4.0.0</modelVersion>
4-
<groupId>com.aspose</groupId>
5-
<artifactId>imaging-java-examples</artifactId>
6-
<version>1.0-SNAPSHOT</version>
7-
<packaging>jar</packaging>
8-
<properties>
9-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
10-
<maven.compiler.source>1.7</maven.compiler.source>
11-
<maven.compiler.target>1.7</maven.compiler.target>
12-
</properties>
13-
<dependencies>
14-
<dependency>
15-
<groupId>com.aspose</groupId>
16-
<artifactId>aspose-imaging</artifactId>
17-
<version>2.9.0</version>
18-
<classifier>jdk16</classifier>
19-
</dependency>
20-
</dependencies>
21-
<repositories>
22-
<repository>
23-
<id>aspose-maven-repository</id>
24-
<url>http://maven.aspose.com/repository/repo/</url>
25-
</repository>
26-
</repositories>
27-
</project>
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.aspose</groupId>
5+
<artifactId>imaging-java-examples</artifactId>
6+
<version>1.0-SNAPSHOT</version>
7+
<packaging>jar</packaging>
8+
<properties>
9+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
10+
<maven.compiler.source>1.7</maven.compiler.source>
11+
<maven.compiler.target>1.7</maven.compiler.target>
12+
</properties>
13+
<dependencies>
14+
<dependency>
15+
<groupId>com.aspose</groupId>
16+
<artifactId>aspose-imaging</artifactId>
17+
<version>3.0</version>
18+
<classifier>jdk16</classifier>
19+
</dependency>
20+
</dependencies>
21+
<repositories>
22+
<repository>
23+
<id>aspose-maven-repository</id>
24+
<url>http://maven.aspose.com/repository/repo/</url>
25+
</repository>
26+
</repositories>
27+
</project>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright 2001-2015 Aspose Pty Ltd. All Rights Reserved.
3+
*
4+
* This file is part of Aspose.Imaging. The source code in this file
5+
* is only intended as a supplement to the documentation, and is provided
6+
* "as is", without warranty of any kind, either expressed or implied.
7+
*/
8+
package com.aspose.imaging.examples.djvu;
9+
10+
import com.aspose.imaging.Image;
11+
import com.aspose.imaging.Rectangle;
12+
import com.aspose.imaging.examples.Utils;
13+
import com.aspose.imaging.fileformats.djvu.DjvuImage;
14+
import com.aspose.imaging.fileformats.png.PngColorType;
15+
import com.aspose.imaging.imageoptions.DjvuMultiPageOptions;
16+
import com.aspose.imaging.imageoptions.PngOptions;
17+
18+
public class ConvertDjvuPagePortionToImage {
19+
20+
public static void main(String[] args) throws Exception {
21+
// The path to the documents directory.
22+
String dataDir = Utils.getDataDir(ConvertDjvuPagePortionToImage.class);
23+
24+
//Load a DjVu image
25+
DjvuImage image = (DjvuImage) Image.load(dataDir + "Sample.djvu");
26+
27+
//Create an instance of PngOptions
28+
PngOptions exportOptions = new PngOptions();
29+
30+
//Set ColorType to Grayscale
31+
exportOptions.setColorType(PngColorType.Grayscale);
32+
33+
//Create an instance of Rectangle and specify the portion on DjVu page
34+
Rectangle exportArea = new Rectangle(0, 0, 2000, 2000);
35+
36+
//Specify the DjVu page index
37+
int exportPageIndex = 2;
38+
39+
//Initialize an instance of DjvuMultiPageOptions
40+
//while passing index of DjVu page index and instance of Rectangle
41+
//covering the area to be exported
42+
exportOptions.setMultiPageOptions(new DjvuMultiPageOptions(exportPageIndex, exportArea));
43+
44+
//Save the image
45+
image.save(dataDir + "Output.png", exportOptions);
46+
47+
System.out.println("File conveted");
48+
}
49+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright 2001-2015 Aspose Pty Ltd. All Rights Reserved.
3+
*
4+
* This file is part of Aspose.Imaging. The source code in this file
5+
* is only intended as a supplement to the documentation, and is provided
6+
* "as is", without warranty of any kind, either expressed or implied.
7+
*/
8+
package com.aspose.imaging.examples.djvu;
9+
10+
import com.aspose.imaging.ColorPaletteHelper;
11+
import com.aspose.imaging.Image;
12+
import com.aspose.imaging.IntRange;
13+
import com.aspose.imaging.ResolutionSetting;
14+
import com.aspose.imaging.examples.Utils;
15+
import com.aspose.imaging.fileformats.djvu.DjvuImage;
16+
import com.aspose.imaging.imageoptions.DjvuMultiPageOptions;
17+
import com.aspose.imaging.imageoptions.GifOptions;
18+
19+
public class ConvertDjvuPagesToGif {
20+
21+
public static void main(String[] args) throws Exception {
22+
// The path to the documents directory.
23+
String dataDir = Utils.getDataDir(ConvertDjvuPagesToGif.class);
24+
25+
//Load a DjVu image
26+
DjvuImage image = (DjvuImage) Image.load(dataDir + "Sample.djvu");
27+
28+
//Create an instance of GifOptions with its default constructor
29+
GifOptions exportOptions = new GifOptions();
30+
31+
//Set the resolution of resultant image
32+
exportOptions.setResolutionSettings(new ResolutionSetting(300, 300));
33+
34+
//Set PaletteCorrection to false
35+
exportOptions.setDoPaletteCorrection(false);
36+
37+
//Create an instance of 8bit palette and set it as Palette property for instance of GifOptions
38+
exportOptions.setPalette(ColorPaletteHelper.create8Bit());
39+
40+
//Create an instance of IntRange and initialize it with range of pages to be exported
41+
IntRange range = new IntRange(0, 2); //Export first 2 pages
42+
43+
//Initialize an instance of DjvuMultiPageOptions while passing instance of IntRange
44+
exportOptions.setMultiPageOptions(new DjvuMultiPageOptions(range));
45+
46+
//Call Save method while passing instance of GifOptions
47+
image.save(dataDir + "output.gif", exportOptions);
48+
49+
System.out.println("File conveted");
50+
}
51+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2001-2015 Aspose Pty Ltd. All Rights Reserved.
3+
*
4+
* This file is part of Aspose.Imaging. The source code in this file
5+
* is only intended as a supplement to the documentation, and is provided
6+
* "as is", without warranty of any kind, either expressed or implied.
7+
*/
8+
package com.aspose.imaging.examples.djvu;
9+
10+
import com.aspose.imaging.Image;
11+
import com.aspose.imaging.IntRange;
12+
import com.aspose.imaging.examples.Utils;
13+
import com.aspose.imaging.fileformats.djvu.DjvuImage;
14+
import com.aspose.imaging.imageoptions.BmpOptions;
15+
import com.aspose.imaging.imageoptions.DjvuMultiPageOptions;
16+
17+
public class ConvertDjvuPagesToImages {
18+
19+
public static void main(String[] args) throws Exception {
20+
// The path to the documents directory.
21+
String dataDir = Utils.getDataDir(ConvertDjvuPagesToImages.class);
22+
23+
//Load a DjVu image
24+
DjvuImage image = (DjvuImage) Image.load(dataDir + "Sample.djvu");
25+
26+
//Create an instance of BmpOptions
27+
BmpOptions exportOptions = new BmpOptions();
28+
29+
//Set BitsPerPixel for resultant images
30+
exportOptions.setBitsPerPixel(32);
31+
32+
//Create an instance of IntRange and initialize it with range of pages to be exported
33+
IntRange range = new IntRange(0, 2); //Export first 2 pages
34+
35+
int counter = 0;
36+
for (int i : range.getRange()) {
37+
//Save each page in separate file, as BMP do not support layering
38+
exportOptions.setMultiPageOptions(new DjvuMultiPageOptions(range.getArrayOneItemFromIndex(counter)));
39+
String output = dataDir + "Output-" + (counter++) + ".bmp";
40+
image.save(output, exportOptions);
41+
}
42+
43+
// Display Status.
44+
System.out.println("File conveted");
45+
}
46+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2001-2015 Aspose Pty Ltd. All Rights Reserved.
3+
*
4+
* This file is part of Aspose.Imaging. The source code in this file
5+
* is only intended as a supplement to the documentation, and is provided
6+
* "as is", without warranty of any kind, either expressed or implied.
7+
*/
8+
package com.aspose.imaging.examples.djvu;
9+
10+
import com.aspose.imaging.Image;
11+
import com.aspose.imaging.IntRange;
12+
import com.aspose.imaging.examples.Utils;
13+
import com.aspose.imaging.fileformats.djvu.DjvuImage;
14+
import com.aspose.imaging.fileformats.tiff.enums.TiffExpectedFormat;
15+
import com.aspose.imaging.imageoptions.DjvuMultiPageOptions;
16+
import com.aspose.imaging.imageoptions.TiffOptions;
17+
18+
public class ConvertDjvuPagesToTiff {
19+
20+
public static void main(String[] args) throws Exception {
21+
// The path to the documents directory.
22+
String dataDir = Utils.getDataDir(ConvertDjvuPagesToTiff.class);
23+
24+
//Load a DjVu image
25+
DjvuImage image = (DjvuImage) Image.load(dataDir + "Sample.djvu");
26+
27+
//Create an instance of TiffOptions & use preset options for Black n While with Deflate compression
28+
TiffOptions exportOptions = new TiffOptions(TiffExpectedFormat.TiffDeflateBW);
29+
30+
//Create an instance of IntRange and initialize it with range of pages to be exported
31+
IntRange range = new IntRange(0, 2); //Export first 2 pages
32+
33+
//Initialize the DjvuMultiPageOptions
34+
exportOptions.setMultiPageOptions(new DjvuMultiPageOptions(range));
35+
36+
//Call Save method while passing instance of TiffOptions
37+
image.save(dataDir + "Output.tiff", exportOptions);
38+
39+
// Display Status.
40+
System.out.println("File conveted");
41+
}
42+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2001-2015 Aspose Pty Ltd. All Rights Reserved.
3+
*
4+
* This file is part of Aspose.Imaging. The source code in this file
5+
* is only intended as a supplement to the documentation, and is provided
6+
* "as is", without warranty of any kind, either expressed or implied.
7+
*/
8+
package com.aspose.imaging.examples.djvu;
9+
10+
import com.aspose.imaging.Image;
11+
import com.aspose.imaging.IntRange;
12+
import com.aspose.imaging.examples.Utils;
13+
import com.aspose.imaging.fileformats.djvu.DjvuImage;
14+
import com.aspose.imaging.fileformats.pdf.PdfDocumentInfo;
15+
import com.aspose.imaging.imageoptions.DjvuMultiPageOptions;
16+
import com.aspose.imaging.imageoptions.PdfOptions;
17+
18+
public class ConvertDjvuToPdf {
19+
20+
public static void main(String[] args) throws Exception {
21+
// The path to the documents directory.
22+
String dataDir = Utils.getDataDir(ConvertDjvuToPdf.class);
23+
24+
//Load a DjVu image
25+
DjvuImage image = (DjvuImage) Image.load(dataDir + "Sample.djvu");
26+
27+
//Create an instance of PdfOptions
28+
PdfOptions exportOptions = new PdfOptions();
29+
30+
//Initialize the metadata for Pdf document
31+
exportOptions.setPdfDocumentInfo(new PdfDocumentInfo());
32+
33+
//Create an instance of IntRange and initialize it with the range of DjVu pages to be exported
34+
IntRange range = new IntRange(0, 3); //Export first 3 pages
35+
36+
//Initialize an instance of DjvuMultiPageOptions with range of DjVu pages to be exported
37+
exportOptions.setMultiPageOptions(new DjvuMultiPageOptions(range));
38+
39+
//Save the result in PDF format
40+
image.save(dataDir + "output.pdf", exportOptions);
41+
42+
// Display Status.
43+
System.out.println("File conveted");
44+
}
45+
}
46+
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2001-2015 Aspose Pty Ltd. All Rights Reserved.
3+
*
4+
* This file is part of Aspose.Imaging. The source code in this file
5+
* is only intended as a supplement to the documentation, and is provided
6+
* "as is", without warranty of any kind, either expressed or implied.
7+
*/
8+
package com.aspose.imaging.examples.djvu;
9+
10+
import com.aspose.imaging.Image;
11+
import com.aspose.imaging.examples.Utils;
12+
import com.aspose.imaging.fileformats.djvu.DjvuImage;
13+
import com.aspose.imaging.fileformats.tiff.enums.TiffExpectedFormat;
14+
import com.aspose.imaging.imageoptions.DjvuMultiPageOptions;
15+
import com.aspose.imaging.imageoptions.TiffOptions;
16+
17+
public class ConvertDjvuToTiff {
18+
19+
public static void main(String[] args) throws Exception {
20+
// The path to the documents directory.
21+
String dataDir = Utils.getDataDir(ConvertDjvuToTiff.class);
22+
23+
//Load a DjVu image
24+
DjvuImage image = (DjvuImage) Image.load(dataDir + "Sample.djvu");
25+
26+
27+
//Create an instance of TiffOptions & use preset options for Black n While with Deflate compression
28+
TiffOptions exportOptions = new TiffOptions(TiffExpectedFormat.TiffDeflateBW);
29+
30+
//Initialize the DjvuMultiPageOptions
31+
exportOptions.setMultiPageOptions(new DjvuMultiPageOptions());
32+
33+
//Call Save method while passing instance of TiffOptions
34+
image.save(dataDir + "Output.tiff", exportOptions);
35+
36+
// Display Status.
37+
System.out.println("File conveted");
38+
}
39+
}
Binary file not shown.

0 commit comments

Comments
 (0)