Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to create a new PDF, add new pages with some text? #236

Open
barseghyanartur opened this issue Jan 16, 2023 · 1 comment
Open

How to create a new PDF, add new pages with some text? #236

barseghyanartur opened this issue Jan 16, 2023 · 1 comment

Comments

@barseghyanartur
Copy link

An example would be appreciated.

@sl2c
Copy link

sl2c commented Sep 20, 2023

from pdfrw import PdfWriter, IndirectPdfDict, PdfDict, PdfName, PdfArray
pdf = PdfWriter()
page = IndirectPdfDict(
    Type = PdfName.Page,
    MediaBox = PdfArray([0,0,100,100]),
    Resources = PdfDict(
        Font = PdfDict(
            MyFont = IndirectPdfDict(
                Type = PdfName.Font,
                Subtype = PdfName.Type1,
                BaseFont = PdfName('Helvetica')
            )
        )
    ),
    Contents = IndirectPdfDict(
        stream = '/MyFont 12 Tf (Hello, World!) Tj'
    )
)
pdf.addPage(page)
pdf.write('hello.pdf')

UPD: corrected version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants