Skip to content

Commit

Permalink
Add page rotation to PDF info (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
jerbob92 committed Jan 16, 2024
1 parent ddba6d9 commit cf96541
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions cmd/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand All @@ -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,
})
}

Expand Down

0 comments on commit cf96541

Please sign in to comment.