def test_basic(self): """ Try to create an empty pdf document """ doc = PythonReader.read([]) pdf = PDFWriter.write(doc).getvalue() html = self.pdf_to_html(pdf)
def test_italic(self): doc = PythonReader.read([P[T(ITALIC)[u"italic text"]]]) pdf = PDFWriter.write(doc).getvalue() html = self.pdf_to_html(pdf) soup = BeautifulSoup.BeautifulSoup(html) node = soup.find("i") assert node assert node.string == "italic text"
def test_bold(self): doc = PythonReader.read([P[T(BOLD)[u"bold text"]]]) pdf = PDFWriter.write(doc).getvalue() html = self.pdf_to_html(pdf) soup = BeautifulSoup.BeautifulSoup(html) node = soup.find("b") assert node assert node.string == "bold text"
def test_paragraph(self): """ Try a simple document with one paragraph """ doc = PythonReader.read(P[u"the text"]) pdf = PDFWriter.write(doc).getvalue() html = self.pdf_to_html(pdf) assert "the text" in html
def test_rst(self): doc = PythonReader.read(P[u"the-text"]) pdf = PDFWriter.write(doc).getvalue() print pdf html = self.pdf_to_html(pdf) assert "the-text" in html, html
def test_rst(self): doc = PythonReader.read(P[u"the-text"]) pdf = PDFWriter.write(doc).getvalue() print(pdf) html = self.pdf_to_html(pdf) assert "the-text" in html, html
# -*- coding: utf-8 -*- from pyth.plugins.rtf15.reader import Rtf15Reader from pyth.plugins.pdf.writer import PDFWriter doc = Rtf15Reader.read(open("../reading/sample.rtf")) fontfile = "/usr/share/fonts/truetype/msttcorefonts/Times_New_Roman%s.ttf" from reportlab.lib.styles import getSampleStyleSheet from reportlab.pdfbase.pdfmetrics import registerFont, registerFontFamily from reportlab.pdfbase.ttfonts import TTFont registerFont(TTFont('TimesTTF', fontfile % "")) registerFont(TTFont('TimesTTF_B', fontfile % "_Bold")) registerFont(TTFont('TimesTTF_I', fontfile % "_Italic")) registerFont(TTFont('TimesTTF_BI', fontfile % "_Bold_Italic")) registerFontFamily("TimesTTF", normal="TimesTTF", bold="TimesTTF_B", italic="TimesTTF_I", boldItalic="TimesTTF_BI") stylesheet = getSampleStyleSheet() paragraphStyle = stylesheet['Normal'] paragraphStyle.fontName = "TimesTTF" PDFWriter.write(doc, open("output.pdf", "wb"), paragraphStyle)
from __future__ import absolute_import # -*- coding: utf-8 -*- from pyth.plugins.rtf15.reader import Rtf15Reader from pyth.plugins.pdf.writer import PDFWriter doc = Rtf15Reader.read(open("../reading/sample.rtf")) fontfile = "/usr/share/fonts/truetype/msttcorefonts/Times_New_Roman%s.ttf" from reportlab.lib.styles import getSampleStyleSheet from reportlab.pdfbase.pdfmetrics import registerFont, registerFontFamily from reportlab.pdfbase.ttfonts import TTFont registerFont(TTFont('TimesTTF', fontfile % "")) registerFont(TTFont('TimesTTF_B', fontfile % "_Bold")) registerFont(TTFont('TimesTTF_I', fontfile % "_Italic")) registerFont(TTFont('TimesTTF_BI', fontfile % "_Bold_Italic")) registerFontFamily("TimesTTF", normal="TimesTTF", bold="TimesTTF_B", italic="TimesTTF_I", boldItalic="TimesTTF_BI") stylesheet = getSampleStyleSheet() paragraphStyle = stylesheet['Normal'] paragraphStyle.fontName = "TimesTTF" PDFWriter.write(doc, open("output.pdf", "wb"), paragraphStyle)
def test_latex(self): doc = PythonReader.read(P[u"the-text"]) pdf = PDFWriter.write(doc, method='latex').getvalue() html = self.pdf_to_html(pdf) assert "the-text" in html, html