All Projects → shinjukunian → DocX

shinjukunian / DocX

Licence: MIT license
Convert NSAttributedString / AttributedString to .docx Word files on iOS and macOS

Programming Languages

swift
15916 projects
Rich Text Format
576 projects
objective c
16641 projects - #2 most used programming language

Projects that are alternatives of or similar to DocX

Docx
Easily generate .docx files with JS/TS with a nice declarative API. Works for Node and on the Browser.
Stars: ✭ 2,150 (+5143.9%)
Mutual labels:  docx, docx-generator
sarna
Security Assessment Report geNerated Automatically
Stars: ✭ 26 (-36.59%)
Mutual labels:  docx, docx-generator
mathtype-extension
Calabash extension step to convert MathType OLE objects to MathML
Stars: ✭ 15 (-63.41%)
Mutual labels:  docx
officeexport-java
三行代码导出自定义样式word
Stars: ✭ 68 (+65.85%)
Mutual labels:  docx
dashboard
iOS app + Today widget that monitors the status of my web apps. Updated for SwiftUI!
Stars: ✭ 41 (+0%)
Mutual labels:  watchos
WWDCNotes
WWDCNotes.com content
Stars: ✭ 343 (+736.59%)
Mutual labels:  watchos
docx-pdf-pagecount
A npm module to page count od pdf and docx files
Stars: ✭ 22 (-46.34%)
Mutual labels:  docx
Orchard
Device identification in Swift and Objective-C for iOS, watchOS, and tvOS.
Stars: ✭ 15 (-63.41%)
Mutual labels:  watchos
KeyboardKitPro
KeyboardKit Pro extends KeyboardKit with pro features.
Stars: ✭ 42 (+2.44%)
Mutual labels:  watchos
SwiftKit
SwiftKit adds extra functionality to the Swift programming language.
Stars: ✭ 47 (+14.63%)
Mutual labels:  watchos
OpenAPI-Swift
KKBOX Open API Swift Developer SDK for iOS/macOS/watchOS/tvOS
Stars: ✭ 13 (-68.29%)
Mutual labels:  watchos
kodbox
kodbox is a file manager for web. It is a newly designed product based on kodexplorer. It is also a web code editor, which allows you to develop websites directly within the web browser.You can run kodbox either online or locally,on Linux, Windows or Mac based platforms
Stars: ✭ 1,188 (+2797.56%)
Mutual labels:  docx
RFKit
Toolkit for daily Cocoa development. Since 2012.
Stars: ✭ 20 (-51.22%)
Mutual labels:  watchos
PDFConverter
Best PDF Converter! PDF to any format, pdf2word/excel/xml/html/txt...
Stars: ✭ 94 (+129.27%)
Mutual labels:  docx
articles-ko
Articles for NSHipster.co.kr
Stars: ✭ 18 (-56.1%)
Mutual labels:  watchos
SmogWatch
watchOS app for checking air pollution levels, created for my blog post series
Stars: ✭ 34 (-17.07%)
Mutual labels:  watchos
wwdc2018
You read my developer triceraptus migration notes from dub dub dc 2018
Stars: ✭ 48 (+17.07%)
Mutual labels:  watchos
SwiftBuilder
SwiftBuilder is a fast way to assign new value to the property of the object.
Stars: ✭ 26 (-36.59%)
Mutual labels:  watchos
SwiftCurrent
A library for managing complex workflows in Swift
Stars: ✭ 286 (+597.56%)
Mutual labels:  watchos
documentspark
💖 DocumentSpark - Simple secure document viewing server. Converts a document to a picture of its pages. Content disarm and reconstruction. CDR. Formerly p2. The CDR solution for ViewFinder remote browser.
Stars: ✭ 211 (+414.63%)
Mutual labels:  docx

DocX

Swift

A small framework that converts NSAttributedString to .docx Word files on iOS and macOS.

Motivation

On iOS, NSAttributedString.DocumentType supports only HTML and Rich Text, while on macOS .doc and .docx are available options. Even then the .docx exporter on macOS supports only a subset of the attributes of NSAttributedString.

