Beispiel #1
0
 def __init__(self, filename):
     super().__init__(backend=pdf)
     self.styles = styles
     parser = ReStructuredTextParser()
     self.root = parser.parse(filename)
     self.content = rt.Chain(self)
     self.parse_input()
Beispiel #2
0
 def __init__(self, filename):
     super().__init__(backend=pdf)
     self.styles = styles
     parser = ReStructuredTextParser()
     self.root = parser.parse(filename)
     self.content = rt.Chain(self)
     self.parse_input()
Beispiel #3
0
def main():
    parser = argparse.ArgumentParser(description='Render a reStructuredText '
                                                 'document to PDF.')
    parser.add_argument('input', type=str, nargs='?',
                       help='the reStructuredText document to render')
    parser.add_argument('--paper', type=str, nargs='?', default='A4',
                       help='the paper size to render to (default: A4)')
    args = parser.parse_args()

    try:
        input_dir, input_filename = os.path.split(args.input)
    except AttributeError:
        parser.print_help()
        return

    try:
        page_size = getattr(paper, args.paper.upper())
    except AttributeError:
        print("Unknown paper size '{}'. Must be one of:".format(args.paper))
        print('   A0, A1, ..., A10, letter, legal, junior_legal, ledger, '
              'tabloid')
        return

    input_root, input_ext = os.path.splitext(input_filename)
    if input_dir:
        os.chdir(input_dir)
    parser = ReStructuredTextParser()
    with open(input_filename) as input_file:
        document_tree = parser.parse(input_file)
    options = ArticleOptions(page_size=page_size)
    document = Article(document_tree, options, backend=pdf)
    document.render(input_root)
Beispiel #4
0
def render_rst(content):
    input_file = StringIO(content)
    parser = ReStructuredTextParser()
    document_tree = parser.parse(input_file)
    document = Article(document_tree, OPTIONS, backend=pdf)
    pdf_output = BytesIO()
    document.render(file=pdf_output)
    pdf_output.seek(0)
    return pdf_output
Beispiel #5
0
def render_rst(content):
    input_file = StringIO(content)
    parser = ReStructuredTextParser()
    document_tree = parser.parse(input_file)
    document = Article(document_tree, OPTIONS, backend=pdf)
    pdf_output = BytesIO()
    document.render(file=pdf_output)
    pdf_output.seek(0)
    return pdf_output
Beispiel #6
0
def main():
    parser = argparse.ArgumentParser(description='Render a reStructuredText '
                                                 'document to PDF.')
    parser.add_argument('input', type=str, nargs='?',
                       help='the reStructuredText document to render')
    parser.add_argument('--paper', type=str, nargs='?', default='A4',
                       help='the paper size to render to (default: A4)')
    args = parser.parse_args()

    try:
        input_dir, input_file = os.path.split(args.input)
    except AttributeError:
        parser.print_help()
        return

    input_base, input_ext = os.path.splitext(input_file)
    if input_dir:
        os.chdir(input_dir)
    parser = ReStructuredTextParser()
    document_tree = parser.parse(input_file)
    options = ArticleOptions(page_size=getattr(paper, args.paper.upper()))
    document = Article(document_tree, options, backend=pdf)
    document.render(input_base)
Beispiel #7
0
from rinoh.paper import A5
from rinoh.backend import pdf
from rinoh.frontend.rst import ReStructuredTextParser

from rinohlib.stylesheets.somestyle import stylesheet as STYLESHEET
from rinohlib.templates.book import Book, BookOptions
from rinohlib.templates.article import Article, ArticleOptions

if __name__ == '__main__':
#    for name in ('quickstart', 'FAQ', 'THANKS'):
    for name in ('demo', ):
        parser = ReStructuredTextParser()
        with open(name + '.txt') as file:
            flowables = parser.parse(file)
        # manual_options = BookOptions(stylesheet=STYLESHEET)
        # document = Book(document_tree, options=manual_options, backend=pdf)
        article_options = ArticleOptions(table_of_contents=False, page_size=A5)
        document = Article(flowables, options=article_options, backend=pdf)
        document.render(name)
Beispiel #8
0
from rinoh.paper import A5
from rinoh.backend import pdf
from rinoh.frontend.rst import ReStructuredTextParser

from rinohlib.stylesheets.somestyle import stylesheet as STYLESHEET
from rinohlib.templates.book import Book, BookOptions
from rinohlib.templates.article import Article, ArticleOptions

if __name__ == '__main__':
#    for name in ('quickstart', 'FAQ', 'THANKS'):
    for name in ('demo', ):
        parser = ReStructuredTextParser()
        flowables = parser.parse(name + '.txt')
        # manual_options = BookOptions(stylesheet=STYLESHEET)
        # document = Book(document_tree, options=manual_options, backend=pdf)
        article_options = ArticleOptions(table_of_contents=False, page_size=A5)
        document = Article(flowables, options=article_options, backend=pdf)
        document.render(name)