Skip to content

Commit dfdfbf1

Browse files
committed
Autoport ApiExamples 24.09
1 parent 254bb56 commit dfdfbf1

11 files changed

+201
-21
lines changed

Examples/ApiExamples/JavaPorting/ExCharts.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,8 +1200,6 @@ public void axisDisplayUnit() throws Exception
12001200
//ExFor:ChartAxis.MajorUnitScale
12011201
//ExFor:ChartAxis.MinorUnitIsAuto
12021202
//ExFor:ChartAxis.MinorUnitScale
1203-
//ExFor:ChartAxis.TickLabelSpacing
1204-
//ExFor:ChartAxis.TickLabelAlignment
12051203
//ExFor:AxisDisplayUnit
12061204
//ExFor:AxisDisplayUnit.CustomUnit
12071205
//ExFor:AxisDisplayUnit.Unit

Examples/ApiExamples/JavaPorting/ExComment.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,18 +124,18 @@ public void removeCommentReplies() throws Exception
124124
comment.addReplyInternal("Joe Bloggs", "J.B.", new Date(), "New reply");
125125
comment.addReplyInternal("Joe Bloggs", "J.B.", new Date(), "Another reply");
126126

127-
Assert.AreEqual(2, comment.getReplies().Count());
127+
Assert.assertEquals(2, comment.getReplies().getCount());
128128

129129
// Below are two ways of removing replies from a comment.
130130
// 1 - Use the "RemoveReply" method to remove replies from a comment individually:
131131
comment.removeReply(comment.getReplies().get(0));
132132

133-
Assert.AreEqual(1, comment.getReplies().Count());
133+
Assert.assertEquals(1, comment.getReplies().getCount());
134134

135135
// 2 - Use the "RemoveAllReplies" method to remove all replies from a comment at once:
136136
comment.removeAllReplies();
137137

138-
Assert.AreEqual(0, comment.getReplies().Count());
138+
Assert.assertEquals(0, comment.getReplies().getCount());
139139
//ExEnd
140140
}
141141

Examples/ApiExamples/JavaPorting/ExDigitalSignatureUtil.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.aspose.words.LoadOptions;
2626
import com.aspose.words.Document;
2727
import com.aspose.words.IncorrectPasswordException;
28+
import com.aspose.words.XmlDsigLevel;
2829

2930

3031
@Test
@@ -253,4 +254,21 @@ public void noCertificateForSign() throws Exception
253254
Assert.<NullPointerException>Throws(
254255
() => DigitalSignatureUtil.sign(doc.getOriginalFileName(), outputFileName, null, signOptions));
255256
}
257+
258+
@Test
259+
public void xmlDsig() throws Exception
260+
{
261+
//ExStart:XmlDsig
262+
//GistId:e06aa7a168b57907a5598e823a22bf0a
263+
//ExFor:SignOptions.XmlDsigLevel
264+
//ExFor:XmlDsigLevel
265+
//ExSummary:Shows how to sign document based on XML-DSig standard.
266+
CertificateHolder certificateHolder = CertificateHolder.create(getMyDir() + "morzal.pfx", "aw");
267+
SignOptions signOptions = new SignOptions(); { signOptions.setXmlDsigLevel(XmlDsigLevel.X_AD_ES_EPES); }
268+
269+
String inputFileName = getMyDir() + "Document.docx";
270+
String outputFileName = getArtifactsDir() + "DigitalSignatureUtil.XmlDsig.docx";
271+
DigitalSignatureUtil.sign(inputFileName, outputFileName, certificateHolder, signOptions);
272+
//ExEnd:XmlDsig
273+
}
256274
}

Examples/ApiExamples/JavaPorting/ExHtmlSaveOptions.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -535,8 +535,8 @@ public void cssClassNamesPrefix() throws Exception
535535

536536
outDocContents = File.readAllText(getArtifactsDir() + "HtmlSaveOptions.CssClassNamePrefix.css");
537537

