Puede convertir un archivo mhtml a una imagen DICOM en Java en dos simples pasos. En primer lugar, al usar Aspose.PDF para Java , puede exportar MHTML a JPEG. Después de eso, al usar Aspose.Imaging for Java API de procesamiento de imágenes, puede convertir JPEG a DICOM. Ambas API se incluyen en el paquete Aspose.Total for Java .
Exportar MHTML a DICOM a través de Java
- Abra el archivo MHTML usando la clase Document
- Inicialice el objeto de clase y renderice MHTML a JPEG mediante [Process]( https://reference.aspose.com/pdf/java/com.aspose.pdf.devices/JpegDevice#process-com . método aspose.pdf.Page-java.io.OutputStream-)
- Cargue el archivo JPEG usando la clase Imagen
- Guarde el documento en formato DICOM usando save método
Requisitos de conversión
Puede usar fácilmente Aspose.Total para Java directamente desde un proyecto basado en Maven
Alternativamente, puede obtener un archivo ZIP de descargas .
// 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()); |
Convierta MHTML a DICOM en un solo archivo a través de Java
La API también le permite exportar archivos MHTML a DICOM a un solo archivo. Para convertir todas las páginas, primero puede convertir su documento MHTML en un archivo TIFF y luego puede exportar el archivo TIFF a DICOM. Puede abrir el archivo de entrada usando la clase Document y crear objetos de dispositivo Resolución, TiffSettings y TIFF. Puede obtener una sola imagen TIFF usando [proceso]( https://reference.aspose.com/pdf/java/com.aspose.pdf.devices/TiffDevice#process-com.aspose.pdf.IDocument-int-int- método java.io.OutputStream-) de la clase TiffDevice . Finalmente, puede cargar el archivo TIFF usando la clase Imagen y guardarlo en formato DICOM usando 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()); |
Convierta MHTML a DICOM con marca de agua a través de Java
Con la API, también puede exportar un archivo MHTML a DICOM con marca de agua en su documento DICOM. Para agregarle una marca de agua, primero puede convertir MHTML a JPEG y agregarle una marca de agua. Para agregar una marca de agua, cargue un archivo de imagen usando la clase Imagen , cree un objeto de Graphics e inicialícela con el objeto Image, cree una nueva Matrix y configure la traducción y transformación al ángulo deseado y agregue una marca de agua usando [Graphics.drawString]( https://reference.aspose.com/imaging/java/com.aspose.imaging/Graphics# método drawString-java.lang.String-com.aspose.imaging.Font-com.aspose.imaging.Brush-float-float-). Después de agregar la marca de agua en su imagen, puede guardar el JPEG como formato 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()); |
Convertir y rotar archivos MHTML a DICOM a través de Java
Usando la API, también puede rotar la imagen DICOM de salida según sus necesidades. El método Image.rotateFlip se puede utilizar para rotar la imagen 90/180/270 grados y voltear la imagen horizontal o verticalmente. La biblioteca proporciona métodos simples para realizar operaciones complejas mientras encapsula todos los detalles desagradables. Puede especificar el tipo de rotación y volteo para aplicar a la imagen. Para rotar y voltear la imagen, puede cargar la imagen JPEG convertida usando la clase Imagen y llamar a la imagen. giratorio mientras especifica el RotateFlipType .
// 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()); |