Пример #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)
Пример #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)
Пример #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"
Пример #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"
Пример #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
Пример #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"
Пример #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"
Пример #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
Пример #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
Пример #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
Пример #11
0
Файл: pdf.py Проект: 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)
Пример #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)
Пример #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