From cf96541995f343f0b9cdfe9f97fca7caca5849e0 Mon Sep 17 00:00:00 2001 From: jerbob92 Date: Tue, 16 Jan 2024 04:58:08 -0800 Subject: [PATCH] Add page rotation to PDF info (#33) --- cmd/info.go | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/cmd/info.go b/cmd/info.go index 36d014b..29229d5 100644 --- a/cmd/info.go +++ b/cmd/info.go @@ -78,10 +78,11 @@ var infoCmd = &cobra.Command{ } type pdfPage struct { - Number int - Width float64 - Height float64 - Label string + Number int + Width float64 + Height float64 + Label string + Rotation int } type pdfSignature struct { @@ -153,6 +154,19 @@ var infoCmd = &cobra.Command{ return } + rotation, err := pdf.PdfiumInstance.FPDFPage_GetRotation(&requests.FPDFPage_GetRotation{ + Page: requests.Page{ + ByIndex: &requests.PageByIndex{ + Document: document.Document, + Index: i, + }, + }, + }) + if err != nil { + handleError(cmd, fmt.Errorf("could not get page rotation for page %d of PDF %s: %w\n", i+1, args[0], newPdfiumError(err)), ExitCodePdfiumError) + return + } + label := "" pageLabel, err := pdf.PdfiumInstance.FPDF_GetPageLabel(&requests.FPDF_GetPageLabel{ Document: document.Document, @@ -163,10 +177,11 @@ var infoCmd = &cobra.Command{ } pdfInfo.Pages = append(pdfInfo.Pages, pdfPage{ - Number: i + 1, - Width: pageSize.Width, - Height: pageSize.Height, - Label: label, + Number: i + 1, + Width: pageSize.Width, + Height: pageSize.Height, + Label: label, + Rotation: int(rotation.PageRotation) * 90, }) }