Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
423afc0
Added XSD Schema
asadalikhan90 Jun 12, 2018
3e266d3
Added new examples for 18.5
asadalikhan90 Jun 19, 2018
52b63a0
Added new Examples
asadalikhan90 Jul 22, 2018
a17c1f8
PDF to XLSX Conversion
asadalikhan90 Jul 22, 2018
95383e3
An error fixed
farhan-raza Jul 22, 2018
78d2b0d
File Updated
farhan-raza Aug 24, 2018
0c4db97
Added New Examples
asadalikhan90 Sep 23, 2018
19d2c97
Added 18.9 Examples
asadalikhan90 Oct 7, 2018
fd5acca
Updated pom.xml
farhan-raza Nov 23, 2018
3a52415
Updated Aspose Repository URL
asadalikhan90 Dec 26, 2018
ade553d
Updated for 18.12 version
farhan-raza Jan 7, 2019
5dfd2d9
Examples Added for Version 19.2
aliahmedaspose Mar 11, 2019
3ba4cf1
Gists Renamed
aliahmedaspose Mar 11, 2019
025179b
Merge pull request #35 from aliahmedaspose/master
aliahmedaspose Mar 12, 2019
61101ca
Updated pom.xml
asadalikhan90 Mar 26, 2019
b69f862
Examples Updated for Version 19.3
aliahmedaspose Apr 8, 2019
d5012d8
Merge pull request #36 from aliahmedaspose/master
aliahmedaspose Apr 8, 2019
75d7d3f
Examples updated for version 19.4
aliahmedaspose May 14, 2019
b35fac6
Merge pull request #37 from aliahmedaspose/master
aliahmedaspose May 14, 2019
fa495ca
Examples Updated for Version 19.5
aliahmedaspose Jun 26, 2019
1fc78aa
Updated API for Version 19.6
aliahmedaspose Jul 3, 2019
4178381
Added Examples
aliahmedaspose Aug 1, 2019
b79ea9c
Added Examples
aliahmedaspose Aug 7, 2019
599dea6
Update README.md
aliahmedaspose Aug 16, 2019
24b9512
Update Aspose.Pdf.xsd
aliahmedaspose Aug 16, 2019
d1245db
Merge branch 'master' of https://github.com/aspose-pdf/Aspose.PDF-for…
aliahmedaspose Aug 16, 2019
521c232
Update pom.xml
aliahmedaspose Sep 5, 2019
734609b
Updates for Aspose.PDF for Java 19.9 Release
kashifiqb Sep 30, 2019
f2a58ef
Merge pull request #39 from kashifiqb/master
kashifiqb Sep 30, 2019
50f0448
Updated README.md for guidance about running the examples
kashifiqb Oct 9, 2019
449eee1
Merge pull request #40 from kashifiqb/master
kashifiqb Oct 9, 2019
2efc4b0
Updated code samples for OptimizePDFFileSize related features
kashifiqb Oct 19, 2019
ea51d99
Merge pull request #41 from kashifiqb/master
kashifiqb Oct 19, 2019
069118a
Examples update for Aspose.PDF for Java 19.10 Release
Nov 4, 2019
f8d0a0c
Merge pull request #42 from kashifiqb/master
kashifiqb Nov 4, 2019
e17d860
Examples update for Aspose.PDF for Java 19.11 Release
Nov 29, 2019
b1cd715
Examples updated to Aspose.PDF for Java 19.12 Release
Dec 24, 2019
5172c64
Examples update for Aspose.PDF for Java 20.1
kashifiqb Jan 27, 2020
b9ca4e2
Examples update for Aspose.PDF for Java 20.2
kashifiqb Feb 21, 2020
a24119c
added workflow, added Docs
valeriy-ten-aspose Aug 11, 2020
401daa0
updated Docs
valeriy-ten-aspose Aug 11, 2020
84e61a8
updated Docs, updated workflow
valeriy-ten-aspose Aug 11, 2020
0ab84ce
Merge pull request #45 from aspose-pdf/develop
ValeriyTen Aug 11, 2020
28a179b
updated Docs
valeriy-ten-aspose Aug 11, 2020
4b0408b
udpdated Docs
valeriy-ten-aspose Aug 11, 2020
3a0e378
Updated Doc links.
saudaspose Aug 13, 2020
5b39b69
Review and update release notes 2017- 2020 and add 20-7, 20-5, 20-6.
AnHolub Aug 14, 2020
53d0d99
Minor fix
AnHolub Aug 14, 2020
7f751b4
Restored missing release notes
Aug 15, 2020
ab665de
Fix bugs, update release notes 2016-2019
AnHolub Aug 17, 2020
f00e81e
Merge branch 'master' into develop
AnHolub Aug 17, 2020
ce8fd92
Added release notes for Aspose.PDF for Java 20.8
kashifiqb Aug 19, 2020
651d1ab
Added content as per the Standard Template.
saudaspose Aug 21, 2020
c6718f3
deleted Docs, workflow
valeriy-ten-aspose Sep 6, 2020
5619428
Updated Examples for version 20.10
muhammadumargroupdocs Oct 27, 2020
0f1f3cc
Fixed Eclipse plugin install issues
ali-salman Nov 2, 2020
8d0bb1b
Merge branch 'master' of https://github.com/aspose-pdf/Aspose.PDF-for…
ali-salman Nov 2, 2020
99fed7b
Update README.md
rizwanniazigroupdocs Feb 10, 2021
d0ee7f4
uncommented the code page.accept(selector);
asadalikhan90 Feb 15, 2021
38e33f8
Bump commons-io from 2.5 to 2.7 in /Examples
dependabot[bot] Apr 26, 2021
0e4ec18
Update README.md
farooqsheikhpk Jun 23, 2021
5582ae9
- update examples for aspose-pdf-22.5
marat-khazin-aspose Jun 6, 2022
4189e16
normalize code
marat-khazin-aspose Jun 6, 2022
6bb409e
Merge pull request #53 from aspose-pdf/actualize-code-for-version-22.5
marat-khazin-aspose Jun 7, 2022
dcd5ab5
Merge pull request #49 from aspose-pdf/dependabot/maven/Examples/comm…
marat-khazin-aspose Jun 7, 2022
4af8b74
optimize examples
marat-khazin-aspose Jun 7, 2022
2348439
Merge pull request #54 from aspose-pdf/actualize-code-for-version-22.5
marat-khazin-aspose Jun 7, 2022
271bdef
Fix compile time errors.
marat-khazin-aspose Jan 16, 2023
b6de4ff
Fix example for ReplaceOnlyFirstOccurrenceOfThePhrase
marat-khazin-aspose Jan 16, 2023
a76d404
update testdata file
marat-khazin-aspose Jan 26, 2023
b3548f3
Update LICENSE
andreynekrasov0911 Feb 14, 2025
9de845b
Fix examples in AddingJavaScriptDOM class
marat-khazin-aspose Aug 26, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ Out/
Out*/
*.lic
Data/*Out*
*out*
5,275 changes: 5,275 additions & 0 deletions Artifacts/Aspose.Pdf.xsd

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion Examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,13 @@ This package contains Java Example Project for [Aspose.PDF for Java](http://prod

## How to Run the Examples?

All the examples are arranged in src folder and any modern IDE like IntelliJ IDEA, Eclipse, Netbeans etc can import the source folder easily. Visit our [documentation website](https://docs.aspose.com/display/pdfjava/How+to+Run+the+Examples) for more details.
All the examples are arranged in src folder and any modern IDE like IntelliJ IDEA, Eclipse, Netbeans etc can import the source folder easily. Visit our [documentation website](https://docs.aspose.com/display/pdfjava/How+to+Run+the+Examples) for more details.

## Install and Configure Maven

You may find following resources helpful:

1. Learn how to <a href="http://www.tutorialspoint.com/maven/maven_environment_setup.htm">install and configure</a> Maven - Environment Setup
2. Maven <a href="http://www.tutorialspoint.com/maven/maven_netbeans.htm">support</a> for NetBeans
3. Maven <a href="http://www.tutorialspoint.com/maven/maven_intellij_idea.htm">support</a> for IntelliJ IDEA
4. Maven <a href="http://www.tutorialspoint.com/maven/maven_eclispe_ide.htm">support</a> for Eclipse IDE
25 changes: 5 additions & 20 deletions Examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.aspose</groupId>
<artifactId>pdf-java-examples</artifactId>
<version>1.0-SNAPSHOT</version>
<version>1.1-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
Expand All @@ -13,36 +13,21 @@
<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>http://artifact.aspose.com/repo/</url>
</repository>
<repository>
<id>com.springsource.repository.bundles.external</id>
<name>SpringSource Enterprise Bundle Repository - External Bundle Releases</name>
<url>http://repository.springsource.com/maven/bundles/external</url>
<url>https://releases.aspose.com/java/repo/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-pdf</artifactId>
<version>18.4</version>
</dependency>
<dependency>
<groupId>javax.media.jai</groupId>
<artifactId>com.springsource.javax.media.jai.core</artifactId>
<version>1.1.3</version>
<version>22.12</version>
</dependency>

<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-words</artifactId>
<version>18.5</version>
<version>22.12</version>
<classifier>jdk16</classifier>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -1,57 +1,71 @@
package com.aspose.pdf.examples.AsposePdfExamples.Annotations;

import com.aspose.pdf.AnnotationFlags;
import com.aspose.pdf.AnnotationState;
import com.aspose.pdf.Border;
import com.aspose.pdf.Dash;
import com.aspose.pdf.DefaultAppearance;
import com.aspose.pdf.Document;
import com.aspose.pdf.FreeTextAnnotation;
import com.aspose.pdf.Rectangle;
import com.aspose.pdf.TextAnnotation;
import com.aspose.pdf.TextIcon;
import com.aspose.pdf.examples.Utils;

public class AddAnnotationToPDF {

public static void main(String[] args) {
addAnnotationToPDF();
invisibleAnnotation();
}

public static void addAnnotationToPDF() {
// Open the source PDF document
Document pdfDocument = new Document("input.pdf");
// Create annotation
TextAnnotation textAnnotation = new TextAnnotation(pdfDocument.getPages().get_Item(1), new Rectangle(200, 400, 400, 600));
// Set annotation title
textAnnotation.setTitle("Sample Annotation Title");
// Set annotation subject
textAnnotation.setSubject("Sample Subject");
textAnnotation.setState(AnnotationState.Accepted);
// Specify the annotation contents
textAnnotation.setContents("Sample contents for the annotation");
textAnnotation.setOpen(true);
textAnnotation.setIcon(TextIcon.Key);
Border border = new Border(textAnnotation);
border.setWidth(5);
border.setDash(new Dash(1, 1));
textAnnotation.setBorder(border);
textAnnotation.setRect(new Rectangle(200, 400, 400, 600));
// Add annotation in the annotations collection of the page
pdfDocument.getPages().get_Item(1).getAnnotations().add(textAnnotation);
// Save the output file
pdfDocument.save("output.pdf");
}

public static void invisibleAnnotation() {
Document doc = new Document();
doc.getPages().add();
FreeTextAnnotation annotation = new FreeTextAnnotation(doc.getPages().get_Item(1), new Rectangle(50, 600, 250, 650), new DefaultAppearance("Helvetica", 16, java.awt.Color.RED));
annotation.setContents("ABCDEFG");
annotation.getCharacteristics().setBorder(java.awt.Color.RED);
annotation.setFlags(AnnotationFlags.Print | AnnotationFlags.NoView);
doc.getPages().get_Item(1).getAnnotations().add(annotation);
doc.save("Invisible_Annotation.pdf");
}
public static void main(String[] args) {
runExamples();
}

public static void runExamples() {
// The paths to resources and output directories.
String testID = "com/aspose/pdf/examples/AsposePdf/Annotations/addannotation/";
String dataDir = Utils.getDataDir(testID);
String outputDir = Utils.getOutDir(testID);

System.out.println("============================");
System.out.println("Example addAnnotationToPDF start");
addAnnotationToPDF(dataDir, outputDir);
System.out.println("Example addAnnotationToPDF end");

System.out.println("============================");
System.out.println("Example invisibleAnnotation start");
invisibleAnnotation(dataDir, outputDir);
System.out.println("Example invisibleAnnotation end");
}

public static void addAnnotationToPDF(String dataDir, String outputDir) {
// Open the source PDF document
com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document(dataDir + "input.pdf");
// Create annotation
com.aspose.pdf.TextAnnotation textAnnotation = new com.aspose.pdf.TextAnnotation(pdfDocument.getPages().get_Item(1), new Rectangle(200, 400, 400, 600));
// Set annotation title
textAnnotation.setTitle("Sample Annotation Title");
// Set annotation subject
textAnnotation.setSubject("Sample Subject");
textAnnotation.setState(com.aspose.pdf.AnnotationState.Accepted);
// Specify the annotation contents
textAnnotation.setContents("Sample contents for the annotation");
textAnnotation.setOpen(true);
textAnnotation.setIcon(TextIcon.Key);
Border border = new Border(textAnnotation);
border.setWidth(5);
border.setDash(new Dash(1, 1));
textAnnotation.setBorder(border);
textAnnotation.setRect(new Rectangle(200, 400, 400, 600));
// Add annotation in the annotations collection of the page
pdfDocument.getPages().get_Item(1).getAnnotations().add(textAnnotation);
// Save the output file
pdfDocument.save(outputDir + "addAnnotationToPDF.pdf");
}

public static void invisibleAnnotation(String dataDir, String outputDir) {
Document doc = new Document();
doc.getPages().add();
FreeTextAnnotation annotation = new FreeTextAnnotation(doc.getPages().get_Item(1), new Rectangle(50, 600, 250, 650), new DefaultAppearance("Helvetica", 16, java.awt.Color.RED));
annotation.setContents("ABCDEFG");
annotation.getCharacteristics().setBorder(java.awt.Color.RED);
annotation.setFlags(com.aspose.pdf.AnnotationFlags.Print | com.aspose.pdf.AnnotationFlags.NoView);
doc.getPages().get_Item(1).getAnnotations().add(annotation);
doc.save(outputDir + "Invisible_Annotation.pdf");
}

}
Original file line number Diff line number Diff line change
@@ -1,16 +1,33 @@
package com.aspose.pdf.examples.AsposePdfExamples.Annotations;

import com.aspose.pdf.Document;
import com.aspose.pdf.examples.Utils;

public class DeleteAllAnnotationsFromPageOfPDFFile {

public static void main(String[] args) {
// Open source PDF document
Document pdfDocument = new Document("input.pdf");
// Delete all annotation
pdfDocument.getPages().get_Item(1).getAnnotations().delete();
// Save the update document
pdfDocument.save("output.pdf");
}
public static void main(String[] args) {
runExamples();
}
public static void runExamples() {

// The paths to resources and output directories.
String testID = "com/aspose/pdf/examples/AsposePdf/Annotations/deleteallannotations/";
String dataDir = Utils.getDataDir(testID);
String outputDir = Utils.getOutDir(testID);

System.out.println("============================");
System.out.println("Example deleteAllAnnotationsFromPageOfPDFFile start");
deleteAllAnnotationsFromPageOfPDFFile(dataDir, outputDir);
System.out.println("Example deleteAllAnnotationsFromPageOfPDFFile end");
}

private static void deleteAllAnnotationsFromPageOfPDFFile(String dataDir, String outputDir) {
// Open source PDF document
Document pdfDocument = new Document(dataDir + "input.pdf");
// Delete all annotation
pdfDocument.getPages().get_Item(1).getAnnotations().delete();
// Save the update document
pdfDocument.save(outputDir + "output.pdf");
}

}
Original file line number Diff line number Diff line change
@@ -1,16 +1,32 @@
package com.aspose.pdf.examples.AsposePdfExamples.Annotations;

import com.aspose.pdf.Document;
import com.aspose.pdf.examples.Utils;

public class DeleteParticularAnnotationFromThePDFFile {

public static void main(String[] args) {
// Open source PDF document
Document pdfDocument = new Document("input.pdf");
// Delete particular annotation
pdfDocument.getPages().get_Item(1).getAnnotations().delete(1);
// Save the update document
pdfDocument.save("output.pdf");
}
public static void main(String[] args) {
runExamples();
}
public static void runExamples() {
// The paths to resources and output directories.
String testID = "com/aspose/pdf/examples/AsposePdf/Annotations/deleteparticularannotation/";
String dataDir = Utils.getDataDir(testID);
String outputDir = Utils.getOutDir(testID);

System.out.println("============================");
System.out.println("Example deleteParticularAnnotationFromThePDFFile start");
deleteParticularAnnotationFromThePDFFile(dataDir, outputDir);
System.out.println("Example deleteParticularAnnotationFromThePDFFile end");
}

private static void deleteParticularAnnotationFromThePDFFile(String dataDir, String outputDir) {
// Open source PDF document
Document pdfDocument = new Document(dataDir + "input.pdf");
// Delete particular annotation
pdfDocument.getPages().get_Item(1).getAnnotations().delete(1);
// Save the update document
pdfDocument.save(outputDir + "output.pdf");
}

}
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
package com.aspose.pdf.examples.AsposePdfExamples.Annotations;

import com.aspose.pdf.Document;
import com.aspose.pdf.examples.Utils;

public class GetAllAnnotationsFromPageInPDF {

public static void main(String[] args) {
// Open source PDF document
Document pdfDocument = new Document("Annotated_output.pdf");
// Loop through all the annotations
for (int Annot_counter = 1; Annot_counter <= pdfDocument.getPages().get_Item(1).getAnnotations().size(); Annot_counter++) {
// Get annotation properties
System.out.printf("Full Name :- " + pdfDocument.getPages().get_Item(Annot_counter).getAnnotations().get_Item(Annot_counter).getFullName());
System.out.printf("Page Number :- " + pdfDocument.getPages().get_Item(Annot_counter).getAnnotations().get_Item(Annot_counter).getPageIndex());
System.out.printf("Contents :- " + pdfDocument.getPages().get_Item(Annot_counter).getAnnotations().get_Item(Annot_counter).getContents());
}
}
public static void main(String[] args) {
runExamples();
}
public static void runExamples() {
// The paths to resources and output directories.
String testID = "com/aspose/pdf/examples/AsposePdf/Annotations/getallannotations/";
String dataDir = Utils.getDataDir(testID);
String outputDir = Utils.getOutDir(testID);

System.out.println("============================");
System.out.println("Example getAllAnnotationsFromPageInPDF start");
getAllAnnotationsFromPageInPDF(dataDir, outputDir);
System.out.println("\r\nExample getAllAnnotationsFromPageInPDF end");
}

private static void getAllAnnotationsFromPageInPDF(String dataDir, String outputDir) {
// Open source PDF document
Document pdfDocument = new Document(dataDir + "input.pdf");
// Loop through all the annotations
for (int Annot_counter = 1; Annot_counter <= pdfDocument.getPages().get_Item(1).getAnnotations().size(); Annot_counter++) {
// Get annotation properties
System.out.printf("Full Name :- " + pdfDocument.getPages().get_Item(Annot_counter).getAnnotations().get_Item(Annot_counter).getFullName());
System.out.printf("Page Number :- " + pdfDocument.getPages().get_Item(Annot_counter).getAnnotations().get_Item(Annot_counter).getPageIndex());
System.out.printf("Contents :- " + pdfDocument.getPages().get_Item(Annot_counter).getAnnotations().get_Item(Annot_counter).getContents());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,34 @@

import com.aspose.pdf.Document;
import com.aspose.pdf.TextAnnotation;
import com.aspose.pdf.examples.Utils;

public class GetParticularAnnotationFromPDF {

public static void main(String[] args) {
// Open source PDF document
Document pdfDocument = new Document("input.pdf");
// Get particular annotation
TextAnnotation textAnnotation = (TextAnnotation) pdfDocument.getPages().get_Item(1).getAnnotations().get_Item(1);
// Get annotation properties
System.out.printf("Title :- " + textAnnotation.getTitle());
System.out.printf("Subject :- " + textAnnotation.getSubject());
System.out.printf("Contents :- " + textAnnotation.getContents());
}
public static void main(String[] args) {
runExamples();
}
public static void runExamples() {
// The paths to resources and output directories.
String testID = "com/aspose/pdf/examples/AsposePdf/Annotations/getparticularannotation/";
String dataDir = Utils.getDataDir(testID);
String outputDir = Utils.getOutDir(testID);

System.out.println("============================");
System.out.println("Example getParticularAnnotationFromPDF start");
getParticularAnnotationFromPDF(dataDir, outputDir);
System.out.println("\r\nExample getParticularAnnotationFromPDF end");
}

private static void getParticularAnnotationFromPDF(String dataDir, String outputDir) {
// Open source PDF document
Document pdfDocument = new Document(dataDir + "input.pdf");
// Get particular annotation
TextAnnotation textAnnotation = (TextAnnotation) pdfDocument.getPages().get_Item(1).getAnnotations().get_Item(1);
// Get annotation properties
System.out.printf("Title :- " + textAnnotation.getTitle());
System.out.printf("Subject :- " + textAnnotation.getSubject());
System.out.printf("Contents :- " + textAnnotation.getContents());
}

}
Loading