go-poppler icon indicating copy to clipboard operation
go-poppler copied to clipboard

pdfseparate possible or write specific pages?

Open G2G2G2G opened this issue 4 years ago • 1 comments

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

G2G2G2G avatar Oct 15 '20 17:10 G2G2G2G

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
}

jmbarbier avatar Feb 08 '22 18:02 jmbarbier