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

If the PDF generated from my HTML file has a cover and the generated directory is right in front of the cover, how can I make the generated directory on the second page? I tried to generate the cover as a separate HTML and the content as another HTML, but there was an issue with the PDF as both the table of contents and content were missing, #123

Open
yiqiui opened this issue Jun 14, 2024 · 1 comment

Comments

@yiqiui
Copy link

yiqiui commented Jun 14, 2024

If the PDF generated from my HTML file has a cover and the generated directory is right in front of the cover, how can I make the generated directory on the second page? I tried to generate the cover as a separate HTML and the content as another HTML, but there was an issue with the PDF as both the table of contents and content were missing,

//// 配置报告封面
//coverFile, err := templates.Templates.ReadFile("configure_report_cover.html")
//if err != nil {
//	panic(err)
//}
//// 添加页面
//coverPage := wkhtmltopdf.NewPageReader(bytes.NewReader(coverFile))
//coverPage.HeaderLeft.Set("Clinflash IRT  配置报告 ")
//coverPage.FooterLeft.Set("项目编号(项目环境)")
//coverPage.FooterRight.Set("[page]/[toPage]")
//coverPage.FooterFontSize.Set(10)
//coverPage.Zoom.Set(1)
//pdfg.AddPage(coverPage)

// 添加目录页面
pdfg.TOC.Include = true
pdfg.TOC.TocHeaderText.Set("目录")

// 配置报告内容
contentFile, err := templates.Templates.ReadFile("configure_report_content.html")
if err != nil {
	panic(err)
}
// 添加页面
contentPage := wkhtmltopdf.NewPageReader(bytes.NewReader(contentFile))

// 设置页眉和页脚选项
contentPage.HeaderLeft.Set("Clinflash IRT  配置报告 ")
contentPage.FooterLeft.Set("项目编号(项目环境)")
contentPage.FooterRight.Set("[page]/[toPage]")
contentPage.FooterFontSize.Set(10)
contentPage.Zoom.Set(1)
pdfg.AddPage(contentPage)

// 生成 PDF 文件
err = pdfg.Create()
if err != nil {
	panic(err)
}
@SebastiaanKlippert
Copy link
Owner

Hi, thanks for you comment.

I don't fully understand what you are trying to do, I believe there are two questions here.
One is that you have a problem with you TOC not appearing correctly if you also have a cover page?
And I also see you have trouble combining two input pages.

The second question I can answer, it looks like you are trying to add multiple pages as "Reader" in this example code. If you uncomment the first section, the second AddPage call will indeed not work.
See #54 for more information. There is also a workaround there that might work for you. Basically you need to make sure you have combined your pages into one HTML document first, before you add it to wkhtmltopdf.

I am not sure why your TOC is not working though, maybe you can share an example output of that.

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