I am wondering if by any mean, i can set the 'Slide sized for ' as On-ScreenShow (16:9). i mean is there any method in master object in apache poi hslf? I couldn't find it. I have added the image for the reference.
You can only have one page size per file.
To set the page dimension call SlideShow.setPageSize().
To find out which page dimensions 4:3, 16:9 or any other formats are, just create a PPT manually via Powerpoint and check its dimension - or use a Cross-multiplication:
import java.io.File;
import java.io.IOException;
import org.apache.poi.sl.usermodel.SlideShow;
import org.apache.poi.sl.usermodel.SlideShowFactory;
public class SlideSizes {
public static void main(String[] args) throws IOException {
String files[] = { "dim_4_3.ppt", "dim_16_9.ppt" };
for (String f : files) {
SlideShow<?,?> ppt = SlideShowFactory.create(new File(f));
System.out.println(ppt.getPageSize());
}
}
}
Related
I have several xlsx files that have the "read-only recommended" flag set.
Is there a POI 5.x method available to disable this checkbox?
I looked through POI XML Properties with no luck.
In Office Open XML-Excel files the setting "read only recommended" is stored in /xl/workbook.xml as an attribute in a fileSharing XML-element.
...
<fileSharing readOnlyRecommended="1"/>
...
This can be set or unset using apache poi only using the low level org.openxmlformats.schemas.spreadsheetml.x2006.main.*-classes.
Complete example:
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.*;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.*;
import java.io.*;
class ExcelRemoveReadOnlyRecommended {
static void removeReadOnlyRecommended(XSSFWorkbook workbook) {
CTWorkbook ctWorkbook = workbook.getCTWorkbook();
CTFileSharing ctfilesharing = ctWorkbook.getFileSharing();
if (ctfilesharing != null) {
ctfilesharing.setReadOnlyRecommended(false);
}
}
public static void main(String[] args) throws Exception {
String sourceFilePath = "./sourceFile.xlsx";
String resultFilePath = "./resultFile.xlsx";
Workbook workbook = WorkbookFactory.create(new FileInputStream(sourceFilePath));
if (workbook instanceof XSSFWorkbook) {
removeReadOnlyRecommended((XSSFWorkbook)workbook);
}
OutputStream out = new FileOutputStream(resultFilePath);
workbook.write(out);
out.close();
workbook.close();
}
}
If the sourceFile.xlsx has set that option, but without passwords, then after running that code the resultFile.xlsx has not set that option anymore.
If passwords are set too, then decryption is needed at first and the password in fileSharing needs to be unset too. Of course then at least the decryption-password needs to be known.
How do you add attachments from a generic filetype using Apose.Slides using java?
The manual PowerPoint operation I’m trying to do programmatically is:
Insert -> Object -> From file
Is this possible with Aspose.Slides insert an Excel file as a link using java?
The below code is working fine for attaching the Excel file using aspose slides
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import com.aspose.slides.IOleEmbeddedDataInfo;
import com.aspose.slides.IOleObjectFrame;
import com.aspose.slides.OleEmbeddedDataInfo;
import com.aspose.slides.Presentation;
import com.aspose.slides.SaveFormat;
public class SetFileTypeForAnEmbeddingObject2 {
public static void main(String[] args) throws IOException {
Presentation pres = new Presentation();
try {
// Add known Ole objects
byte[] fileBytes = Files.readAllBytes(Paths.get("C:\\work\\Demo uploadt.xlsm"));
// Create Ole embedded file info
IOleEmbeddedDataInfo dataInfo = new OleEmbeddedDataInfo(fileBytes, "xls");
// Create OLE object
IOleObjectFrame oleFrame = pres.getSlides().get_Item(0).getShapes().addOleObjectFrame(150, 420, 250, 50,
dataInfo);
oleFrame.setObjectIcon(true);
pres.save("C:\\work\\" + "SetFileTypeForAnEmbeddingObject7.pptx", SaveFormat.Pptx);
} finally {
if (pres != null)
pres.dispose();
}
}
}
I am trying to create a pdf using itext java library like:
Where I create highlighter icon(the arrow sign) like:
Phrase ph=new Phrase("ä", FontFactory.getFont(FontFactory.ZAPFDINGBATS, 14f));
Now I want that all the text of the advertisement ie.
Now own a Farm Plot nr Jigani in 5yrs installment option #INR450/sqft
with 5acre Club House.www.goldeneraproperty.com M-9999999999
should automatically wrap around the icon which I created above using FontFactory.ZAPFDINGBATS.
However I am stuck here.Please could anyone help me resolve it.
I tried creating a table of one column and one cell and put the icon in that cell but it did not help as the text did not wrap around the table.
Please suggest how could i create a pdf where the text would automatically wrap around the icon.Thanks in Advance!!!
I have designed it to a similar state. Please use you own alignment, fonts, sizes, etc. inside you PDF file.
PFB the code for above design:
package com.itext_dummy;
import java.io.FileOutputStream;
import java.io.IOException;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Image;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
public class Hello {
/** Path to the resulting PDF file. */
public static final String RESULT
= "src/hello.pdf";
public static void main(String[] args)
throws DocumentException, IOException {
new Hello().createPdf(RESULT);
}
public void createPdf(String filename)
throws DocumentException, IOException {
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream(filename));
document.open();
Image img = Image.getInstance("src/Arrow.png");
img.scaleAbsolute(50f, 50f);
img.setAlignment(Image.LEFT | Image.TEXTWRAP);
document.add(img);
Paragraph para = new Paragraph();
para.add("Now own a Farm Plot nr Jigani in 5yrs installment option #INR450/sqft with 5acre Club House.www.goldeneraproperty.com M-99999999994444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444");
document.add(para);
document.close();
}
}
Please do your own alignment on image size and paragraph text sizes and alignments.
Also PFB the icon image that I used:
I used the image since, that is the only way the wrapping could be done.
PFB my result screenshot:
i'm developing a DMS.
i'm currently working on the document management system aspect , like Managing PDFs and Docs;
Now I want my application to be able to show all the existing PDF and
DOC files on the computer in my application. so that they can be
opened when the user clicks on them.
i'm currently just focusing on PDFs And Docs
import java.io.File;
import java.util.Collection;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.IOFileFilter;
public class SearchDocFiles {
public static String[] EXTENSIONS = { "doc", "docx" };
public Collection<File> searchFilesWithExtensions(final File directory, final String[] extensions) {
return FileUtils.listFiles(directory,
extensions,
true);
}
public static void main(String... args) {
Collection<File> documents = new SearchDocFiles().searchFilesWithExtensions(
new File("/path/to/document/folder"),
SearchDocFiles.EXTENSIONS);
for (File document: documents) {
System.out.println(document.getName() + " - " + document.length());
}
}
}
this uses Apache Commons IO expectially FileUtil
I made a desktop app in java with netbeans platform. In my app I want to give separate copy-paste and cut-paste option of file or folder.
So how can I do that? I tried Files.copy(new File("D:\\Pndat").toPath(),new File("D:\\212").toPath(), REPLACE_EXISTING);. But I don't get the exact output.
If there any other option then suggest me.
In case of "cut-paste" you can use renameTo() like this:
File source = new File("////////Source path");
File destination = new File("//////////destination path");
if (!destination.exists()) {
source.renameTo(destination);
}
In case of "copy-paste" you need to read in Input and Output stream.
Use FileUtils from apache io and do FileUtils.copyDirectory(sourceDir, destDir);
You can also do the following file operations
writing to a file
reading from a file
make a directory including parent directories
copying files and directories
deleting files and directories
converting to and from a URL
listing files and directories by filter and extension
comparing file content
file last changed date
Download link for apache i/o jar.
I think this question relates to using the system clipboard for copying a file specified in a Java app and using the OS "Paste" function to copy the file to a folder. Here is a short instructional example that will show you how to add a single file to the OS clipboard for later doing an OS "Paste" function. Tweak as necessary and add error/exception checking as needed.
As a secondary, this code also places the file name on the clipboard so you can paste the file name into document editors.
package com.example.charles.clipboard;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.ClipboardOwner;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
public class JavaToSystemClipboard {
public static void main(final String[] args) throws Exception {
final File fileOut = new File("someFileThatExists");
putFileToSystemClipboard(fileOut);
}
public static void putFileToSystemClipboard(final File fileOut) throws Exception {
final Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
final ClipboardOwner clipboardOwner = null;
final Transferable transferable = new Transferable() {
public boolean isDataFlavorSupported(final DataFlavor flavor) {
return false;
}
public DataFlavor[] getTransferDataFlavors() {
return new DataFlavor[] { DataFlavor.javaFileListFlavor, DataFlavor.stringFlavor };
}
public Object getTransferData(final DataFlavor flavor) {
if (flavor.equals(DataFlavor.javaFileListFlavor)) {
final List<String> list = new ArrayList<>();
list.add(fileOut.getAbsolutePath());
return list;
}
if (flavor.equals(DataFlavor.stringFlavor)) {
return fileOut.getAbsolutePath();
}
return null;
}
};
clipboard.setContents(transferable, clipboardOwner);
}
}
You can write things by yourself using FileOutputStream and FileInputStream or you can used Apache Camel.