두 가지 간단한 단계를 통해 Java에서 html 파일을 DICOM 이미지로 변환할 수 있습니다. 먼저 Aspose.PDF for Java 를 사용하여 HTML을 JPEG로 내보낼 수 있습니다. 그런 다음 Aspose.Imaging for Java Image Processing API를 사용하여 JPEG를 DICOM로 렌더링할 수 있습니다. 두 API 모두 Java용 Aspose.Total 패키지에 있습니다.
Java를 통해 HTML을 DICOM로 내보내기
변환 요구 사항
Maven 기반 프로젝트에서 직접 Java용 Aspose.Total을 쉽게 사용할 수 있습니다. pom.xml에 라이브러리를 포함합니다.
또는 다운로드 에서 ZIP 파일을 받을 수 있습니다.
// supports PDF, CGM, EPUB, TeX, PCL, PS, XPS, MD, MHTML, XSLFO, HTML file formats | |
// load PDF with an instance of Document | |
Document document = new Document("input.pdf"); | |
// create an object of JpegDevice | |
JpegDevice renderer = new JpegDevice(); | |
// convert first of a particular PDF page to JPEG format | |
renderer.process(document.getPages().get_Item(1), "output.jpeg"); | |
// load JPEG file | |
Image image = Image.Load("output.jpeg"); | |
// supports Dicom, Jpeg2000, Apng, Psd, Dxf, Wmf, Emz, Wmz, Tga, Svgz file formats | |
// save JPEG to PSD file format | |
image.save("output.psd", new PsdOptions()); |
Java를 통해 단일 파일에서 HTML을 DICOM로 변환
API를 사용하면 HTML 파일을 단일 파일로 DICOM로 내보낼 수도 있습니다. 모든 페이지를 변환하려면 먼저 HTML 문서를 하나의 TIFF 파일로 렌더링한 다음 TIFF 파일을 DICOM로 내보낼 수 있습니다. Document 클래스를 사용하여 입력 파일을 열고 Resolution, TiffSettings 및 TIFF 장치 개체를 생성할 수 있습니다. process 를 사용하여 단일 TIFF 이미지를 얻을 수 있습니다. TiffDevice 클래스의 java.io.OutputStream-) 메서드입니다. 마지막으로 Image 클래스를 사용하여 TIFF 파일을 로드하고 save 메서드.
// supports PDF, CGM, EPUB, TeX, PCL, PS, XPS, MD, MHTML, XSLFO, HTML file formats | |
// load PDF with an instance of Document | |
Document pdfDocument = new Document("input.pdf"); | |
// Create Resolution object | |
Resolution resolution = new Resolution(300); | |
// Create TiffSettings object | |
TiffSettings tiffSettings = new TiffSettings(); | |
tiffSettings.setCompression(CompressionType.None); | |
tiffSettings.setDepth(ColorDepth.Default); | |
tiffSettings.setShape(ShapeType.Landscape); | |
// Create TIFF device | |
TiffDevice tiffDevice = new TiffDevice(resolution, tiffSettings); | |
// Convert a particular page and save the image to stream | |
tiffDevice.process(pdfDocument, 1, 1, "output.tif"); | |
// load TIFF file | |
Image image = Image.Load("output.tif"); | |
// supports Dicom, Jpeg2000, Apng, Psd, Dxf, Wmf, Emz, Wmz, Tga, Svgz file formats | |
// save TIFF to PSD file format | |
image.save("output.psd", new PsdOptions()); |
Java를 통해 워터마크를 사용하여 HTML을 DICOM로 변환
API를 사용하면 DICOM 문서에 워터마크가 있는 HTML 파일을 DICOM로 내보낼 수도 있습니다. 워터마크를 추가하려면 먼저 HTML을 JPEG로 변환하고 워터마크를 추가할 수 있습니다. 워터마크를 추가하기 위해서는 Image 클래스를 이용하여 이미지 파일을 불러오고, Graphics 클래스의 객체를 생성합니다. ://apireference.aspose.com/imaging/java/com.aspose.imaging/Graphics) 클래스를 생성하고 Image 객체로 초기화하고 새로운 Matrix 객체를 생성하고 번역 및 변형을 원하는 각도로 설정하고 Graphics.drawString 을 사용하여 워터마크를 추가합니다. drawString-java.lang.String-com.aspose.imaging.Font-com.aspose.imaging.Brush-float-float-) 메서드. 이미지에 워터마크를 추가한 후 JPEG를 DICOM 형식으로 저장할 수 있습니다.
// supports PDF, CGM, EPUB, TeX, PCL, PS, XPS, MD, MHTML, XSLFO, HTML file formats | |
// load PDF with an instance of Document | |
Document document = new Document("input.pdf"); | |
// create an object of JpegDevice | |
JpegDevice renderer = new JpegDevice(); | |
// convert first of a particular PDF page to JPEG format | |
renderer.process(document.getPages().get_Item(1), "output.jpeg"); | |
// load JPEG | |
Image image = Image.load("output.jpeg"); | |
// create and initialize an instance of Graphics class | |
Graphics graphics= new Graphics(image); | |
// create an instance of Font | |
Font font = new Font("Times New Roman", 16, FontStyle.Bold); | |
// create an instance of SolidBrush and set its properties | |
SolidBrush brush = new SolidBrush(); | |
brush.setColor(Color.getBlack()); | |
brush.setOpacity(100); | |
Size sz = graphics.getImage().getSize(); | |
// create an object of Matrix class for transformation | |
Matrix matrix = new Matrix(); | |
// first a translation then a rotation | |
matrix.translate(sz.getWidth() / 2, sz.getHeight() / 2); | |
matrix.rotate(-45.0f); | |
// set the Transformation through Matrix | |
graphics.setTransform(matrix); | |
// draw a string using the SolidBrush and Font objects at specific point | |
graphics.drawString("Watermark by Aspose.Imaging for Java", font, brush, 0, 0); | |
// supports Dicom, Jpeg2000, Apng, Psd, Dxf, Wmf, Emz, Wmz, Tga, Svgz file formats | |
// save JPEG to PSD file format | |
image.save("output.psd", new PsdOptions()); |
Java를 통해 HTML을 DICOM 파일로 변환 및 회전
API를 사용하여 필요에 따라 출력 DICOM 이미지를 회전할 수도 있습니다. Image.rotateFlip 메서드는 이미지를 90/180/270도 회전하고 이미지를 가로 또는 세로로 뒤집는 데 사용할 수 있습니다. 라이브러리는 모든 추악한 세부 사항을 캡슐화하면서 복잡한 작업을 수행하는 간단한 방법을 제공합니다. 이미지에 적용할 회전 및 뒤집기 유형을 지정할 수 있습니다. 이미지를 회전하고 뒤집으려면 Image 클래스를 사용하여 변환된 JPEG 이미지를 로드하고 Image를 호출하면 됩니다. 적절한 RotateFlipType 을 지정하면서 rotateFlip 메서드를 사용합니다.
// supports PDF, CGM, EPUB, TeX, PCL, PS, XPS, MD, MHTML, XSLFO, HTML file formats | |
// load PDF with an instance of Document | |
Document document = new Document("input.pdf"); | |
// create an object of JpegDevice | |
JpegDevice renderer = new JpegDevice(); | |
// convert first of a particular PDF page to JPEG format | |
renderer.process(document.getPages().get_Item(1), "output.jpeg"); | |
// load JPEG file | |
Image image = Image.Load("output.jpeg"); | |
// roate image | |
image.RotateFlip(RotateFlipType.Rotate270FlipNone); | |
// supports Dicom, Jpeg2000, Apng, Psd, Dxf, Wmf, Emz, Wmz, Tga, Svgz file formats | |
// save JPEG to PSD file format | |
image.save("output.psd", new PsdOptions()); |