538-
Assert.assertTrue(outDocContents.contains(".myprefix-Footer { margin-bottom:0pt; line-height:normal; font-family:Arial; font-size:11pt; -aw-style-name:footer }\r\n" +
539-
".myprefix-Header { margin-bottom:0pt; line-height:normal; font-family:Arial; font-size:11pt; -aw-style-name:header }\r\n"));
538+
Assert.assertTrue(outDocContents.contains(".myprefix-Footer { margin-bottom:0pt; line-height:normal; font-family:Arial; font-size:11pt; -aw-style-name:footer }"));
539+
Assert.assertTrue(outDocContents.contains(".myprefix-Header { margin-bottom:0pt; line-height:normal; font-family:Arial; font-size:11pt; -aw-style-name:header }"));
540540
//ExEnd
541541
}
542542

Examples/ApiExamples/JavaPorting/ExInlineStory.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
import java.util.Date;
3333
import com.aspose.words.SaveFormat;
3434
import com.aspose.words.ShapeType;
35+
import com.aspose.words.FootnoteSeparator;
36+
import com.aspose.words.FootnoteSeparatorType;
37+
import com.aspose.words.ParagraphAlignment;
3538
import org.testng.annotations.DataProvider;
3639

3740

@@ -679,5 +682,41 @@ public void updateActualReferenceMarks() throws Exception
679682
Assert.assertEquals("1", footnote.getActualReferenceMark());
680683
//ExEnd:UpdateActualReferenceMarks
681684
}
685+
686+
@Test
687+
public void endnoteSeparator() throws Exception
688+
{
689+
//ExStart:EndnoteSeparator
690+
//GistId:e06aa7a168b57907a5598e823a22bf0a
691+
//ExFor:DocumentBase.FootnoteSeparators
692+
//ExFor:FootnoteSeparatorType
693+
//ExSummary:Shows how to remove endnote separator.
694+
Document doc = new Document(getMyDir() + "Footnotes and endnotes.docx");
695+
696+
FootnoteSeparator endnoteSeparator = doc.getFootnoteSeparators().getByFootnoteSeparatorType(FootnoteSeparatorType.ENDNOTE_SEPARATOR);
697+
// Remove endnote separator.
698+
endnoteSeparator.getFirstParagraph().getFirstChild().remove();
699+
//ExEnd:EndnoteSeparator
700+
701+
doc.save(getArtifactsDir() + "InlineStory.EndnoteSeparator.docx");
702+
}
703+
704+
@Test
705+
public void footnoteSeparator() throws Exception
706+
{
707+
//ExStart:FootnoteSeparator
708+
//GistId:e06aa7a168b57907a5598e823a22bf0a
709+
//ExFor:DocumentBase.FootnoteSeparators
710+
//ExFor:FootnoteSeparatorType
711+
//ExSummary:Shows how to manage footnote separator format.
712+
Document doc = new Document(getMyDir() + "Footnotes and endnotes.docx");
713+
714+
FootnoteSeparator footnoteSeparator = doc.getFootnoteSeparators().getByFootnoteSeparatorType(FootnoteSeparatorType.FOOTNOTE_SEPARATOR);
715+
// Align footnote separator.
716+
footnoteSeparator.getFirstParagraph().getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
717+
//ExEnd:FootnoteSeparator
718+
719+
doc.save(getArtifactsDir() + "InlineStory.FootnoteSeparator.docx");
720+
}
682721
}
683722

Examples/ApiExamples/JavaPorting/ExLowCode.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,15 @@ public void convertStream() throws Exception
145145
FileStream streamOut = new FileStream(getArtifactsDir() + "LowCode.ConvertStream.SaveFormat.docx", FileMode.CREATE, FileAccess.READ_WRITE);
146146
try /*JAVA: was using*/
147147
{
148-
Converter.convert(streamIn, streamOut, SaveFormat.DOCX);
148+
Converter.convertInternal(streamIn, streamOut, SaveFormat.DOCX);
149149
}
150150
finally { if (streamOut != null) streamOut.close(); }
151151

152152
OoxmlSaveOptions saveOptions = new OoxmlSaveOptions(); { saveOptions.setPassword("Aspose.Words"); }
153153
FileStream streamOut1 = new FileStream(getArtifactsDir() + "LowCode.ConvertStream.SaveOptions.docx", FileMode.CREATE, FileAccess.READ_WRITE);
154154
try /*JAVA: was using*/
155155
{
156-
Converter.convert(streamIn, streamOut1, saveOptions);
156+
Converter.convertInternal(streamIn, streamOut1, saveOptions);
157157
}
158158
finally { if (streamOut1 != null) streamOut1.close(); }
159159
}
@@ -190,15 +190,15 @@ public void convertToImagesStream() throws Exception
190190
//ExFor:Converter.ConvertToImages(Document, SaveFormat)
191191
//ExFor:Converter.ConvertToImages(Document, ImageSaveOptions)
192192
//ExSummary:Shows how to convert document to images stream.
193-
Stream[] streams = Converter.convertToImages(getMyDir() + "Big document.docx", SaveFormat.PNG);
193+
Stream[] streams = Converter.convertToImagesInternal(getMyDir() + "Big document.docx", SaveFormat.PNG);
194194