This library is used in SimpleFurigana for macOS and SimpleFurigana for iOS, hence the focus on furigana annotation export.

Installation

Add

.package(name: "DocX", url: "https://github.com/shinjukunian/DocX.git", .branch("master"))

to dependencies in your Package.swift file. This requires Swift 5.3, which shipped with Xcode12. Alternatively, add DocX in Xcode via File->Swift Packages->Add Package Dependency, paste https://github.com/shinjukunian/DocX.git as URL and specify master as branch.

Usage

let string = NSAttributedString(string: "This is a string", attributes: [.font: UIFont.systemFont(ofSize: UIFont.systemFontSize), .backgroundColor: UIColor.blue])
let url = URL(fileURLWithPath:"myPath")
try? string.writeDocX(to: url)

Starting from iOS 15 / macOS 12, you can use the new AttributedString.

var att=AttributedString("Lorem ipsum dolor sit amet")
att.font = NSFont(name: "Helvetica", size: 12)
att[att.range(of: "Lorem")!].backgroundColor = .blue
let url = URL(fileURLWithPath:"myPath")
try att.writeDocX(to: url)

Naturally, this works for Markdown as well:

let mD="~~This~~ is a **Markdown** *string*."
let att=try AttributedString(markdown: mD)
try att.writeDocX(to: url)

You can optionally specify MetaData using DocXOptions:

let font = NSFont(name: "Helvetica", size: 13)! //on macOS
let string = NSAttributedString(string: "The Foundation For Law and Government favours Helvetica.", attributes: [.font: font])

var options = DocXOptions()
options.author = "Michael Knight"
options.title = "Helvetica Document"

let url = URL(fileURLWithPath:"myPath")
try string.writeDocX(to: url, options:options)

See the attached sample projects (for iOS and macOS) for usage and limitations. On iOS, DocX also includes a UIActivityItemProvider subclass (DocXActivityItemProvider) for exporting .docx files through UIActivityViewController.

NSAttributedString has no concept of pagination. For manual pagination, use

try DocXWriter.write(pages:[NSAttributedString], to url:URL)

to render each NSAttributedString as a separate page.

Screenshot macOS

A sample output on macOS opened in Word365.

Screenshot Lenna

A sample output on macOS with an embedded image (via NSTextAttachment). in the macOS sample application (which is a simple NSTextView), this can be achieved using drag&drop. Note that there is little control over the placement of the image, the image will be inline with text.

Screenshot iOS

A sample output on iOS opened in Word for iOS. Furigana annotations are preserved. The link is clickable. Please note that Quicklook (on both platforms) only supports a limited number of attributes.

Supported Attributes

  • most things in NSAttributedString.Key (fonts, colors, underline, indents etc.) except
    • NSAttributedString.Key.expansion
    • NSAttributedString.Key.kern
    • NSAttributedString.Key.ligature
    • NSAttributedString.Key.obliqueness
    • NSAttributedString.Key.superscript (macOS only, doesnt really work for most fonts anyway)
    • NSAttributedString.Key.textEffect
  • CTRubyAnnotation for furigana (ruby) annotations in CoreText
  • NSTextAttachment embedded images (inline with text)

For AttributedString, DocX supports the attributes present in NSAttributedString, i.e. most attributes in AttributeScopes.AppKitAttributes or AttributeScopes.UIKitAttributes (see above for omissions). For AttributedStrings initialized from Markdown (AttributeScopes.FoundationAttributes), DocX supports links (AttributeScopes.FoundationAttributes.LinkAttribute), bold, italic, and strikethrough (AttributeScopes.FoundationAttributes.InlinePresentationIntentAttribute), and inline images (AttributeScopes.FoundationAttributes.ImageURLAttribute). Please note that images are not rendered by SwiftUI's Text.

Some attributes don't have a direct correspondence. For example NSAttributedString does (typically) not have the concept of a page size.

Dependencies

Alternatives

References

Licence

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].