def test_html_images(self): pdf = MyFPDF() pdf.add_page() initial = 10 mm_after_image = initial + px2mm(300) self.assertEqual(round(pdf.get_x()), 10, "Initial x margin is not expected") self.assertEqual(round(pdf.get_y()), 10, "Initial y margin is not expected") self.assertEqual(round(pdf.w), 210, "Page width is not expected") img_path = relative_path_to( "../image/png_images/c636287a4d7cb1a36362f7f236564cef.png") pdf.write_html( "<center><img src=\"%s\" height='300' width='300'></center>" % img_path) # Unable to text position of the image as write html moves to a new line after # adding the image but it can be seen in the produce test.pdf file. self.assertEqual(round(pdf.get_x()), 10, "Have not moved to beginning of new line") self.assertAlmostEqual( pdf.get_y(), mm_after_image, places=2, msg="Image height has moved down the page", ) assert_pdf_equal(self, pdf, "test_html_images.pdf")
def test_html_images(self): pdf = MyFPDF() set_doc_date_0(pdf) pdf.add_page() rel = os.path.dirname(os.path.abspath(__file__)) img_path = rel + "/image/png_images/c636287a4d7cb1a36362f7f236564cef.png" initial = 10 mm_after_image = initial + px2mm(300) self.assertEqual(round(pdf.get_x()), 10, 'Initial x margin is not expected') self.assertEqual(round(pdf.get_y()), 10, 'Initial y margin is not expected') self.assertEqual(round(pdf.w), 210, 'Page width is not expected') pdf.write_html( "<center><img src=\"%s\" height='300' width='300'></center>" % img_path) # Unable to text position of the image as write html moves to a new line after # adding the image but it can be seen in the produce test.pdf file. self.assertEqual(round(pdf.get_x()), 10, 'Have not moved to beginning of new line') self.assertAlmostEqual(pdf.get_y(), mm_after_image, places=2, msg='Image height has moved down the page') pdf.output('test/test.pdf', "F") # comment to see view output after test known_good_hash = "663ecbb2c23d55d4589629039d394911" self.assertEqual(calculate_hash_of_file('test/test.pdf'), known_good_hash) os.unlink('test/test.pdf')
def test_html_images(tmp_path): pdf = MyFPDF() pdf.add_page() initial = 10 mm_after_image = initial + px2mm(300) assert round(pdf.get_x()) == 10 assert round(pdf.get_y()) == 10 assert round(pdf.w) == 210 img_path = HERE.parent / "image/png_images/c636287a4d7cb1a36362f7f236564cef.png" pdf.write_html( f"<center><img src=\"{img_path}\" height='300' width='300'></center>") # Unable to text position of the image as write html moves to a new line after # adding the image but it can be seen in the produce test.pdf file. assert round(pdf.get_x()) == 10 assert pdf.get_y() == pytest.approx(mm_after_image, abs=0.01) assert_pdf_equal(pdf, HERE / "html_images.pdf", tmp_path)