use of org.apache.poi.hslf.usermodel.HSLFSlide in project poi by apache.
the class Hyperlinks method main.
public static void main(String[] args) throws Exception {
for (int i = 0; i < args.length; i++) {
FileInputStream is = new FileInputStream(args[i]);
HSLFSlideShow ppt = new HSLFSlideShow(is);
is.close();
for (HSLFSlide slide : ppt.getSlides()) {
System.out.println("\nslide " + slide.getSlideNumber());
// read hyperlinks from the slide's text runs
System.out.println("- reading hyperlinks from the text runs");
for (List<HSLFTextParagraph> paras : slide.getTextParagraphs()) {
for (HSLFTextParagraph para : paras) {
for (HSLFTextRun run : para) {
HSLFHyperlink link = run.getHyperlink();
if (link != null) {
System.out.println(toStr(link, run.getRawText()));
}
}
}
}
// in PowerPoint you can assign a hyperlink to a shape without text,
// for example to a Line object. The code below demonstrates how to
// read such hyperlinks
System.out.println("- reading hyperlinks from the slide's shapes");
for (HSLFShape sh : slide.getShapes()) {
if (sh instanceof HSLFSimpleShape) {
HSLFHyperlink link = ((HSLFSimpleShape) sh).getHyperlink();
if (link != null) {
System.out.println(toStr(link, null));
}
}
}
}
ppt.close();
}
}
use of org.apache.poi.hslf.usermodel.HSLFSlide in project poi by apache.
the class CreateHyperlink method main.
public static void main(String[] args) throws IOException {
HSLFSlideShow ppt = new HSLFSlideShow();
try {
HSLFSlide slideA = ppt.createSlide();
ppt.createSlide();
HSLFSlide slideC = ppt.createSlide();
// link to a URL
HSLFTextBox textBox1 = slideA.createTextBox();
textBox1.setText("Apache POI");
textBox1.setAnchor(new Rectangle(100, 100, 200, 50));
HSLFHyperlink link1 = textBox1.getTextParagraphs().get(0).getTextRuns().get(0).createHyperlink();
link1.linkToUrl("http://www.apache.org");
link1.setLabel(textBox1.getText());
// link to another slide
HSLFTextBox textBox2 = slideA.createTextBox();
textBox2.setText("Go to slide #3");
textBox2.setAnchor(new Rectangle(100, 300, 200, 50));
HSLFHyperlink link2 = textBox2.getTextParagraphs().get(0).getTextRuns().get(0).createHyperlink();
link2.linkToSlide(slideC);
FileOutputStream out = new FileOutputStream("hyperlink.ppt");
ppt.write(out);
out.close();
} finally {
ppt.close();
}
}
use of org.apache.poi.hslf.usermodel.HSLFSlide in project poi by apache.
the class PowerPointExtractor method getText.
public String getText(boolean getSlideText, boolean getNoteText, boolean getCommentText, boolean getMasterText) {
StringBuffer ret = new StringBuffer();
if (getSlideText) {
if (getMasterText) {
for (HSLFSlideMaster master : _show.getSlideMasters()) {
for (HSLFShape sh : master.getShapes()) {
if (sh instanceof HSLFTextShape) {
HSLFTextShape hsh = (HSLFTextShape) sh;
final String text = hsh.getText();
if (text == null || "".equals(text) || "*".equals(text)) {
continue;
}
if (HSLFMasterSheet.isPlaceholder(sh)) {
// check for metro shape of complex placeholder
boolean isMetro = new HSLFMetroShape<HSLFShape>(sh).hasMetroBlob();
if (!isMetro) {
// don't bother about boiler plate text on master sheets
LOG.log(POILogger.INFO, "Ignoring boiler plate (placeholder) text on slide master:", text);
continue;
}
}
ret.append(text);
if (!text.endsWith("\n")) {
ret.append("\n");
}
}
}
}
}
for (HSLFSlide slide : _slides) {
String headerText = "";
String footerText = "";
HeadersFooters hf = slide.getHeadersFooters();
if (hf != null) {
if (hf.isHeaderVisible()) {
headerText = safeLine(hf.getHeaderText());
}
if (hf.isFooterVisible()) {
footerText = safeLine(hf.getFooterText());
}
}
// Slide header, if set
ret.append(headerText);
// Slide text
textRunsToText(ret, slide.getTextParagraphs());
// Table text
for (HSLFShape shape : slide.getShapes()) {
if (shape instanceof HSLFTable) {
extractTableText(ret, (HSLFTable) shape);
}
}
// Slide footer, if set
ret.append(footerText);
// Comments, if requested and present
if (getCommentText) {
for (Comment comment : slide.getComments()) {
ret.append(comment.getAuthor() + " - " + comment.getText() + "\n");
}
}
}
if (getNoteText) {
ret.append('\n');
}
}
if (getNoteText) {
// Not currently using _notes, as that can have the notes of
// master sheets in. Grab Slide list, then work from there,
// but ensure no duplicates
Set<Integer> seenNotes = new HashSet<Integer>();
String headerText = "";
String footerText = "";
HeadersFooters hf = _show.getNotesHeadersFooters();
if (hf != null) {
if (hf.isHeaderVisible()) {
headerText = safeLine(hf.getHeaderText());
}
if (hf.isFooterVisible()) {
footerText = safeLine(hf.getFooterText());
}
}
for (HSLFSlide slide : _slides) {
HSLFNotes notes = slide.getNotes();
if (notes == null) {
continue;
}
Integer id = Integer.valueOf(notes._getSheetNumber());
if (seenNotes.contains(id)) {
continue;
}
seenNotes.add(id);
// Repeat the Notes header, if set
ret.append(headerText);
// Notes text
textRunsToText(ret, notes.getTextParagraphs());
// Repeat the notes footer, if set
ret.append(footerText);
}
}
return ret.toString();
}
use of org.apache.poi.hslf.usermodel.HSLFSlide in project poi by apache.
the class TestDocumentEncryption method cryptoAPIDecryption.
@Test
public void cryptoAPIDecryption() throws Exception {
// taken from a msdn blog:
// http://blogs.msdn.com/b/openspecification/archive/2009/05/08/dominic-salemno.aspx
Biff8EncryptionKey.setCurrentUserPassword("crypto");
NPOIFSFileSystem fs = new NPOIFSFileSystem(slTests.getFile("cryptoapi-proc2356.ppt"));
HSLFSlideShowImpl hss = new HSLFSlideShowImpl(fs);
HSLFSlideShow ss = new HSLFSlideShow(hss);
HSLFSlide slide = ss.getSlides().get(0);
String rawText = HSLFTextParagraph.getRawText(slide.getTextParagraphs().get(0));
assertEquals("Dominic Salemno", rawText);
String[][] picCmp = { { "0", "nKsDTKqxTCR8LFkVVWlP9GSTvZ0=" }, { "95163", "SuNOR+9V1UVYZIoeD65l3VTaLoc=" }, { "100864", "Ql3IGrr4bNq07ZTp5iPg7b+pva8=" }, { "714114", "8pdst9NjBGSfWezSZE8+aVhIRe0=" }, { "723752", "go6xqW7lvkCtlOO5tYLiMfb4oxw=" }, { "770128", "gZUM8YqRNL5kGNfyyYvEEernvCc=" }, { "957958", "CNU2iiqUFAnk3TDXsXV1ihH9eRM=" } };
MessageDigest md = CryptoFunctions.getMessageDigest(HashAlgorithm.sha1);
List<HSLFPictureData> pd = hss.getPictureData();
int i = 0;
for (HSLFPictureData p : pd) {
byte[] hash = md.digest(p.getData());
assertEquals(Integer.parseInt(picCmp[i][0]), p.getOffset());
assertEquals(picCmp[i][1], Base64.encodeBase64String(hash));
i++;
}
DocumentEncryptionAtom dea = hss.getDocumentEncryptionAtom();
POIFSFileSystem fs2 = ((CryptoAPIDecryptor) dea.getEncryptionInfo().getDecryptor()).getSummaryEntries(fs.getRoot(), "EncryptedSummary");
PropertySet ps = PropertySetFactory.create(fs2.getRoot(), SummaryInformation.DEFAULT_STREAM_NAME);
assertTrue(ps.isSummaryInformation());
assertEquals("RC4 CryptoAPI Encryption", ps.getProperties()[1].getValue());
ps = PropertySetFactory.create(fs2.getRoot(), DocumentSummaryInformation.DEFAULT_STREAM_NAME);
assertTrue(ps.isDocumentSummaryInformation());
assertEquals("On-screen Show (4:3)", ps.getProperties()[1].getValue());
ss.close();
fs.close();
fs2.close();
}
use of org.apache.poi.hslf.usermodel.HSLFSlide in project poi by apache.
the class TestSlideAtom method testSSSlideInfoAtom.
@Test
public void testSSSlideInfoAtom() throws IOException {
HSLFSlideShow ss1 = new HSLFSlideShow();
HSLFSlide slide1 = ss1.createSlide(), slide2 = ss1.createSlide();
slide2.setHidden(true);
HSLFSlideShow ss2 = HSLFTestDataSamples.writeOutAndReadBack(ss1);
slide1 = ss2.getSlides().get(0);
slide2 = ss2.getSlides().get(1);
assertFalse(slide1.getHidden());
assertTrue(slide2.getHidden());
ss2.close();
ss1.close();
}
Aggregations