Removing EXIF data from Images and Files

1
Hi all,   We need to remove the EXIF data from documents that is uploaded to our system. Anyone knows how this can be achieved? Currently, it the allowed extension types is either documents (PDF,  DOC & DOCX) and images.   I have seen that there is an Apache Commons ExifRewriter class (How can I remove metadata from a JPEG image in Java? - Stack Overflow) but this is limited to JPEGs and I am looking for a more encapsulating solution.   I have also attempted the following using a Java action, but it did not work: InputStream content = Core.getFileDocumentContent(getContext(), __fileToStrip); try { Core.storeFileDocumentContent(getContext(), fileToStrip.getMendixObject(), content); fileToStrip.commit(); } catch(Exception e){ }   Thanks in advanced!
asked
2 answers
0

Hi Nico,

 

I once created the PDF Parser widget. This widget contains operations to edit the metadata in PDF documents. I think you can use the code from Github and alter it to your needs. This would only work for the PDFs of course, you need other operations to do the same thing fod DOC and DOCX documents. Hope this helps. 

answered
0

I managed to remove the EXIF data from images using the following JAVA code:

 

public java.lang.Void executeAction() throws Exception
	{
		this.imageToStrip = this.__imageToStrip == null ? null : system.proxies.Image.initialize(getContext(), __imageToStrip);

		// BEGIN USER CODE
		BufferedImage img = ImageIO.read(Core.getImage(getContext(), __imageToStrip, false));
		ByteArrayOutputStream os = new ByteArrayOutputStream();
		ImageIO.write(img, getFileExtension(imageToStrip), os);
		Core.storeImageDocumentContent(getContext(), __imageToStrip, new ByteArrayInputStream(os.toByteArray()), 0, 0);
		
		return null;
		// END USER CODE
	}

Where,

	private static String getFileExtension(FileDocument file) throws Exception {
		String fileName = file.getName().toLowerCase();
		
		try {
			if(fileName.contains(".")) {
				java.lang.String extention = fileName.substring(fileName.lastIndexOf('.')+1);
				return extention;
			}
		}
		catch(Exception e) {
		}
		throw new Exception("");
	}

 

answered