195195
ImageSaveOptions imageSaveOptions = new ImageSaveOptions(SaveFormat.PNG);
196196
imageSaveOptions.setPageSet(new PageSet(1));
197-
streams = Converter.convertToImages(getMyDir() + "Big document.docx", imageSaveOptions);
197+
streams = Converter.convertToImagesInternal(getMyDir() + "Big document.docx", imageSaveOptions);
198198

199-
streams = Converter.convertToImages(new Document(getMyDir() + "Big document.docx"), SaveFormat.PNG);
199+
streams = Converter.convertToImagesInternal(new Document(getMyDir() + "Big document.docx"), SaveFormat.PNG);
200200

201-
streams = Converter.convertToImages(new Document(getMyDir() + "Big document.docx"), imageSaveOptions);
201+
streams = Converter.convertToImagesInternal(new Document(getMyDir() + "Big document.docx"), imageSaveOptions);
202202
//ExEnd:ConvertToImagesStream
203203
}
204204

@@ -213,11 +213,11 @@ public void convertToImagesFromStream() throws Exception
213213
FileStream streamIn = new FileStream(getMyDir() + "Big document.docx", FileMode.OPEN, FileAccess.READ);
214214
try /*JAVA: was using*/
215215
{
216-
Stream[] streams = Converter.convertToImages(streamIn, SaveFormat.JPEG);
216+
Stream[] streams = Converter.convertToImagesInternal(streamIn, SaveFormat.JPEG);
217217

218218
ImageSaveOptions imageSaveOptions = new ImageSaveOptions(SaveFormat.PNG);
219219
imageSaveOptions.setPageSet(new PageSet(1));
220-
streams = Converter.convertToImages(streamIn, imageSaveOptions);
220+
streams = Converter.convertToImagesInternal(streamIn, imageSaveOptions);
221221
}
222222
finally { if (streamIn != null) streamIn.close(); }
223223
//ExEnd:ConvertToImagesFromStream

Examples/ApiExamples/JavaPorting/ExMarkdownLoadOptions.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
import com.aspose.words.MarkdownLoadOptions;
99
import com.aspose.words.Document;
1010
import org.testng.Assert;
11+
import com.aspose.words.Paragraph;
12+
import com.aspose.words.NodeType;
13+
import com.aspose.words.Underline;
1114

1215

1316
@Test
@@ -34,5 +37,31 @@ public void preserveEmptyLines() throws Exception
3437
finally { if (stream != null) stream.close(); }
3538
//ExEnd:PreserveEmptyLines
3639
}
40+
41+
@Test
42+
public void importUnderlineFormatting() throws Exception
43+
{
44+
//ExStart:ImportUnderlineFormatting
45+
//GistId:e06aa7a168b57907a5598e823a22bf0a
46+
//ExFor:MarkdownLoadOptions.ImportUnderlineFormatting
47+
//ExSummary:Shows how to recognize plus characters "++" as underline text formatting.
48+
MemoryStream stream = new MemoryStream(Encoding.getASCII().getBytes("++12 and B++"));
49+
try /*JAVA: was using*/
50+
{
51+
MarkdownLoadOptions loadOptions = new MarkdownLoadOptions(); { loadOptions.setImportUnderlineFormatting(true); }
52+
Document doc = new Document(stream, loadOptions);
53+
54+
Paragraph para = (Paragraph)doc.getChild(NodeType.PARAGRAPH, 0, true);
55+
Assert.assertEquals(Underline.SINGLE, para.getRuns().get(0).getFont().getUnderline());
56+
57+
loadOptions = new MarkdownLoadOptions(); { loadOptions.setImportUnderlineFormatting(false); }
58+
doc = new Document(stream, loadOptions);
59+
60+
para = (Paragraph)doc.getChild(NodeType.PARAGRAPH, 0, true);
61+
Assert.assertEquals(Underline.NONE, para.getRuns().get(0).getFont().getUnderline());
62+
}
63+
finally { if (stream != null) stream.close(); }
64+
//ExEnd:ImportUnderlineFormatting
65+
}
3766
}
3867

