Welcome Guest Search | Active Topics | Sign In | Register

PDF as template Options
Bernhard Queißer
Posted: Tuesday, December 14, 2021 5:19:36 AM
Rank: Newbie
Groups: Member

Joined: 8/6/2021
Posts: 5
Hallo EO.PDF Team,

I have a question, I would like to load sections of text into a PDF that contains a template as a background. It works very well on the first page, from the second page on I get an empty PDF with the text. How can I set the PDF template for each page?

Greetings from Germany
Bernhard

Dim doc As New PdfDocument(App.path+"\PDFMERGE\PDF_DRV_BERICHT\PDF_MERGE_BLATT1A1.PDF")

'Set the document information
doc.Info.Title = "EO.Pdf Sample PDF file"
doc.Info.Creator = "EO.Pdf Library"
doc.Info.Author = "EO.Pdf"


'Hide the toolbar
doc.ViewerPreference.HideToolbar = True

Dim lay As New AcmPageLayout(New SizeF(8.2, 11.69), New AcmPadding(1, 1.57, 0.5, 1))

'Create a new AcmRender object
Dim render As New AcmRender(doc, lay)
doc.Fields("PNAME").Value = "Peter Mustermann"


Dim Text(20) As AcmText
Dim Titel(20) As AcmText

'Create a new text object
For x As Integer = 0 To 20

Titel(x) = New AcmText("That is title nr." + x.ToString)
Titel(x).Style.FontStyle = FontStyle.Bold
Text(x) = New AcmText("Lorem Ypsum.")
Text(x).Style.ForegroundColor = Color.Black
render.Render(Titel(x))
render.Render(Text(x))

Next x
MsgBox(doc.Pages.Count.ToString)
'Save the result
doc.Save("d:\test.pdf")
eo_support
Posted: Tuesday, December 14, 2021 9:06:20 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,217
Hi,

If your template PDF file is only one page, then you must expand it to the exact number of pages as your output. So for example, if your final output is 3 pages, then you must expand your template PDF file to 3 pages first. You can use PdfDocument.Merge to merge the file into 3 pages:

Code: Visual Basic.NET
Dim docs(3) As PdfDocument

For i As Integer = 0 To docs.Length - 1
     docs(i) = New PdfDocument(template_file_path)
Next

Dim template As PdfDocument = PdfDocument.Merge(docs)


After that you can use AcmRender to render into template.

If you do not know exactly how many pages your result will be, you can run your rendering code twice --- the first time to get how many pages you have. The second time uses the correct template.

Hope this helps. Please feel free to let us know if you have any questions.

Thanks!
Bernhard Queißer
Posted: Tuesday, December 14, 2021 9:35:40 AM
Rank: Newbie
Groups: Member

Joined: 8/6/2021
Posts: 5
Thank YOU!!!!
eo_support
Posted: Tuesday, December 14, 2021 10:09:06 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,217
You are welcome. Please feel free to let us know if there is anything else.


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.