web stats
Scale image to fit in Document Writer - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 07-13-2017, 01:38 AM
rauchj rauchj is offline
OBX.1 Kenobi
 
Join Date: Feb 2014
Location: Freiburg, Germany
Posts: 43
rauchj is on a distinguished road
Default 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 at 01:44 AM.
Reply With Quote
  #2  
Old 07-17-2017, 04:09 AM
siddharth siddharth is offline
Mirth Guru
 
Join Date: Feb 2013
Posts: 835
siddharth is on a distinguished road
Default

That's a good question!

Following the lead on this thread,
https://stackoverflow.com/questions/...per-size-pages

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.
http://developers.itextpdf.com/examp...ocks/page-size
Reply With Quote
  #3  
Old 07-19-2017, 08:05 AM
rauchj rauchj is offline
OBX.1 Kenobi
 
Join Date: Feb 2014
Location: Freiburg, Germany
Posts: 43
rauchj is on a distinguished road
Default

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();
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 01:19 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Mirth Corporation