Skip to content

Commit e2db5a7

Browse files
committed
Fix #1142
1 parent a22ca4a commit e2db5a7

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

pkg/pdfcpu/importImage.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ func ParseImportDetails(s string, u types.DisplayUnit) (*Import, error) {
255255
return imp, nil
256256
}
257257

258-
func importImagePDFBytes(wr io.Writer, pageDim *types.Dim, imp *Import) {
258+
func importImagePDFBytes(wr io.Writer, pageDim *types.Dim, imgWidth, imgHeight float64, imp *Import) {
259259

260260
vpw := float64(pageDim.Width)
261261
vph := float64(pageDim.Height)
@@ -270,14 +270,13 @@ func importImagePDFBytes(wr io.Writer, pageDim *types.Dim, imp *Import) {
270270
return
271271
}
272272

273-
w, h := vpw, vph
274273
if imp.DPI > 0 {
275274
// NOTE: We could also set "UserUnit" in the page dict.
276-
w *= float64(72) / float64(imp.DPI)
277-
h *= float64(72) / float64(imp.DPI)
275+
imgWidth *= float64(72) / float64(imp.DPI)
276+
imgHeight *= float64(72) / float64(imp.DPI)
278277
}
279278

280-
bb := types.RectForDim(w, h)
279+
bb := types.RectForDim(imgWidth, imgHeight)
281280
ar := bb.AspectRatio()
282281

283282
if imp.ScaleAbs {
@@ -362,7 +361,7 @@ func NewPagesForImage(xRefTable *model.XRefTable, r io.Reader, parentIndRef *typ
362361
mediaBox := types.RectForDim(dim.Width, dim.Height)
363362

364363
var buf bytes.Buffer
365-
importImagePDFBytes(&buf, dim, imp)
364+
importImagePDFBytes(&buf, dim, float64(imgRes.Width), float64(imgRes.Height), imp)
366365
sd, err := xRefTable.NewStreamDictForBuf(buf.Bytes())
367366
if err != nil {
368367
return nil, err

0 commit comments

Comments
 (0)