Skip to content

Commit 5afdac4

Browse files
v29.1.33
1 parent 1ef3e3c commit 5afdac4

File tree

126 files changed

+53708
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+53708
-0
lines changed

README.md

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Syncfusion Java Samples
2+
3+
This repository contains demos of Syncfusion Java controls. This is the best place to check our controls to get more insight about the usage of APIs.
4+
5+
This section guides to use the Syncfusion Java samples in your application.
6+
7+
* [Requirements to run the demo](#requirements-to-run-the-demo)
8+
* [How to run the samples](#how-to-run-the-samples)
9+
* [License](#license)
10+
* [Controls Catalog](#controls-catalog)
11+
* [Support and Feedback](#support-and-feedback)
12+
13+
## <a name="requirements-to-run-the-demo"></a>Requirements to run the demo ##
14+
15+
* The samples require Java SE 8.0 (1.8) or above versions to be installed at your end.
16+
* Get the dependent jar files to run the samples by installing [file formats controls](https://www.syncfusion.com/sales/products/fileformats?utm_source=github&utm_medium=listing&utm_campaign=java-demos#). You can find the required jars in the build installed location `$system drive:\Program Files\Syncfusion\Essential Studio\`.
17+
18+
## <a name="how-to-run-the-samples"></a>How to run the samples ##
19+
20+
1. Clone this repository.
21+
2. Open the command prompt and navigate to the samples root directory.
22+
3. Set the Java path using below command
23+
24+
*Syntax:* `set path=<jdk_installed_location>`
25+
26+
*Example:* `set path=C:\Program Files\Java\jdk-12.0.1\bin`
27+
28+
4. Compile the sample with the dependent jars file using below command
29+
30+
*Syntax:* `javac -cp “<jar_file1_location>;.;”<jar_file2_location>” sampleFolder/*.java`
31+
32+
*Example:* `javac -cp "D:\java-demos\Jarfiles\syncfusion-docio-18.3.0.35.jar";.;"D:\java-demos \Jarfiles\syncfusion-javahelper-18.3.0.35.jar" employeereport/EmployeeReport.java`
33+
34+
5. Then, run the sample using below command
35+
36+
*Syntax:* `java -cp “<jar_file1_location>;.;”<jar_file2_location>” sampleFolder/*.java`
37+
38+
*Example:* `java -cp "D:\java-demos\Jarfiles\syncfusion-docio-18.3.0.35.jar";.;"D:\java-demos\Jarfiles\syncfusion-javahelper-18.3.0.35.jar" employeereport/EmployeeReport.java`
39+
40+
41+
## <a name="license"></a>License ##
42+
43+
Syncfusion has no liability for any damage or consequence that may arise by the use or viewing of the samples. The samples are for demonstrative purposes and if you choose to use or access the samples you agree to not hold Syncfusion liable, in any form, for any damage that is related to use, accessing or otherwise viewing the samples. By accessing, viewing, or otherwise seeing the samples you acknowledge and agree Syncfusion’s samples will not allow you to seek injunctive relief in any form for any claim related to the sample. If you do not agree to this, do not view, access, utilize or otherwise do anything with Syncfusion’s samples.
44+
45+
## <a name="controls-catalog"></a>Controls Catalog ##
46+
**File Formats**
47+
* <a href="docio">Word library<a>
48+
49+
## <a name="support-and-feedback"></a>Support and feedback ##
50+
51+
* For queries, contact our  [Syncfusion support team](https://www.syncfusion.com/support/directtrac/incidents/newincident?utm_source=github&utm_medium=listing&utm_campaign=java-demos#) or post the queries through [community forums](https://www.syncfusion.com/forums?utm_source=github&utm_medium=listing&utm_campaign=java-demos#).
52+
53+
* To renew the subscription, click [here](https://www.syncfusion.com/sales/products?utm_source=github&utm_medium=listing&utm_campaign=java-demos#) or contact our sales team at [[email protected]](mailto:[email protected]#).
+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package advancedreplace;
2+
3+
import java.io.File;
4+
import java.util.regex.Pattern;
5+
6+
import com.syncfusion.docio.*;
7+
import com.syncfusion.javahelper.system.StringSupport;
8+
import com.syncfusion.javahelper.system.text.regularExpressions.MatchSupport;
9+
10+
public class AdvancedReplace {
11+
public static void main(String[] args) throws Exception {
12+
13+
// Creates a new Word document.
14+
WordDocument docSource1 = new WordDocument();
15+
WordDocument docSource2 = new WordDocument();
16+
WordDocument docMaster = new WordDocument();
17+
// Loads the template Word document.
18+
docSource1.open(getDataDir("SourceTemplate1.docx"),FormatType.Docx);
19+
20+
docSource2.open(getDataDir("SourceTemplate2.docx"),FormatType.Docx);
21+
22+
docMaster.open(getDataDir("MasterTemplate.docx"),FormatType.Docx);
23+
// Search for a string and store in TextSelection
24+
// The TextSelection copies a text segment with formatting.
25+
TextSelection selection1 = docSource1.find("PlaceHolder text is replaced with this formatted animated text",false,false);
26+
// Get the text segment to replace the text across multiple paragraphs.
27+
TextBodyPart replacePart = new TextBodyPart(docSource2);
28+
for(Object bodyItem_tempObj : docSource2.getLastSection().getBody().getChildEntities())
29+
{
30+
TextBodyItem bodyItem = (TextBodyItem)bodyItem_tempObj;
31+
replacePart.getBodyItems().add(bodyItem.clone());
32+
}
33+
// Replacing the placeholder inside Master Template with matches found while
34+
// search the two template documents.
35+
docMaster.replace("PlaceHolder1",selection1,true,true,true);
36+
docMaster.replaceSingleLine((Pattern.compile(MatchSupport.trimPattern("PlaceHolder2Start:Suppliers/Vendors of Northwind." + "Customers of Northwind.Employee details of Northwind traders.The product information.The inventory details.The shippers." + "PO transactions i.e Purchase Order transactions.Sales Order transaction.Inventory transactions.Invoices.PlaceHolder2End"))),replacePart);
37+
// Saves and closes the Word document.
38+
docMaster.save("AdvancedReplace.docx", FormatType.Docx);
39+
docMaster.close();
40+
41+
System.out.println("Word document generated successfully.");
42+
43+
}
44+
45+
/**
46+
* Get the file path
47+
*
48+
* @param path specifies the file path
49+
*/
50+
public static String getDataDir(String path) {
51+
File dir = new File(System.getProperty("user.dir"));
52+
if (!(dir.toString().endsWith("samples")))
53+
dir = dir.getParentFile();
54+
dir = new File(dir, "resources");
55+
dir = new File(dir, path);
56+
if (dir.isDirectory() == false)
57+
dir.mkdir();
58+
return dir.toString();
59+
}
60+
61+
}

docio/autoshapes/AutoShapes.java

+143
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
package autoshapes;
2+
3+
import java.io.*;
4+
import com.syncfusion.docio.*;
5+
import com.syncfusion.javahelper.system.drawing.*;
6+
7+
public class AutoShapes {
8+
public static void main(String[] args) throws Exception {
9+
// Initialize Word document.
10+
WordDocument doc = new WordDocument();
11+
// Ensure Minimum.
12+
doc.ensureMinimal();
13+
// Create AutoShape.
14+
Shape shape = createShape(doc, AutoShapeType.RoundedRectangle, (float) 130, (float) 45, (float) 50, true,
15+
ColorSupport.getBlue(), VerticalAlignment.Middle);
16+
// Add Texbody contents to Shape.
17+
IWParagraph para = addParagraph(shape);
18+
IWTextRange textRange = appendText(para, "Requirement");
19+
shape = createDownArrow(doc, AutoShapeType.DownArrow, (float) 45, (float) 45, (float) 95, true);
20+
shape = createShape(doc, AutoShapeType.RoundedRectangle, (float) 130, (float) 45, (float) 140, true,
21+
ColorSupport.getOrange(), VerticalAlignment.Middle);
22+
// Add Texbody contents to Shape.
23+
para = addParagraph(shape);
24+
textRange = appendText(para, "Design");
25+
shape = createDownArrow(doc, AutoShapeType.DownArrow, (float) 45, (float) 45, (float) 185, true);
26+
shape = createShape(doc, AutoShapeType.RoundedRectangle, (float) 130, (float) 45, (float) 230, true,
27+
ColorSupport.getBlue(), VerticalAlignment.Middle);
28+
// Add Texbody contents to Shape.
29+
para = addParagraph(shape);
30+
textRange = appendText(para, "Execution");
31+
shape = createDownArrow(doc, AutoShapeType.DownArrow, (float) 45, (float) 45, (float) 275, true);
32+
shape = createShape(doc, AutoShapeType.RoundedRectangle, (float) 130, (float) 45, (float) 320, true,
33+
ColorSupport.getViolet(), VerticalAlignment.Middle);
34+
// Add Texbody contents to Shape.
35+
para = addParagraph(shape);
36+
textRange = appendText(para, "Testing");
37+
shape = createDownArrow(doc, AutoShapeType.DownArrow, (float) 45, (float) 45, (float) 365, true);
38+
shape = createShape(doc, AutoShapeType.RoundedRectangle, (float) 130, (float) 45, (float) 410, true,
39+
ColorSupport.getPaleVioletRed(), VerticalAlignment.Middle);
40+
// Add Texbody contents to Shape.
41+
para = addParagraph(shape);
42+
textRange = appendText(para, "Release");
43+
// Save and close the document.
44+
doc.save("Auto Shapes.docx");
45+
doc.close();
46+
System.out.println("Word document generated successfully.");
47+
}
48+
49+
/**
50+
* Create AutoShape.
51+
*
52+
* @param autoShapeType Represents the shape type.
53+
* @param width Represents the width of the shape.
54+
* @param height Represents the height of the shape.
55+
* @param verticalPosition Represents vertical position of the shape.
56+
* @param isAllowOverlap Represents given shape can overlap other shapes.
57+
* @param color Represents color to fill.
58+
* @param verticalAlignment Represents color to fill.
59+
*/
60+
61+
private static Shape createShape(WordDocument doc, AutoShapeType autoShapeType, float width, float height,
62+
float verticalPosition, boolean isAllowOverlap, ColorSupport color, VerticalAlignment verticalAlignment)
63+
throws Exception {
64+
// Append AutoShape.
65+
Shape shape = doc.getLastParagraph().appendShape(autoShapeType, width, height);
66+
// Set horizontal alignment.
67+
shape.setHorizontalAlignment(ShapeHorizontalAlignment.Center);
68+
// Set horizontal origin.
69+
shape.setHorizontalOrigin(HorizontalOrigin.Page);
70+
// Set vertical origin.
71+
shape.setVerticalOrigin(VerticalOrigin.Page);
72+
// Set vertical position.
73+
shape.setVerticalPosition(verticalPosition);
74+
// Set AllowOverlap to true for overlapping shapes.
75+
shape.getWrapFormat().setAllowOverlap(isAllowOverlap);
76+
// Set Fill Color.
77+
shape.getFillFormat().setColor(color);
78+
// Set Content vertical alignment.
79+
shape.getTextFrame().setTextVerticalAlignment(verticalAlignment);
80+
return shape;
81+
}
82+
83+
/**
84+
* Create AutoShape.
85+
*
86+
* @param autoShapeType Represents the shape type.
87+
* @param width Represents the width of the shape.
88+
* @param height Represents the height of the shape.
89+
* @param verticalPosition Represents vertical position of the shape.
90+
* @param isAllowOverlap Represents given shape can overlap other shapes.
91+
*
92+
*/
93+
private static Shape createDownArrow(WordDocument doc, AutoShapeType autoShapeType, float width, float height,
94+
float verticalPosition, boolean isAllowOverlap) throws Exception {
95+
// Append AutoShape.
96+
Shape shape = doc.getLastParagraph().appendShape(autoShapeType, width, height);
97+
// Set horizontal alignment.
98+
shape.setHorizontalAlignment(ShapeHorizontalAlignment.Center);
99+
// Set horizontal origin.
100+
shape.setHorizontalOrigin(HorizontalOrigin.Page);
101+
// Set vertical origin.
102+
shape.setVerticalOrigin(VerticalOrigin.Page);
103+
// Set vertical position.
104+
shape.setVerticalPosition(verticalPosition);
105+
// Set AllowOverlap to true for overlapping shapes.
106+
shape.getWrapFormat().setAllowOverlap(isAllowOverlap);
107+
return shape;
108+
}
109+
110+
/**
111+
*
112+
* Add the paragraph
113+
*
114+
* @param shape Represents the Shape
115+
*
116+
*/
117+
118+
private static IWParagraph addParagraph(Shape shape) throws Exception {
119+
IWParagraph para = shape.getTextBody().addParagraph();
120+
para.getParagraphFormat().setHorizontalAlignment(HorizontalAlignment.Center);
121+
return para;
122+
}
123+
124+
/**
125+
*
126+
* Add texbody contents to Shape.
127+
*
128+
* @param para specifies the paragraph in which the text is appended.
129+
* @param text specifies the textrange to be added
130+
*
131+
*/
132+
private static IWTextRange appendText(IWParagraph para, String text) throws Exception {
133+
// Add text contents to paragraph.
134+
IWTextRange textRange = para.appendText(text);
135+
// Apply the character formats.
136+
WCharacterFormat characterFormat = textRange.getCharacterFormat();
137+
characterFormat.setBold(true);
138+
characterFormat.setTextColor(ColorSupport.getWhite());
139+
characterFormat.setFontSize(12f);
140+
characterFormat.setFontName("Verdana");
141+
return textRange;
142+
}
143+
}

0 commit comments

Comments
 (0)