public void save()
{ Presentation pres = new Presentation(filename);
ISlide slide = pres.getSlides().get_Item(0);
IShape shape= null;
for (int i = 0 ; i < slide.getShapes().size() ; i++)
{ shape = slide.getShapes().get_Item(i);
if (shape.getPlaceholder() != null)
{
((IAutoShape)shape).getTextFrame().setText(txtArea.getText());
}
}
pres.save(filename,SaveFormat.Ppt);
}
This code is for changing the text but it's not working. I have used two APIs at a time, display code is below:
public void Display(int currentPage, String source)
{
try {
// Create a slideshow object; this creates an underlying POIFSFileSystem object for us
SlideShow ppt = new SlideShow(new HSLFSlideShow(source));
current=currentPage;
// Get all of the slides from the PPT file
Slide[] slides = ppt.getSlides();
Dimension pgsize = ppt.getPageSize();
all = slides.length;
String temp="";
lblPage.setText(currentPage+" / "+all);
BufferedImage img = new BufferedImage(pgsize.width, pgsize.height, BufferedImage.TYPE_INT_RGB);
Graphics2D graphics = img.createGraphics();
graphics.setPaint(Color.white);
graphics.fill(new Rectangle2D.Float(0, 0, pgsize.width, pgsize.height));
//render
slides[currentPage-1].draw(graphics);
//save the output
/*FileOutputStream out = new FileOutputStream("slide-" + (i + 1) + ".png");
javax.imageio.ImageIO.write(img, "png", out);
out.close();
//ImageIcon icon = new ImageIcon("slide-" + (i + 1) + ".png");*/
ImageIcon icon = new ImageIcon(img);
lblPresentasi.setIcon(icon);
// Obtain metrics about the slide: its number and name
int number = slides[currentPage-1].getSlideNumber();
String title = slides[currentPage-1].getTitle();
// Obtain the embedded text in the slide
TextRun[] textRuns = slides[currentPage-1].getTextRuns();
System.out.println("Slide " + number + ": " + title);
System.out.println("\tText Runs");
txtArea.setText("Slide : " + number + " Title : " + title + "\n");
for (int j = 0; j < textRuns.length; j++) {
// Display each of the text runs present on the slide
System.out.println("\t\t" + j + ": " + textRuns[j].getText());
temp=txtArea.getText();
txtArea.setText(temp+"\t\t" + textRuns[j].getText() + "\n");
}
// Obtain the notes for this slide
System.out.println("\tNotes: ");
Notes notes = slides[currentPage-1].getNotesSheet();
if (notes != null) {
// Notes are comprised of an array of text runs
TextRun[] notesTextRuns = notes.getTextRuns();
for (int j = 0; j < notesTextRuns.length; j++) {
System.out.println("\t\t" + notesTextRuns[j].getText());
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
Can anyone please help, I am trying to make a simple powerpoint editor in Java.
I want to change text in textarea press save button so text has to change and call display function.
I have observed your sample code and like to share that as far as code related to Aspose.Slides is concerned, there is no issue and it is perfectly right. You can verify this by opening the saved presentation with changed text in PowerPoint. If you encounter any issue in this, we will be glad to help you further. You may also contact us in Aspose.Slides support forums as well.
I work with Aspose as Developer evangelist.
Related
I'm trying to grab the frames from a video and put them into a collection of BufferedImage so I can use the images later. I tried to use the code in the second answer for this question, but it wasn't really helpful because the code they provided only grabs the first frame. How would I extract all the frames and put them into a collection?
So, a little bit of Googling (and reading the source code), was I able to hobble together this basic concept.
The "obvious" solution was to loop over the frames in the video and extract them, the "un-obvious" solution was "how"?!
The two methods you need are FFmpegFrameGrabber#getLengthInFrames and FFmpegFrameGrabber#setFrameNumber, from there it's just a simple method of converting the current frame and writing it to a file (which has already been demonstrated from the previous question)
File videoFile = new File("Storm - 106630.mp4");
FFmpegFrameGrabber frameGrabber = new FFmpegFrameGrabber(videoFile.getAbsoluteFile());
frameGrabber.start();
Java2DFrameConverter c = new Java2DFrameConverter();
int frameCount = frameGrabber.getLengthInFrames();
for (int frameNumber = 0; frameNumber < frameCount; frameNumber++) {
System.out.println("Extracting " + String.format("%04d", frameNumber) + " of " + String.format("%04d", frameCount) + " frames");
frameGrabber.setFrameNumber(frameNumber);
Frame f = frameGrabber.grab();
BufferedImage bi = c.convert(f);
ImageIO.write(bi, "png", new File("Frame " + String.format("%04d", frameNumber) + "-" + String.format("%04d", frameCount) + ".png"));
}
frameGrabber.stop();
Now, obviously, you could store the images into some kind of List in memory, just beware, depending on the size and length of the original video, this might run you into memory issues.
You can use OpenCV to extract frames in a video, try the below code. input is the video file path of your computer
VideoCapture cap = new VideoCapture();
String output = "resources/output";
cap.open(input);
int video_length = (int) cap.get(Videoio.CAP_PROP_FRAME_COUNT);
int frames_per_second = (int) cap.get(Videoio.CAP_PROP_FPS);
Mat frame = new Mat();
if (cap.isOpened()) {
System.out.println("Video is opened");
System.out.println("Number of Frames: " + video_length);
System.out.println(frames_per_second + " Frames per Second");
System.out.println("Converting Video to images...");
cap.read(frame);
int frame_number = 0;
while (cap.read(frame)) {
Imgcodecs.imwrite(output + "/" + frame_number + ".jpg", frame);
frame_number++;
}
cap.release();
processingStatus = video_length + " Frames extracted";
System.out.println(processingStatus);
} else {
processingStatus = "Failed";
System.out.println(processingStatus);
}
I am developing an rsps and cant seem to find where to find the background image
i found the loading screen but cant find the background image any ideas on what to search?
loading screen code
try {
for (int i = 1; i <= 3; i++) {
if (!new File(signlink.findcachedir() + "load" + i + ".png").exists()) {
String url = "";
switch (i) {
case 1:
url = "http://Morytania.org/load1.png";
break;
case 2:
url = "http://Morytania.org/load2.png";
break;
case 3:
url = "http://Morytania.org/load3.png";
break;
}
HttpDownloadUtility.downloadFile(url, signlink.findcachedir());
}
loadingSprites[i - 1] = Toolkit.getDefaultToolkit()
.getImage(signlink.findcachedir() + "load" + i + ".png");
}
super.graphics.drawImage(loadingSprites[0], 0, 0, null);
super.graphics.drawImage(loadingSprites[1], 5, clientHeight - 35, null);
} catch (Exception e) {
e.printStackTrace();
}
It would appear that you're using revision 317 of the RuneScape client. In the older versions of the engine, such as the one you're using, the background is, by default, loaded from the game cache.
Inside of archive 0, there is a file labelled "title". Inside of that file, you may find the actual background ("title.dat") as the login box ("titlebox.dat") and buttons ("titlebutton.dat"). These files are simply JPEG images.
The background itself is stored as a 383x503 image that is then mirrored in-engine to create the full image. See createTitleBackground(). An excerpt of the code can be found below.
public void createTitleBackground() throws IOException {
Image24 image = new Image24(archiveTitle.read("title.dat"), this);
...
// Flips the title background horizontally
int[] tmp = new int[image.width];
for (int y = 0; y < image.height; y++) {
for (int x = 0; x < image.width; x++) {
tmp[x] = image.pixels[(image.width - x - 1) + (image.width * y)];
}
System.arraycopy(tmp, 0, image.pixels, image.width * y, image.width);
}
...
}
The code above is then called in the load() method:
archiveTitle = loadArchive(1, "title screen", "title", archiveChecksum[1], 25);
fontPlain11 = new BitmapFont(archiveTitle, "p11_full", false);
fontPlain12 = new BitmapFont(archiveTitle, "p12_full", false);
fontBold12 = new BitmapFont(archiveTitle, "b12_full", false);
fontQuill8 = new BitmapFont(archiveTitle, "q8_full", true);
createTitleBackground();
createTitleImages();
screenshots is getting captured like below images but i want to capture it in actual colors also i don't know the reason behind it can anybody tell me why this is happening?
((JavascriptExecutor)driver).executeScript("window.scrollBy(0,131)");
int yPosition = Decision_Maker.getLocation().getY();
for(int j = 1; j<=list.size(); j++)
{
// Get entire page screenshot
File screenshots = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
BufferedImage fullImg = ImageIO.read(screenshots);
ImageIO.read(screenshots).getHeight();
// Get width and height of the element
int eleWidth = Decision_Maker.getSize().getWidth();
int eleHeight = Decision_Maker.getSize().getHeight();
//Crop the entire page screenshot to get only element screenshot
BufferedImage eleScreenshot= fullImg.getSubimage(465, 190,eleWidth,eleHeight);
ImageIO.write(eleScreenshot, "jpg", screenshots);
//Scroll vertically to the element
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("window.scroll (0, " + yPosition + ") ");
yPosition = yPosition + eleHeight;
//wait for sometime
Thread.sleep(3000);
//File Location
String location = "E:\\Automation\\Screenshots\\";
Thread.sleep(3000);
//capture screenshot
FileUtils.copyFile(screenshots, new File (location + "img" + i + ".jpg"));
Thread.sleep(3000L);
}
You can create utils class to take screenshot and use it
public static void TakeScreenshot(String filename) throws IOException
{
File file= ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(file, new File("path to store screenshot" + filename + ".jpg"));
}
I am trying to get text details like co-ordinates, width and height using the following code (took up this solution from here), but the output was only the text from the last page.
Code
public static void main( String[] args ) throws IOException {
PDDocument document = null;
String fileName = "apache.pdf"
PDFParser parser = new PDFParser(new FileInputStream(fileName));
parser.parse();
StringWriter outString = new StringWriter();
CustomPDFTextStripper stripper = new CustomPDFTextStripper();
stripper.writeText(parser.getPDDocument(), outString);
Vector<List<TextPosition>> vectorlistoftps = stripper.getCharactersByArticle();
for (int i = 0; i < vectorlistoftps.size(); i++) {
List<TextPosition> tplist = vectorlistoftps.get(i);
for (int j = 0; j < tplist.size(); j++) {
TextPosition text = tplist.get(j);
System.out.println(" String "
+ "[x: " + text.getXDirAdj() + ", y: "
+ text.getY() + ", height:" + text.getHeightDir()
+ ", space: " + text.getWidthOfSpace() + ", width: "
+ text.getWidthDirAdj() + ", yScale: " + text.getYScale() + "]"
+ text.getCharacter() +" Font "+ text.getFont().getBaseFont() + " PageNUm "+ (i+1));
}
}
}
CustomPDFTextStripper class:
class CustomPDFTextStripper extends PDFTextStripper
{
//Vector<Vector<List<TextPosition>>> data = new Vector<Vector<List<TextPosition>>>();
public CustomPDFTextStripper() throws IOException {
super();
}
public Vector<List<TextPosition>> getCharactersByArticle(){
// data.add(charactersByArticle);
return charactersByArticle;
}
}
I tried to add the vectors to a list, but when calling the stripper() it is iterating through all the pages and the last page details are stored in charactersByArticle vector and thus returning the same. How do I get info for all pages??
Temporary Fix:
Changed the main method to set the current page as end page and getting the text info. Not a good idea though.
for (int page = 0; page < pageCount; page++)
{
stripper.setStartPage(0);
stripper.setEndPage(page + 1);
stripper.writeText(parser.getPDDocument(), outString);
Vector vectorlistoftps = stripper.getCharactersByArticle();
PDPage thisPage = stripper.getCurrentPage();
for (int i = 0; i < vectorlistoftps.size(); i++) {
List<TextPosition> tplist = vectorlistoftps.get(i);
}
}
I am trying to add a scroll function to my code as currently it merely displays the first couple tweets, enough to fill the canvas but no more. How do I go about adding a scroll/click function so the canvas lists other tweets as well?
This is what I have so far with my Twitter API tokens omitted.
import java.util.Date;
import java.util.Arrays;
ArrayList<String> words = new ArrayList();
void setup() {
//Set the size of the stage, and the background to black.
size(750, 750);
background(0);
//Credentials
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setOAuthConsumerKey("x");
cb.setOAuthConsumerSecret("x");
cb.setOAuthAccessToken("x");
cb.setOAuthAccessTokenSecret("x");
TwitterFactory twitterFactory;
twitterFactory = new TwitterFactory(cb.build());
Twitter twitter = twitterFactory.getInstance();
Query query = new Query("StackOverFow");
query.count(100);
try {
QueryResult result = twitter.search(query);
ArrayList tweets = (ArrayList) result.getTweets();
for (int i = 0; i < tweets.size (); i++) {
Status t = (Status) tweets.get(i);
User u=(User) t.getUser();
String user=u.getName();
String msg = t.getText();
Date d = t.getCreatedAt();
text("User Name - " + user + " Time - " + d + " Message - " + msg,
20, 15+i*50, width-40, 50);
println("Tweet by " + user + " at " + d + ": " + msg);
//Break the tweet into words
String[] input = msg.split(" ");
println(input);
for (int j = 0; j < input.length; j++) {
//Put each word into the words ArrayList
words.add(input[j]);
}
};
}
catch (TwitterException te) {
println("Couldn't connect: " + te);
};
}
int j=0;
void mousePressed() {
saveData();
}
void saveData() {
String[] data = new String[words.size()];
words.toArray(data);
saveStrings("data/data.txt", data);
}
You already have a handler for mousePressed, adding click and scroll handling is the same concept: add mouseClicked for full click handling, and mouseWheel() for handling scroll events.