Open MarErm27 opened 4 years ago
My guess is that nrPages := len(imp.GetPageSizes())
is for some reason not returning the number of pages. (Any comment, @phpdave11?) I think pdf.PageCount()
will always return the number of times pdf.AddPage()
is called, and in this case, it will be limited to the value of nrPages.
Small hint unrelated to the issue: os.Open()
returns an os.File which implements the io.ReadSeeker interface. You could use this in your call to imp.ImportPageFromStream()
instead of reading all bytes into one large array and then streaming them out with a bytes.Reader.
I came to this code
func isValueInList(value string, list []string) int {
for i, v := range list {
if strings.Contains(v, value) {
return i
}
}
return -1
}
out, err := exec.Command("pdfinfo.exe", DocName).Output()
if err != nil {
log.Fatal(err)
}
fmt.Printf("The date is %s\n", out)
str := string(out)
s := strings.Split(str, "\n")
x := "Pages"
indexOfPages := isValueInList(x, s)
fmt.Println(indexOfPages)
if indexOfPages != -1 {
pages := strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll(s[indexOfPages], "Pages:", ""), " ", ""), "\r", "")
i, err := strconv.Atoi(pages)
if err != nil {
fmt.Println(err)
}
fmt.Println(i)
fmt.Println(i < 8)
}
pdfinfo.exe is from this open source project http://www.xpdfreader.com/download.html Thank you very much
Hello everyone! This is my first question at Github! My task is to check how many pages contain a pdf document and if it has less than 8 pages print it silently. I'm using this imports
and code below