working on it ...
Explore Public Snippets
Found 4 snippets
public by johansonkatherine 4814 2 6 2
Load Existing Email Message and Modify its Contents inside Android Apps
This technical tip shows how to load any existing email message and modify its contents before saving it back to disk using Aspose.Email for Android API. To do this successfully, specify the MessageFormat when loading the email message from disk. In addition, it is important to specify the correct MailMessageSaveType when saving the message back to
public static void UpdateAndSaveEmail() { // Base folder for reading and writing files String strBaseFolder = Environment.getExternalStorageDirectory().getPath(); strBaseFolder = strBaseFolder + "/"; //Initialize and load an existing MSG file by specifying the MessageFormat MailMessage email = MailMessage.load(strBaseFolder + "anEmail.msg", MessageFormat.getMsg()); //Initialize a String variable to get the Email Subject String subject = email.getSubject(); //Append some more information to Subject subject = subject + " This text is added to the existing subject"; //Set the Email Subject email.setSubject(subject); //Initialize a String variable to get the Email's HTML Body String body = email.getHtmlBody(); //Apppend some more information to the Body variable body = body + "<br> This text is added to the existing body"; //Set the Email Body email.setHtmlBody(body); //Initialize MailAddressCollection object MailAddressCollection contacts = new MailAddressCollection(); //Retrieve Email's TO list contacts = email.getTo(); //Check if TO list has some values if (contacts.size() > 0) { //Remove the first email address contacts.remove(0); //Add another email address to collection contacts.add("to1@domain.com"); } //Set the collection as Email's TO list email.setTo(contacts); //Initialize MailAddressCollection contacts = new MailAddressCollection(); //Retrieve Email's CC list contacts = email.getCC(); //Add another email address to collection contacts.add("cc2@domain.com"); //Set the collection as Email's CC list email.setCC(contacts); //Save the Email message to disk by specifying the MessageFormat email.save(strBaseFolder + "message.msg", MailMessageSaveType.getOutlookMessageFormat());
public by johansonkatherine 4879 0 6 3
Java code for Changing Color Space of PDF Document
This code shows how java developers can change color space of PDF document from RGB color to CMYK and vice versa by using Aspose.PDF for Java Library. The following methods have been implemented in the Operator class for changing colors. Use it to change some specific RGB/CMYK colors to CMYK/RGB color space, keeping the remaining PDF document as it
Document doc = new Document(myDir + "input_color.pdf"); OperatorCollection contents = doc.getPages().get_Item(1).getContents(); System.out.println("Values of RGB color operators in the pdf document"); for (int j = 1; j <= contents.size(); j++) { Operator oper = contents.get_Item(j); if (oper instanceof Operator.SetRGBColor || oper instanceof Operator.SetRGBColorStroke) try { //Converting RGB to CMYK color System.out.println(oper.toString()); double[] rgbFloatArray = new double[] { Double.valueOf(oper.getParameters().get(0).toString()), Double.valueOf(oper.getParameters().get(1).toString()), Double.valueOf(oper.getParameters().get(2).toString()), }; double[] cmyk = new double[4]; if (oper instanceof Operator.SetRGBColor) { ((Operator.SetRGBColor)oper).getCMYKColor(rgbFloatArray, cmyk); contents.set_Item(j, new Operator.SetCMYKColor(cmyk[0], cmyk[1], cmyk[2], cmyk[3])); } else if (oper instanceof Operator.SetRGBColorStroke) { ((Operator.SetRGBColorStroke)oper).getCMYKColor(rgbFloatArray, cmyk); contents.set_Item(j, new Operator.SetCMYKColorStroke(cmyk[0], cmyk[1], cmyk[2], cmyk[3])); } else throw new java.lang.Throwable("Unsupported command"); } catch (Throwable e) { e.printStackTrace(); } } doc.save(myDir + "input_colorout.pdf"); //Testing the result System.out.println("Values of converted CMYK color operators in the result pdf document"); doc = new Document(myDir + "input_colorout.pdf"); contents = doc.getPages().get_Item(1).getContents(); for (int j = 1; j <= contents.size(); j++) { Operator oper = contents.get_Item(j); if (oper instanceof Operator.SetCMYKColor || oper instanceof Operator.SetCMYKColorStroke) { System.out.println(oper.toString()); } }
public by johansonkatherine 2877 1 6 2
Java Code Sample to Create PDF from HTML Using REST API
This code sample shows how Java developers can create PDF file from HTML using Aspose.Pdf for Cloud API in their REST applications.
//build uri to create empty pdf String strURI = "http://api.aspose.com/v1.1/pdf/outPdfFile.pdf?templateFile=input.html&templateType=html"; String signedURI = Sign(strURI); InputStreamresponseStream = ProcessCommand(signedURI, "PUT"); String strJSON = StreamToString(responseStream); Gsongson = new Gson(); //Parse the json string to JObject and Deserializes the JSON to a object. BaseResponsebaseResponse = gson.fromJson(strJSON,BaseResponse.class); if (baseResponse.getCode().equals("200") &&baseResponse.getStatus().equals("OK")) System.out.println("Empty PDF file has been created successfully"); //Here is the BaseResponse class public class BaseResponse { publicBaseResponse() { } private String Code; private String Status; public String getCode(){return Code;} public String getStatus(){return Status;} public void setCode(String temCode){ Code=temCode;} public void setStatus(String temStatus){ Status=temStatus;} }
public by johansonkatherine 3172 0 6 1
How to Convert MemoryStream Image to PDF inside Android Applications
This technical tip shows how developers can convert MemoryStream image to PDF file inside their Android application. The Image class in Aspose.Pdf makes it possible to convert an image from various sources into PDF format. This may include an image from particular location over the hard-drive, an image from MemoryStream or an image at a web locatio
try { // Create PDF document Pdfpdf = new Pdf(); // Add a section into the PDF document Section sec1 = pdf.getSections().add(); byte[] fileArray = null; //=====================================================// // Get the Image contents into Byte Array //=====================================================// try { fileArray = getBytesFromFile(new File("/mnt/sdcard/Aspose.jpg")); } catch (IOException e) { e.printStackTrace(); } // Create an image object in the section aspose.pdf.Image img1 = new aspose.pdf.Image(sec1); // Add image object into the Paragraphs collection of the section sec1.getParagraphs().add(img1); // Set the Image file type img1.getImageInfo().setImageFileType(ImageFileType.Jpeg); // Create a BinayFileStream Object to hold byte array BinaryFileStreambstream = new BinaryFileStream(fileArray); // Set the image object to use BinaySgtream object img1.getImageInfo().setImageStream(bstream); // Save the PDF file pdf.save("/mnt/sdcard/Image2PDF.pdf"); }catch(java.io.IOExceptionioe){ System.out.println(ioe.getMessage()); }catch(Exception e){ System.out.println(e.getMessage()); } } //=====================================================// // Method Returns the contents of file in a byte array //=====================================================// private static byte[] getBytesFromFile(File file) throws IOException { InputStream is = new FileInputStream(file); // Get the size of the file long length = file.length(); /* * Ensure that file is not loarger than Integer.MAX_VALUE; */ if (length >Integer.MAX_VALUE) { System.out.println("File is too large to process"); return null; } // Create the byte array to hold the data byte[] bytes = new byte[(int)length]; // Read in the bytes int offset = 0; intnumRead = 0; while ( (offset <bytes.length) && ( (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) ) { offset += numRead; } // Ensure all the bytes have been read in if (offset <bytes.length) { throw new IOException("Could not completely read file " + file.getName()); } is.close(); return bytes; }