Skip to content

Create SingleImageToPdf transformer #24

@mykolamelnykml

Description

@mykolamelnykml

Need to implement SingleImageToPdf transformer for convert single image to the single page pdf.

Please use img2pdf package.

It should have following params:

  • inputCol
  • outputCol
  • resolution

Please use HasOutputCol, HasInputCol, HasResolution classes. For example:

class SingleImageToPdf(Transformer, DefaultParamsReadable, DefaultParamsWritable, HasOutputCol, HasInputCol, HasResolution):

And should use following code for transform image to pdf:

imageResolution = image.resolution
if imageResolution == 0 or imageResolution is None:
imageResolution = 300
if self.getResolution() > 0:
imageResolution = self.getResolution()

width = image.width / imageResolution * self.POINTS_PER_INCH
height = image.height / imageResolution * self.POINTS_PER_INCH

a4inpt = (img2pdf.mm_to_pt(210), img2pdf.mm_to_pt(297))
layout_fun = img2pdf.get_layout_fun(a4inpt)
pdf_bytes = img2pdf.convert(io.BytesIO(image.data), layout_fun=layout_fun)

And create good test coverage for Spark and Local pipelines.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

Status

Backlog

Relationships

None yet

Development

No branches or pull requests

Issue actions