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

pdfseparate possible or write specific pages? #12

Open
G2G2G2G opened this issue Oct 15, 2020 · 1 comment
Open

pdfseparate possible or write specific pages? #12

G2G2G2G opened this issue Oct 15, 2020 · 1 comment

Comments

@G2G2G2G
Copy link

G2G2G2G commented Oct 15, 2020

In poppler it has "pdfseparate"
you can run something like:
pdfseparate main_pdf.pdf pdf_page_%d.pdf
This gives you pdf_page_1.pdf ..2..3.. etc

Or alternatively writing a page, right now you can grab a pdffile like:

pdf, err := poppler.Open("file.pdf");
pageCount := pdf.GetNPages();
for i := 0; i < pageCount; i++ {
	pdfPage := pdf.GetPage(i);
	//write pdfPage to a file?
}

above could allow you to write specific pages if you had an if statement searching for some text() or something as well..
Is there a way to do this? Thank you

@jmbarbier
Copy link

Late hint : using cairo PDFSurface we can output a page into a file. For example

func Convert2Pdf(pgs []*Page, dest string) string {
	width, height := pgs[0].Size()
	surface := cairo.NewPDFSurface(dest, width, height, cairo.PDF_VERSION_1_5)
	defer surface.Finish()
	for _, pge := range pgs {
		_, ctx := surface.Native()
		//goland:noinspection GoVetUnsafePointer
		C.poppler_page_render_for_printing(pge.p, (*C.cairo_t)(unsafe.Pointer(ctx)))
		surface.ShowPage()
	}
	return dest
}

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