本文整理汇总了Java中com.aspose.words.Document类的典型用法代码示例。如果您正苦于以下问题:Java Document类的具体用法?Java Document怎么用?Java Document使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Document类属于com.aspose.words包,在下文中一共展示了Document类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: main
import com.aspose.words.Document; //导入依赖的package包/类
public static void main(String[] args) throws Exception
{
String dataPath = "src/asposefeatures/workingwithdocument/movingcursor/data/";
Document doc = new Document(dataPath + "document.doc");
DocumentBuilder builder = new DocumentBuilder(doc);
//Shows how to access the current node in a document builder.
Node curNode = builder.getCurrentNode();
Paragraph curParagraph = builder.getCurrentParagraph();
// Shows how to move a cursor position to a specified node.
builder.moveTo(doc.getFirstSection().getBody().getLastParagraph());
// Shows how to move a cursor position to the beginning or end of a document.
builder.moveToDocumentEnd();
builder.writeln("This is the end of the document.");
builder.moveToDocumentStart();
builder.writeln("This is the beginning of the document.");
doc.save(dataPath + "AsposeMovingCursor.doc");
System.out.println("Done.");
}
开发者ID:asposemarketplace,项目名称:Aspose_for_Apache_POI,代码行数:26,代码来源:AsposeMovingCursor.java
示例2: main
import com.aspose.words.Document; //导入依赖的package包/类
public static void main(String[] args) throws Exception
{
String dataPath = "src/asposefeatures/workingwithdocument/appenddoc/data/";
Document doc1 = new Document(dataPath + "doc1.doc");
Document doc2 = new Document(dataPath + "doc2.doc");
doc1.appendDocument(doc2, ImportFormatMode.KEEP_SOURCE_FORMATTING);
doc1.save(dataPath + "AsposeMerged.doc", SaveFormat.DOC);
}
开发者ID:asposemarketplace,项目名称:Aspose_for_Apache_POI,代码行数:12,代码来源:AsposeAppendDocs.java
示例3: main
import com.aspose.words.Document; //导入依赖的package包/类
public static void main(String[] args) throws Exception
{
Document doc = new Document();
// DocumentBuilder provides members to easily add content to a document.
DocumentBuilder builder = new DocumentBuilder(doc);
// Write a new paragraph in the document with some text as "Sample Content..."
builder.writeln("Aspose Sample Content for Word file.");
// Save the document in DOCX format. The format to save as is inferred from the extension of the file name.
// Aspose.Words supports saving any document in many more formats.
doc.save("data/Aspose_SaveDoc.docx",SaveFormat.DOCX);
System.out.println("Process Completed Successfully");
}
开发者ID:asposemarketplace,项目名称:Aspose_for_Apache_POI,代码行数:17,代码来源:AsposeSaveDocument.java
示例4: main
import com.aspose.words.Document; //导入依赖的package包/类
public static void main(String[] args) throws Exception
{
String dataPath = "src/featurescomparison/workingwithdocuments/mergedocs/data/";
Document doc1 = new Document(dataPath + "doc1.doc");
Document doc2 = new Document(dataPath + "doc2.doc");
doc1.appendDocument(doc2, ImportFormatMode.KEEP_SOURCE_FORMATTING);
doc1.save(dataPath + "AsposeMerged.doc", SaveFormat.DOC);
}
开发者ID:asposemarketplace,项目名称:Aspose_Java_for_Docx4j,代码行数:12,代码来源:AsposeAppendDocs.java
示例5: main
import com.aspose.words.Document; //导入依赖的package包/类
public static void main(String[] args) throws Exception
{
String dataPath = "src/featurescomparison/workingwithdocuments/createnewdoc/data/";
Document doc = new Document();
// DocumentBuilder provides members to easily add content to a document.
DocumentBuilder builder = new DocumentBuilder(doc);
// Write a new paragraph in the document with some text as "Sample Content..."
builder.setBold(true);
builder.writeln("Aspose Sample Content for Word file.");
// Save the document in DOCX format. The format to save as is inferred from the extension of the file name.
// Aspose.Words supports saving any document in many more formats.
doc.save(dataPath + "Aspose_NewDoc.docx",SaveFormat.DOCX);
}
开发者ID:asposemarketplace,项目名称:Aspose_Java_for_Docx4j,代码行数:19,代码来源:AsposeNewDocument.java
示例6: convertPDF
import com.aspose.words.Document; //导入依赖的package包/类
@Override
public File convertPDF(File theFile, String md5UploadedFile) throws PDFConverterException {
try {
// TEST ONLY!
// License license = new License();
// license.setLicense("");
String outFileName = this.getOutputFileName(md5UploadedFile);
File pdfOutput = new File(Config.getString("application.staticFiles"), outFileName);
Document doc = new Document(new FileInputStream(theFile));
doc.save(pdfOutput.getCanonicalPath());
return pdfOutput;
} catch (Exception e) {
log.error("Fail to create PDF in AsposeWords Converter", e);
throw new PDFConverterException("Fail to create PDF in AsposeWords Converter", e);
}
}
开发者ID:LeoFCardoso,项目名称:tudoToPDF,代码行数:17,代码来源:AsposeWordsConverter.java
示例7: exportToDoc
import com.aspose.words.Document; //导入依赖的package包/类
public static void exportToDoc(File tempDocFile, byte[] bytes)
throws PortalException, SystemException {
try {
InputStream is = new ByteArrayInputStream(bytes);
LoadOptions loadOptions = new LoadOptions();
loadOptions.setLoadFormat(LoadFormat.HTML);
Document doc = new Document(is, loadOptions);
doc.save(new FileOutputStream(tempDocFile),
com.aspose.words.SaveFormat.DOC);
} catch (Exception e) {
String msg = "Aspose: Unable to export to ms word format.. some error occured: "
+ e.getMessage();
s_log.error(msg, e);
throw new PortalException(
"Aspose: Unable to export to ms word format.. some error occured",
e);
}
}
开发者ID:asposemarketplace,项目名称:Aspose_for_Liferay,代码行数:25,代码来源:AsposExportHelper.java
示例8: exportToPdf
import com.aspose.words.Document; //导入依赖的package包/类
public static void exportToPdf(File tempPdfFile, byte[] bytes)
throws PortalException, SystemException {
try {
InputStream is = new ByteArrayInputStream(bytes);
LoadOptions loadOptions = new LoadOptions();
loadOptions.setLoadFormat(LoadFormat.HTML);
Document doc = new Document(is, loadOptions);
doc.save(new FileOutputStream(tempPdfFile),
com.aspose.words.SaveFormat.PDF);
} catch (Exception e) {
String msg = "Aspose: Unable to export to PDF format.. some error occured: "
+ e.getMessage();
s_log.error(msg, e);
throw new PortalException(
"Aspose: Unable to export PDF format.. some error occured",
e);
}
}
开发者ID:asposemarketplace,项目名称:Aspose_for_Liferay,代码行数:25,代码来源:AsposExportHelper.java
示例9: insertWatermarkText
import com.aspose.words.Document; //导入依赖的package包/类
/**
* Inserts a watermark into a document.
*
* @param doc The input document.
* @param watermarkText Text of the watermark.
*/
private static void insertWatermarkText(Document doc, String watermarkText) throws Exception
{
// Create a watermark shape. This will be a WordArt shape.
// You are free to try other shape types as watermarks.
Shape watermark = new Shape(doc, ShapeType.TEXT_PLAIN_TEXT);
// Set up the text of the watermark.
watermark.getTextPath().setText(watermarkText);
watermark.getTextPath().setFontFamily("Arial");
watermark.setWidth(500);
watermark.setHeight(100);
// Text will be directed from the bottom-left to the top-right corner.
watermark.setRotation(-40);
// Remove the following two lines if you need a solid black text.
watermark.getFill().setColor(Color.GRAY); // Try LightGray to get more Word-style watermark
watermark.setStrokeColor(Color.GRAY); // Try LightGray to get more Word-style watermark
// Place the watermark in the page center.
watermark.setRelativeHorizontalPosition(RelativeHorizontalPosition.PAGE);
watermark.setRelativeVerticalPosition(RelativeVerticalPosition.PAGE);
watermark.setWrapType(WrapType.NONE);
watermark.setVerticalAlignment(VerticalAlignment.CENTER);
watermark.setHorizontalAlignment(HorizontalAlignment.CENTER);
// Create a new paragraph and append the watermark to this paragraph.
Paragraph watermarkPara = new Paragraph(doc);
watermarkPara.appendChild(watermark);
// Insert the watermark into all headers of each document section.
for (Section sect : doc.getSections())
{
// There could be up to three different headers in each section, since we want
// the watermark to appear on all pages, insert into all headers.
insertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HEADER_PRIMARY);
// insertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HEADER_FIRST);
// insertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HEADER_EVEN);
}
}
开发者ID:asposemarketplace,项目名称:Aspose_for_Apache_POI,代码行数:45,代码来源:AsposeWatermarks.java
示例10: main
import com.aspose.words.Document; //导入依赖的package包/类
public static void main(String[] args) throws Exception
{
String dataPath = "src/asposefeatures/workingwithdocument/insertpicture/data/";
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.insertImage(dataPath + "background.jpg");
builder.insertImage(dataPath + "background.jpg",
RelativeHorizontalPosition.MARGIN,
100,
RelativeVerticalPosition.MARGIN,
200,
200,
100,
WrapType.SQUARE);
doc.save(dataPath + "AsposeImageInDoc.docx");
System.out.println("Done.");
}
开发者ID:asposemarketplace,项目名称:Aspose_for_Apache_POI,代码行数:22,代码来源:AsposeInsertImage.java
示例11: main
import com.aspose.words.Document; //导入依赖的package包/类
public static void main(String[] args) throws Exception
{
String dataPath = "src/asposefeatures/workingwithtables/joiningtables/data/";
// Load the document.
Document doc = new Document(dataPath + "tableDoc.doc");
// Get the first and second table in the document.
// The rows from the second table will be appended to the end of the first table.
Table firstTable = (Table)doc.getChild(NodeType.TABLE, 0, true);
Table secondTable = (Table)doc.getChild(NodeType.TABLE, 1, true);
// Append all rows from the current table to the next.
// Due to the design of tables even tables with different cell count and widths can be joined into one table.
while (secondTable.hasChildNodes())
firstTable.getRows().add(secondTable.getFirstRow());
// Remove the empty table container.
secondTable.remove();
doc.save(dataPath + "AsposeJoinTables.doc");
System.out.println("Done.");
}
开发者ID:asposemarketplace,项目名称:Aspose_for_Apache_POI,代码行数:25,代码来源:AsposeJoiningTables.java
示例12: main
import com.aspose.words.Document; //导入依赖的package包/类
public static void main(String[] args) throws Exception
{
String dataPath = "src/asposefeatures/workingwithtables/autofitsettingstotable/data/";
// Open the document
Document doc = new Document(dataPath + "tableDoc.doc");
Table table = (Table)doc.getChild(NodeType.TABLE, 0, true);
// Autofit the first table to the page width.
table.autoFit(AutoFitBehavior.AUTO_FIT_TO_WINDOW);
Table table2 = (Table)doc.getChild(NodeType.TABLE, 1, true);
// Auto fit the table to the cell contents
table2.autoFit(AutoFitBehavior.AUTO_FIT_TO_CONTENTS);
// Save the document to disk.
doc.save(dataPath + "AsposeAutoFitTable_Out.doc");
System.out.println("Process Completed Successfully");
}
开发者ID:asposemarketplace,项目名称:Aspose_for_Apache_POI,代码行数:21,代码来源:AsposeTableAutoFitSettings.java
示例13: main
import com.aspose.words.Document; //导入依赖的package包/类
public static void main(String[] args) throws Exception
{
String dataPath = "src/asposefeatures/workingwithtext/usingcontrolcharacters/data/";
// Load the document.
Document doc = new Document();
// DocumentBuilder provides members to easily add content to a document.
DocumentBuilder builder = new DocumentBuilder(doc);
// Write a new paragraph in the document with some text as "Sample Content..."
builder.setBold(true);
builder.writeln("Aspose Sample Content for Word file.\r More Sample");
String text = doc.getText();
System.out.println("Doc Text: " + text);
//Replace "\r" control character with "\r\n"
text = text.replace(ControlChar.CR, ControlChar.CR_LF);
System.out.println("Doc Text: " + text);
doc.save(dataPath + "AsposeControlChars.doc", SaveFormat.DOC);
}
开发者ID:asposemarketplace,项目名称:Aspose_for_Apache_POI,代码行数:23,代码来源:AsposeUseControlCharacters.java
示例14: main
import com.aspose.words.Document; //导入依赖的package包/类
public static void main(String[] args) throws Exception
{
String dataPath = "src/asposefeatures/workingwithtext/extractcomments/data/";
Document doc = new Document(dataPath + "AsposeComments.docx");
ArrayList collectedComments = new ArrayList();
// Collect all comments in the document
NodeCollection comments = doc.getChildNodes(NodeType.COMMENT, true);
// Look through all comments and gather information about them.
for (Comment comment : (Iterable<Comment>) comments)
{
System.out.println(comment.getAuthor() + " - " + comment.getDateTime() + " - "
+ comment.toString(SaveFormat.TEXT));
}
System.out.println("Done.");
}
开发者ID:asposemarketplace,项目名称:Aspose_for_Apache_POI,代码行数:20,代码来源:AsposeExtractComments.java
示例15: main
import com.aspose.words.Document; //导入依赖的package包/类
public static void main(String[] args) throws Exception
{
String dataPath = "src/asposefeatures/workingwithtext/insertcomments/data/";
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.write("Some text is added.");
Comment comment = new Comment(doc, "Aspose", "As", new Date());
builder.getCurrentParagraph().appendChild(comment);
comment.getParagraphs().add(new Paragraph(doc));
comment.getFirstParagraph().getRuns().add(new Run(doc, "Comment text."));
doc.save(dataPath + "AsposeComments.docx");
System.out.println("Done.");
}
开发者ID:asposemarketplace,项目名称:Aspose_for_Apache_POI,代码行数:18,代码来源:AsposeInsertComments.java
示例16: main
import com.aspose.words.Document; //导入依赖的package包/类
public static void main(String[] args) throws Exception
{
String dataPath = "src/asposefeatures/workingwithtext/removecomments/data/";
Document doc = new Document(dataPath + "AsposeComments.docx");
// Collect all comments in the document
NodeCollection comments = doc.getChildNodes(NodeType.COMMENT, true);
// Look through all comments and remove those written by the authorName author.
for (int i = comments.getCount() - 1; i >= 0; i--)
{
Comment comment = (Comment) comments.get(i);
if (comment.getAuthor().equalsIgnoreCase("Aspose"))
System.out.println("Aspose comment removed");
comment.remove();
}
doc.save(dataPath + "AsposeCommentsRemoved.docx");
System.out.println("Done...");
}
开发者ID:asposemarketplace,项目名称:Aspose_for_Apache_POI,代码行数:21,代码来源:AsposeRemoveComments.java
示例17: main
import com.aspose.words.Document; //导入依赖的package包/类
public static void main(String[] args) throws Exception
{
Document doc = new Document("data/document.doc");
NodeCollection shapes = doc.getChildNodes(NodeType.SHAPE, true);
int imageIndex = 0;
for (Shape shape : (Iterable<Shape>) shapes)
{
if (shape.hasImage())
{
String imageFileName = java.text.MessageFormat.format(
"Aspose.Images.{0}{1}", imageIndex, FileFormatUtil
.imageTypeToExtension(shape.getImageData()
.getImageType()));
shape.getImageData().save("data/asposeImages/" + imageFileName);
imageIndex++;
}
}
}
开发者ID:asposemarketplace,项目名称:Aspose_for_Apache_POI,代码行数:21,代码来源:AsposeExtractImages.java
示例18: main
import com.aspose.words.Document; //导入依赖的package包/类
public static void main(String[] args) throws Exception
{
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.insertImage("data/background.jpg");
builder.insertImage("data/background.jpg",
RelativeHorizontalPosition.MARGIN,
100,
RelativeVerticalPosition.MARGIN,
200,
200,
100,
WrapType.SQUARE);
doc.save("data/Aspose_InsertImage.docx");
System.out.println("Process Completed Successfully");
}
开发者ID:asposemarketplace,项目名称:Aspose_for_Apache_POI,代码行数:20,代码来源:AsposeInsertImage.java
示例19: main
import com.aspose.words.Document; //导入依赖的package包/类
public static void main(String[] args) throws Exception
{
Document doc = new Document();
// DocumentBuilder provides members to easily add content to a document.
DocumentBuilder builder = new DocumentBuilder(doc);
// Write a new paragraph in the document with some text as "Sample Content..."
builder.setBold(true);
builder.writeln("Aspose Sample Content for Word file.");
// Save the document in DOCX format. The format to save as is inferred from the extension of the file name.
// Aspose.Words supports saving any document in many more formats.
doc.save("data/Aspose_NewDoc.docx",SaveFormat.DOCX);
}
开发者ID:asposemarketplace,项目名称:Aspose_for_Apache_POI,代码行数:17,代码来源:AsposeNewDocument.java
示例20: main
import com.aspose.words.Document; //导入依赖的package包/类
public static void main(String[] args) throws Exception
{
String dataPath = "src/asposefeatures/workingwithdocuments/movingcursorindocs/data/";
Document doc = new Document(dataPath + "document.doc");
DocumentBuilder builder = new DocumentBuilder(doc);
//Shows how to access the current node in a document builder.
Node curNode = builder.getCurrentNode();
Paragraph curParagraph = builder.getCurrentParagraph();
// Shows how to move a cursor position to a specified node.
builder.moveTo(doc.getFirstSection().getBody().getLastParagraph());
// Shows how to move a cursor position to the beginning or end of a document.
builder.moveToDocumentEnd();
builder.writeln("This is the end of the document.");
builder.moveToDocumentStart();
builder.writeln("This is the beginning of the document.");
doc.save(dataPath + "AsposeMovingCursor.doc");
System.out.println("Done.");
}
开发者ID:asposemarketplace,项目名称:Aspose_Java_for_Docx4j,代码行数:26,代码来源:AsposeMovingCursor.java
注:本文中的com.aspose.words.Document类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论