mirror of
https://github.com/unidoc/unipdf.git
synced 2025-04-29 13:48:54 +08:00
52 lines
1009 B
Go
52 lines
1009 B
Go
/*
|
|
* This file is subject to the terms and conditions defined in
|
|
* file 'LICENSE.md', which is part of this source code package.
|
|
*/
|
|
|
|
package creator
|
|
|
|
import (
|
|
"os"
|
|
|
|
"github.com/unidoc/unidoc/pdf/model"
|
|
)
|
|
|
|
func dimensionsMMtoPoints(dimensionsMM [2]float64, ppi float64) [2]float64 {
|
|
width := dimensionsMM[0] / 25.4 * ppi
|
|
height := dimensionsMM[1] / 25.4 * ppi
|
|
return [2]float64{width, height}
|
|
}
|
|
|
|
// Loads the template from path as a list of pages.
|
|
func loadPagesFromFile(path string) ([]*model.PdfPage, error) {
|
|
// Read the input pdf file.
|
|
f, err := os.Open(path)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer f.Close()
|
|
|
|
pdfReader, err := model.NewPdfReader(f)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
numPages, err := pdfReader.GetNumPages()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// Load the pages.
|
|
pages := []*model.PdfPage{}
|
|
for i := 0; i < numPages; i++ {
|
|
page, err := pdfReader.GetPage(i + 1)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
pages = append(pages, page)
|
|
}
|
|
|
|
return pages, nil
|
|
}
|