워드 문서의 옵션 및 모양 작업
때로는 문서의 모양을 변경해야 할 수도 있습니다(예:언어 기본 설정 또는 페이지 당 줄 수 설정).Aspose.Words은 문서 표시 방법과 몇 가지 추가 옵션을 제어할 수 있는 기능을 제공합니다. 이 기사에서는 이러한 가능성을 설명합니다.
문서 표시 옵션 설정
ViewOptions클래스를 사용하여Microsoft Word에 문서가 표시되는 방법을 제어할 수 있습니다. 예를 들어ZoomPercent속성을 사용하여 문서 확대/축소 값을 설정하거나ViewType속성을 사용하여 보기 모드를 설정할 수 있습니다.
다음 코드 예제에서는Microsoft Word에서 열 때 문서가 50%로 표시되도록 하는 방법을 보여 줍니다:
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java | |
Document doc = new Document(dataDir + "Document.doc"); | |
doc.getViewOptions().setViewType(ViewType.PAGE_LAYOUT); | |
doc.getViewOptions().setZoomPercent(50); | |
doc.save(dataDir + "Document.SetZoom_out.doc"); |
페이지 표시 옵션 설정
줄당 문자 수를 설정하려면CharactersPerLine속성을 사용합니다. LinesPerPage속성을 사용하여 문서 표에서 페이지당 줄 수를 가져오거나 설정합니다.
다음 코드 예제에서는Microsoft Word문서에 대해 행당 문자 수와 페이지당 줄 수를 설정하는 방법을 보여 줍니다:
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java | |
// The path to the documents directory. | |
Document doc = new Document(dataDir + "Document.doc"); | |
// Set the layout mode for a section allowing to define the document grid | |
// behavior | |
// Note that the Document Grid tab becomes visible in the Page Setup dialog of | |
// MS Word if any Asian language is defined as editing language. | |
doc.getFirstSection().getPageSetup().setLayoutMode(SectionLayoutMode.GRID); | |
// Set the number of characters per line in the document grid. | |
doc.getFirstSection().getPageSetup().setCharactersPerLine(30); | |
// Set the number of lines per page in the document grid. | |
doc.getFirstSection().getPageSetup().setLinesPerPage(10); | |
// Save the document | |
doc.save(dataDir + "Document.PageSetup_out.doc"); |
언어 기본 설정 설정
Microsoft Word에서 문서를 표시하는 것은 이 문서의 기본 언어로 설정된 언어에 따라 달라집니다. 기본 언어로 설정된 언어가 없는 경우 Microsoft Word은 “Office 언어 기본 설정 설정” 대화 상자에서 정보를 가져옵니다. 예를 들어, Microsoft Word 2019의 “파일 → 옵션 → 언어"에서 찾을 수 있습니다.
Aspose.Words을 사용하면 LanguagePreferences 클래스를 사용하여 언어 기본 설정을 설정할 수도 있습니다. 또한 문서를 올바르게 표시하려면 문서 로딩 프로세스가 일치해야 하는 Microsoft Word 버전을 설정해야 합니다. 이는 MswVersion 속성을 사용하여 수행할 수 있습니다.
다음 코드 예제에서는 편집 언어에 일본어를 추가하는 방법을 보여 줍니다:
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java | |
// Specify LoadOptions to add Editing Language | |
LoadOptions loadOptions = new LoadOptions(); | |
loadOptions.getLanguagePreferences().addEditingLanguage(EditingLanguage.JAPANESE); | |
Document doc = new Document(dataDir + "languagepreferences.docx", loadOptions); | |
int localeIdFarEast = doc.getStyles().getDefaultFont().getLocaleIdFarEast(); | |
if (localeIdFarEast == (int) EditingLanguage.JAPANESE) | |
System.out.println("The document either has no any FarEast language set in defaults or it was set to Japanese originally."); | |
else | |
System.out.println("The document default FarEast language was set to another than Japanese language originally, so it is not overridden."); |
다음 코드 예제에서는 러시아어를 기본 편집 언어로 설정하는 방법을 보여 줍니다:
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java | |
// Specify LoadOptions to set Default Editing Language | |
LoadOptions loadOptions = new LoadOptions(); | |
loadOptions.getLanguagePreferences().setDefaultEditingLanguage(EditingLanguage.RUSSIAN); | |
Document doc = new Document(dataDir + "languagepreferences.docx", loadOptions); | |
int localeId = doc.getStyles().getDefaultFont().getLocaleId(); | |
if (localeId == (int) EditingLanguage.RUSSIAN) | |
System.out.println("The document either has no any language set in defaults or it was set to Russian originally."); | |
else | |
System.out.println("The document default language was set to another than Russian language originally, so it is not overridden."); |
특정 단어 버전에 대한 문서 최적화
OptimizeFor방법을 사용하면 특정 버전의Microsoft Word에 대한 기본Aspose.Words동작뿐만 아니라 문서 내용을 최적화 할 수 있습니다. 이 방법을 사용하면Microsoft Word가 문서 로드 시"호환 모드"리본을 표시하지 못하도록 할 수 있습니다. Compliance
속성을Iso29500_2008_Transitional이상으로 설정해야 할 수도 있습니다.
다음 코드 예제에서는Microsoft Word2016 에 대한 문서 콘텐츠를 최적화하는 방법을 보여 줍니다:
Document doc = new Document(dataDir + "Document.docx");
// Set Word2016 version for document
doc.getCompatibilityOptions().optimizeFor(MsWordVersion.WORD_2016);
// Save the document.
doc.save(dataDir + "output.docx");