Two Pilots™    Home  |  Navigation  |  Site Map  |  Products  |  Download  |  Prices  |  For Partners  |  Support

All forums · Statistics · Search ·

Two Pilots forum / For software developers / Advanced headers/footers
Author Message
# Posted: 2 Jul 2008 08:35

Two questions:

1. Is there a quick way to add multiline header/footer without having to calculate each line height and how many lines there are and then cutting up a string into separate lines etc?
I.e. ideally I would want to set a watermark/header by giving it a string that has crlf's inside it and it would automatically add new lines where the crlfs are.

2. I figured out how to add headers/footers into HTML converted pdfs (htmladdon). I'm wondering if its possible to add advanced headers/footers with HTML code. I.e. is there any way I can set a watermark using an HTML snippet "<b>test</b><br>" etc...

# Posted: 3 Jul 2008 02:51

You may do it this way:
- Create a watermark and fill up and bottom parts of it with needed text and graphics (pictures, etc). Top part would be a header, bottom - footer.
- Set top and bottom margins for HTML2PDF Addon object to the value enough to fit your header and footer.
- Load HTML document into addon and call ConvertPage method for each page
- Set created watermark to this page.

Here an eample on VBS, you will easy convert it to any language:

Set PDF = CreateObject("PDFCreatorPilot3.PDFDocument3")
Set HTML = CreateObject("HTML2PDFAddon.HTML2PDF2")
PDF.StartEngine "demo@demo", "demo"
PDF.AutoLaunch = TRUE
PDF.FileName = "test.pdf"

'*** create watermark
j = PDF.CreateWatermark
PDF.SwitchedToWaterMark = True
strHeader = "Some text, some graphics e.t.c."
l = PDF.PDFPAGE_Width / 2
l = l - PDF.PDFPAGE_GetTextWidth(strHeader) / 2
PDF.PDFPAGE_SetActiveFont "Verdana", FALSE, FALSE, FALSE, FALSE, 10, 0
PDF.PDFPAGE_SetRGBColor 1, 0, 0
'* draw top part (header)
PDF.PDFPAGE_Rectangle 0, 0, PDF.PDFPAGE_Width, 50
PDF.PDFPAGE_TextOut l, 10, 0.0, strHeader
'* draw bottom part (footer)
PDF.PDFPAGE_TextOut l, PDF.PDFPAGE_Height - 25, 0.0, strHeader
PDF.SwitchedToWaterMark = False

'*** now load document to addon and convert it
HTML.StartHTMLEngine "",""
HTML.ConnectToPDFLibrary PDF
'* here we set top and bottom margins for html page.
'* this is done to prevent converted html overlapping with header/footer
HTML.MarginTop = 50
HTML.MarginBottom = 50
HTML.LoadHTMLFile "d:downloads11.htm"
pages = HTML.TotalPageCount

for i=0 to pages-1
HTML.ConvertPage i
'* important: set watermark created to current page
PDF.PDFPAGE_WaterMark = j
if i<>pages-1 then HTML.SafeNewPage

Set HTML = nothing
Set PDF = nothing

# Posted: 3 Jul 2008 04:21

Yes, that's the part I said that I already figured out. I asked two things which your code doesn't address: multiline headers/footers using crlf's and/or HTML-formatted headers/footers.

# Posted: 3 Jul 2008 04:50

1) There is no such method that splits text by CRLF, but if you use watermark as header/footer then multy-lined text can be drawn as at usual PDF canvas: you may use PDFPAGE_TextOutBox or PDFPAGE_TextOutBox2 methods (output wrapped text), maybe it'll help you.

2) If you want to make headers/footers from html, then just convert this html content not to page but to the watermark: create watermark, switch to it, load html, convert it, switch to page, draw your page.

# Posted: 3 Jul 2008 06:09

Thanks for the reply. The remaining question is can I convert two HTML files into the same PDF, one into the watermark, and the second into the page?

# Posted: 3 Jul 2008 06:20

Sure you can.
Just convert 1st file while in watermark mode and the 2nd while in page mode:
- PDF.SwitchedToWaterMark = True (watermark mode)
- load 1st html file in addon
- convert html to watermark
- call addon's method UnloadAll to clear all loaded data
- PDF.SwitchedToWaterMark = False (page mode)
- load 2nd html file in addon
- convert html to page



Powered by miniBB 2.0 RC7 © 2001-2004 Page creation time (sec.): 0.015


Page top