Scale image to fit in Document Writer

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • rauchj
    OBX.1 Kenobi
    • Feb 2014
    • 47

    Scale image to fit in Document Writer

    Hi everyone,

    I'm trying insert a DICOM image to a PDF-Report with Document Writer (mirth 3.4.0). The Image has a resolution of 1024x786 pixels, the page size of the document writer is A4. The Image is cropped when the PDF is rendered by the Document Writer.

    Is there a way to scale the image to fit the page automatically? Or do i need to scale the image before inserting in the PDF?

    thanks in advance!
    Last edited by rauchj; 07-13-2017, 12:44 AM.
  • siddharth
    Mirth Guru
    • Feb 2013
    • 945

    #2
    That's a good question!

    Following the lead on this thread,


    I used this HTML code in the template, and that does generate a document.

    <table width="42.0cm" height="59.4cm">
    <tr>${message.encodedData}</tr>
    </table>

    But the properties of the pdf shows A4 measurements instead of A2, rather multiple A4 sheets. So it looks like working but it does not. You could use a combination of CSS and HTML together to auto scale document based on the size, but I doubt that will work either.

    I think you could use iText 2.1.7 API in a JS writer destination, which is what mirth internally uses to create PDFs through Document writer.

    Something on these lines.
    HL7v2.7 Certified Control Specialist!

    Comment

    • rauchj
      OBX.1 Kenobi
      • Feb 2014
      • 47

      #3
      So i did some research:

      While a bitmap-image (like jpg) has a resolution, PDF does not. Only when a PDF is rendered eg for displaying on a screen or for printing, the resolution (DPI) matters.

      Now: My image has a resolution of 1024x768 pixels. A normal DPI for displaying or printing is 96dpi, which means 1024px / 96dpi = 10.66 inch ~27cm would be the dimension of this image.

      With a A4 Paper in Portrait (21cm width) and margins of 1cm, the usable space is 19cm => 19cm/27cm = 0.7 -> I need to scale the image to 70% that it fits the A4 page. Or choose a higher page size (like A2). Unfortunatly the setting "Page Size" in Document Writer for PDF does not affect the PDF, only when css style "@page" is used.

      further reading: http://developers.itextpdf.com/conte...ion-images-pdf

      if someone finds this useful, this is a javascript for document writer in Javascript writer destination:

      Code:
      // http://grepcode.com/snapshot/repo1.maven.org/maven2/com.lowagie/itext/2.1.7
      importPackage(com.lowagie.text);
      importPackage(com.lowagie.text.pdf);
      
      var document = new Document(PageSize.A4, 10, 10, 10, 10);
      
      PdfWriter.getInstance(document, new java.io.FileOutputStream(Packages.java.io.File("c://temp//document_writer.pdf")));
      document.open();
      //p = new Paragraph("Hi");
      
      img1 = new Image.getInstance("c://temp//dicom//convert - Kopie//81708188_20170714125534_1.jpg");
      img2 = new Image.getInstance("c://temp//dicom//convert - Kopie//81708188_20170714125534_2.jpg");
      img3 = new Image.getInstance("c://temp//dicom//convert - Kopie//81708188_20170714125534_3.jpg");
      
      //img1.scaleToFit(PageSize.A2.getWidth(), PageSize.A2.getHeight());
      //img2.scaleToFit(PageSize.A2.getWidth(), PageSize.A2.getHeight());
      //img3.scaleToFit(PageSize.A2.getWidth(), PageSize.A2.getHeight());
      
      //document.add(p);
      document.add(img1);
      document.newPage();
      document.add(img2);
      document.newPage();
      document.add(img3);
      document.close();

      Comment

      Working...
      X