Esempio n. 1
0
 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)
Esempio n. 2
0
 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)
Esempio n. 3
0
 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"
Esempio n. 4
0
 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"
Esempio n. 5
0
 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
Esempio n. 6
0
 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"
Esempio n. 7
0
 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"
Esempio n. 8
0
 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
Esempio n. 9
0
 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
Esempio n. 10
0
 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
Esempio n. 11
0
File: pdf.py Progetto: CongWu/pyth
# -*- 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)
Esempio n. 12
0
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)
Esempio n. 13
0
 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