0
CSV 입력에서 PDF 파일을 렌더링하는 템플릿을 만들었습니다. 그러나 csv 입력 필드에 줄 바꿈 및 들여 쓰기가 포함 된 사용자 서식이 포함되어 있으면 rst2pdf 서식 지정 엔진이 엉망입니다. 문서 흐름을 깨뜨리지 않고 입력 텍스트의 서식을 유지하는 방식으로 사용자 입력을 일관되게 처리 할 수있는 방법이 있습니까? 아래 예제 스크립트 :mako 및 rst2pdf를 사용하여 가져온 텍스트의 서식을 유지합니다.
from mako.template import Template
from rst2pdf.createpdf import RstToPdf
mytext = """This is the first line
Then there is a second
Then a third
This one could be indented
I'd like it to maintain the formatting."""
template = """
My PDF Document
===============
It starts with a paragraph, but after this I'd like to insert `mytext`.
It should keep the formatting intact, though I don't know what formatting to expect.
${mytext}
"""
mytemplate = Template(template)
pdf = RstToPdf()
pdf.createPdf(text=mytemplate.render(mytext=mytext),output='foo.pdf')
나는 각 라인의 시작 |
을 삽입하는 템플릿에 다음과 같은 기능을 추가하는 시도했지만, 그 중 하나가 작동하지 않습니다.
<%!
def wrap(text):
return text.replace("\\n", "\\n|")
%>
그런 다음
${mytext}
는
|${mytext | wrap}
이 될 것입니다. 난 그냥
|
와 텍스트 사이의 공간을 필요
<string>:10: (WARNING/2) Inline substitution_reference start-string without end-string.
이 방법을 별도의 템플릿 파일에서 사용하면 줄 바꿈 문자를 이중으로 이스케이프 할 필요가 없으므로'\\ n '은'\ n'으로 바뀝니다. – rudivonstaden