Examples/ApiExamples/JavaPorting/ExShape.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3548,5 +3548,42 @@ public void checkedCheckBox() throws Exception
35483548
Assert.assertEquals(Forms2OleControlType.CHECK_BOX, checkBoxControl.getType());
35493549
//ExEnd:CheckedCheckBox
35503550
}
3551+
3552+
@Test
3553+
public void insertGroupShape() throws Exception
3554+
{
3555+
//ExStart:InsertGroupShape
3556+
//GistId:e06aa7a168b57907a5598e823a22bf0a
3557+
//ExFor:DocumentBuilder.InsertGroupShape(double, double, double, double, Shape[])
3558+
//ExFor:DocumentBuilder.InsertGroupShape(Shape[])
3559+
//ExSummary:Shows how to insert DML group shape.
3560+
Document doc = new Document();
3561+
DocumentBuilder builder = new DocumentBuilder(doc);
3562+
3563+
Shape shape1 = builder.insertShape(ShapeType.RECTANGLE, 200.0, 250.0);
3564+
shape1.setLeft(20.0);
3565+
shape1.setTop(20.0);
3566+
shape1.getStroke().setColor(Color.RED);
3567+
3568+
Shape shape2 = builder.insertShape(ShapeType.ELLIPSE, 150.0, 200.0);
3569+
shape2.setLeft(40.0);
3570+
shape2.setTop(50.0);
3571+
shape2.getStroke().setColor(msColor.getGreen());
3572+
3573+
// Dimensions for the new GroupShape node.
3574+
double left = 10.0;
3575+
double top = 10.0;
3576+
double width = 200.0;
3577+
double height = 300.0;
3578+
// Insert GroupShape node for the specified size which is inserted into the specified position.
3579+
GroupShape groupShape1 = builder.insertGroupShape(left, top, width, height, new Shape[] { shape1, shape2 });
3580+
3581+
// Insert GroupShape node which position and dimension will be calculated automatically.
3582+
Shape shape3 = (Shape)shape1.deepClone(true);
3583+
GroupShape groupShape2 = builder.insertGroupShape(shape3);
3584+
3585+
doc.save(getArtifactsDir() + "Shape.InsertGroupShape.docx");
3586+
//ExEnd:InsertGroupShape
3587+
}
35513588
}
35523589

Examples/ApiExamples/JavaPorting/ExStructuredDocumentTag.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,5 +1417,27 @@ public void appearance() throws Exception
14171417
tag.setAppearance(SdtAppearance.TAGS);
14181418
//ExEnd:Appearance
14191419
}
1420+
1421+
@Test
1422+
public void insertStructuredDocumentTag() throws Exception
1423+
{
1424+
//ExStart:InsertStructuredDocumentTag
1425+
//GistId:e06aa7a168b57907a5598e823a22bf0a
1426+
//ExFor:DocumentBuilder.InsertStructuredDocumentTag(SdtType)
1427+
//ExSummary:Shows how to simply insert structured document tag.
1428+
Document doc = new Document(getMyDir() + "Rendering.docx");
1429+
DocumentBuilder builder = new DocumentBuilder(doc);
1430+
1431+
builder.moveTo(doc.getFirstSection().getBody().getParagraphs().get(3));
1432+
// Note, that only following StructuredDocumentTag types are allowed for insertion:
1433+
// SdtType.PlainText, SdtType.RichText, SdtType.Checkbox, SdtType.DropDownList,
1434+
// SdtType.ComboBox, SdtType.Picture, SdtType.Date.
1435+
// Markup level of inserted StructuredDocumentTag will be detected automatically and depends on position being inserted at.
1436+
// Added StructuredDocumentTag will inherit paragraph and font formatting from cursor position.
1437+
StructuredDocumentTag sdtPlain = builder.insertStructuredDocumentTag(SdtType.PLAIN_TEXT);
1438+
1439+
doc.save(getArtifactsDir() + "StructuredDocumentTag.InsertStructuredDocumentTag.docx");
1440+
//ExEnd:InsertStructuredDocumentTag
1441+
}
14201442
}
14211443

Examples/ApiExamples/JavaPorting/ExTable.java

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
import com.aspose.words.TabStop;
6666
import com.aspose.words.TabAlignment;
6767
import com.aspose.words.TabLeader;
68+
import com.aspose.words.DocumentBuilderOptions;
6869
import org.testng.annotations.DataProvider;
6970
import com.aspose.words.ref.RefInt;
7071

@@ -1797,10 +1798,10 @@ public void convertWithParagraphMark() throws Exception
17971798

17981799
// Replace the table with the new paragraph
17991800
convertTable(table);
1800-
1801+
// Remove table after convertion.
18011802
table.remove();
18021803

1803-
doc.save(getArtifactsDir() + "output.docx");
1804+
doc.save(getArtifactsDir() + "Table.ConvertWithParagraphMark.docx");
18041805
}
18051806

18061807
/// <summary>
@@ -1991,4 +1992,38 @@ private Cell calculateColSpan(Cell cell, /*out*/RefInt colSpan)
19911992
}
19921993
return cell;
19931994
}
1995+
1996+
@Test
1997+
public void contextTableFormatting() throws Exception
1998+
{
1999+
//ExStart:ContextTableFormatting
2000+
//GistId:e06aa7a168b57907a5598e823a22bf0a
2001+
//ExFor:DocumentBuilderOptions
2002+
//ExFor:DocumentBuilderOptions.ContextTableFormatting
2003+
//ExSummary:Shows how to ignore table formatting for content after.
2004+
Document doc = new Document();
2005+
DocumentBuilderOptions builderOptions = new DocumentBuilderOptions();
2006+
builderOptions.setContextTableFormatting(true);
2007+
DocumentBuilder builder = new DocumentBuilder(doc, builderOptions);
2008+
2009+
// Adds content before the table.
2010+
// Default font size is 12.
2011+
builder.writeln("Font size 12 here.");
2012+
builder.startTable();
2013+
builder.insertCell();
2014+
// Changes the font size inside the table.
2015+
builder.getFont().setSize(5.0);
2016+
builder.write("Font size 5 here");
2017+
builder.insertCell();
2018+
builder.write("Font size 5 here");
2019+
builder.endRow();
2020+
builder.endTable();
2021+
2022+
// If ContextTableFormatting is true, then table formatting isn't applied to the content after.
2023+
// If ContextTableFormatting is false, then table formatting is applied to the content after.
2024+
builder.writeln("Font size 12 here.");
2025+
2026+
doc.save(getArtifactsDir() + "Table.ContextTableFormatting.docx");
2027+
//ExEnd:ContextTableFormatting
2028+
}
19942029
}

Examples/ApiExamples/JavaPorting/ExXpsSaveOptions.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
import com.aspose.words.BreakType;
2323
import com.aspose.words.PageSet;
2424
import com.aspose.words.CertificateHolder;
25-
import com.aspose.words.DigitalSignatureDetails;
2625
import com.aspose.words.SignOptions;
2726
import java.util.Date;
2827
import com.aspose.ms.System.DateTime;
28+
import com.aspose.words.DigitalSignatureDetails;
2929
import org.testng.annotations.DataProvider;
3030

3131

@@ -204,9 +204,11 @@ public void xpsDigitalSignature() throws Exception
204204
Document doc = new Document(getMyDir() + "Document.docx");
205205

206206
CertificateHolder certificateHolder = CertificateHolder.create(getMyDir() + "morzal.pfx", "aw");
207-
DigitalSignatureDetails digitalSignatureDetails = new DigitalSignatureDetails(
208-
certificateHolder,
209-
new SignOptions(); { digitalSignatureDetails.setComments("Some comments"); digitalSignatureDetails.setSignTime(new Date()); });
207+
SignOptions options = new SignOptions();
208+
options.setSignTimeInternal(new Date());
209+
options.setComments("Some comments");
210+
211+
DigitalSignatureDetails digitalSignatureDetails = new DigitalSignatureDetails(certificateHolder, options);
210212

211213
XpsSaveOptions saveOptions = new XpsSaveOptions();
212214
saveOptions.setDigitalSignatureDetails(digitalSignatureDetails);

0 commit comments

Comments
 (0)