Skip to content

Commit

Permalink
Added support for slide links (Issue #251)
Browse files Browse the repository at this point in the history
  • Loading branch information
GitBrent authored and GitBrent committed Dec 4, 2017
1 parent 6c76512 commit 6d5a593
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 23 deletions.
32 changes: 20 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ slide.addText([ {text:'TEXT', options:{OPTIONS}} ]);
| `fill` | string | | | fill/bkgd color | hex color code or [scheme color constant](#scheme-colors). Ex: `{ color:'0088CC' }` |
| `font_face` | string | | | font face | Ex: 'Arial' |
| `font_size` | number | points | | font size | 1-256. Ex: `{ font_size:12 }` |
| `hyperlink` | string | | | add hyperlink | object with `url` and optionally `tooltip`. Ex: `{ hyperlink:{url:'https://github.com'} }` |
| `hyperlink` | string | | | add hyperlink | object with `url` or `slide` (`tooltip` optional). Ex: `{ hyperlink:{url:'https://github.com'} }` |
| `indentLevel`| number | level | `0` | bullet indent level | 1-32. Ex: `{ indentLevel:1 }` |
| `inset` | number | inches | | inset/padding | 1-256. Ex: `{ inset:1.25 }` |
| `isTextBox` | boolean | | `false` | PPT "Textbox" | `true` or `false` |
Expand Down Expand Up @@ -697,14 +697,22 @@ slide.addText(
{ x:8.0, y:5.0, w:'30%', h:1.4, color:'ABABAB', margin:1 }
);

// EX: Hyperlinks
// EX: Hyperlink: Web
slide.addText(
[{
text: 'PptxGenJS Project',
options: { hyperlink:{ url:'https://github.com/gitbrent/pptxgenjs', tooltip:'Visit Homepage' } }
}],
{ x:1.0, y:1.0, w:5, h:1 }
);
// EX: Hyperlink: Slide in Presentation
slide.addText(
[{
text: 'Slide #2',
options: { hyperlink:{ slide:'2', tooltip:'Go to Summary Slide' } }
}],
{ x:1.0, y:2.5, w:5, h:1 }
);

// EX: Drop/Outer Shadow
slide.addText(
Expand Down Expand Up @@ -951,16 +959,16 @@ Animated GIFs can be included in Presentations in one of two ways:
* Client Browsers: pre-encode the gif and add it using the `data` option (encoding images into GIFs is beyond any current browser)

### Image Options
| Option | Type | Unit | Default | Description | Possible Values |
| :----------- | :------ | :----- | :-------- | :------------------ | :--------------- |
| `x` | number | inches | `1.0` | horizontal location | 0-n |
| `y` | number | inches | `1.0` | vertical location | 0-n |
| `w` | number | inches | `1.0` | width | 0-n |
| `h` | number | inches | `1.0` | height | 0-n |
| `data` | string | | | image data (base64) | base64-encoded image string. (either `data` or `path` is required) |
| `hyperlink` | string | | | add hyperlink | object with `url` and optionally `tooltip`. Ex: `{ hyperlink:{url:'https://github.com'} }` |
| `path` | string | | | image path | Same as used in an (img src="") tag. (either `data` or `path` is required) |
| `sizing` | object | | | transforms image | See [Image Sizing](#image-sizing) |
| Option | Type | Unit | Default | Description | Possible Values |
| :----------- | :------ | :----- | :------- | :------------------ | :--------------- |
| `x` | number | inches | `1.0` | horizontal location | 0-n |
| `y` | number | inches | `1.0` | vertical location | 0-n |
| `w` | number | inches | `1.0` | width | 0-n |
| `h` | number | inches | `1.0` | height | 0-n |
| `data` | string | | | image data (base64) | base64-encoded image string. (either `data` or `path` is required) |
| `hyperlink` | string | | | add hyperlink | object with `url` or `slide` (`tooltip` optional). Ex: `{ hyperlink:{url:'https://github.com'} }` |
| `path` | string | | | image path | Same as used in an (img src="") tag. (either `data` or `path` is required) |
| `sizing` | object | | | transforms image | See [Image Sizing](#image-sizing) |

**NOTES**
* SVG images are not currently supported in PowerPoint or PowerPoint Online (even when encoded into base64). PptxGenJS does
Expand Down
31 changes: 20 additions & 11 deletions dist/pptxgen.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ if ( NODEJS ) {
var PptxGenJS = function(){
// APP
var APP_VER = "2.0.0-beta";
var APP_REL = "20171129";
var APP_REL = "20171203";

// CONSTANTS
var MASTER_OBJECTS = {
Expand Down Expand Up @@ -403,15 +403,15 @@ var PptxGenJS = function(){

// STEP 5: (Issue#77) Hyperlink support
if ( typeof objHyperlink === 'object' ) {
if ( !objHyperlink.url || typeof objHyperlink.url !== 'string' ) console.log("ERROR: 'hyperlink.url is required and/or should be a string'");
if ( !objHyperlink.url && !objHyperlink.slide ) console.log("ERROR: 'hyperlink requires either: `url` or `slide`'");
else {
var intRelId = imageRelId + 1;

target.rels.push({
type: 'hyperlink',
data: 'dummy',
data: (objHyperlink.slide ? 'slide' : 'dummy'),
rId: intRelId,
Target: objHyperlink.url
Target: objHyperlink.url || objHyperlink.slide
});

objHyperlink.rId = intRelId;
Expand Down Expand Up @@ -1015,7 +1015,8 @@ var PptxGenJS = function(){
strSlideXml += '<p:pic>';
strSlideXml += ' <p:nvPicPr>'
strSlideXml += ' <p:cNvPr id="'+ (idx + 2) +'" name="Object '+ (idx + 1) +'" descr="'+ slideItemObj.image +'">';
if ( slideItemObj.hyperlink ) strSlideXml += '<a:hlinkClick r:id="rId'+ slideItemObj.hyperlink.rId +'" tooltip="'+ (slideItemObj.hyperlink.tooltip ? decodeXmlEntities(slideItemObj.hyperlink.tooltip) : '') +'"/>';
if ( slideItemObj.hyperlink && slideItemObj.hyperlink.url ) strSlideXml += '<a:hlinkClick r:id="rId'+ slideItemObj.hyperlink.rId +'" tooltip="'+ (slideItemObj.hyperlink.tooltip ? decodeXmlEntities(slideItemObj.hyperlink.tooltip) : '') +'" />';
if ( slideItemObj.hyperlink && slideItemObj.hyperlink.slide ) strSlideXml += '<a:hlinkClick r:id="rId'+ slideItemObj.hyperlink.rId +'" tooltip="'+ (slideItemObj.hyperlink.tooltip ? decodeXmlEntities(slideItemObj.hyperlink.tooltip) : '') +'" action="ppaction://hlinksldjump" />';
strSlideXml += ' </p:cNvPr>';
strSlideXml += ' <p:cNvPicPr><a:picLocks noChangeAspect="1"/></p:cNvPicPr><p:nvPr/>';
strSlideXml += ' </p:nvPicPr>';
Expand Down Expand Up @@ -1204,7 +1205,12 @@ var PptxGenJS = function(){
strXml += '<Relationship Id="rId'+ rel.rId +'" Target="'+ rel.Target +'" TargetMode="External" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/video"/>';
}
else if ( rel.type.toLowerCase().indexOf('hyperlink') > -1 ) {
strXml += '<Relationship Id="rId'+ rel.rId +'" Target="'+ rel.Target +'" TargetMode="External" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink"/>';
if ( rel.data == 'slide' ) {
strXml += '<Relationship Id="rId'+ rel.rId +'" Target="slide'+ rel.Target +'.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide"/>';
}
else {
strXml += '<Relationship Id="rId'+ rel.rId +'" Target="'+ rel.Target +'" TargetMode="External" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink"/>';
}
}
});

Expand Down Expand Up @@ -1960,17 +1966,17 @@ var PptxGenJS = function(){
if ( Array.isArray(text) ) createHyperlinkRels(text, slideRels);
else if ( text && typeof text === 'object' && text.options && text.options.hyperlink && !text.options.hyperlink.rId ) {
if ( typeof text.options.hyperlink !== 'object' ) console.log("ERROR: text `hyperlink` option should be an object. Ex: `hyperlink: {url:'https://github.com'}` ");
else if ( !text.options.hyperlink.url || typeof text.options.hyperlink.url !== 'string' ) console.log("ERROR: 'hyperlink.url is required and/or should be a string'");
else if ( !text.options.hyperlink.url && !text.options.hyperlink.slide ) console.log("ERROR: 'hyperlink requires either: `url` or `slide`'");
else {
var intRels = 1;
gObjPptx.slides.forEach(function(slide,idx){ intRels += slide.rels.length; });
var intRelId = intRels+1;

slideRels.push({
type: 'hyperlink',
data: 'dummy',
data: (text.options.hyperlink.slide ? 'slide' : 'dummy'),
rId: intRelId,
Target: text.options.hyperlink.url
Target: text.options.hyperlink.url || text.options.hyperlink.slide
});

text.options.hyperlink.rId = intRelId;
Expand Down Expand Up @@ -3769,11 +3775,14 @@ var PptxGenJS = function(){
// Hyperlink support
if ( opts.hyperlink ) {
if ( typeof opts.hyperlink !== 'object' ) console.log("ERROR: text `hyperlink` option should be an object. Ex: `hyperlink:{url:'https://github.com'}` ");
else if ( !opts.hyperlink.url || typeof opts.hyperlink.url !== 'string' ) console.log("ERROR: 'hyperlink.url is required and/or should be a string'");
else if ( !opts.hyperlink.url && !opts.hyperlink.slide ) console.log("ERROR: 'hyperlink requires either `url` or `slide`'");
else if ( opts.hyperlink.url ) {
// FIXME-20170410: FUTURE-FEATURE: color (link is always blue in Keynote and PPT online, so usual text run above isnt honored for links..?)
//startInfo += '<a:uFill>'+ genXmlColorSelection('0000FF') +'</a:uFill>'; // Breaks PPT2010! (Issue#74)
startInfo += '<a:hlinkClick r:id="rId'+ opts.hyperlink.rId +'" invalidUrl="" action="" tgtFrame="" tooltip="'+ (opts.hyperlink.tooltip ? decodeXmlEntities(opts.hyperlink.tooltip) : '') +'" history="1" highlightClick="0" endSnd="0"/>';
startInfo += '<a:hlinkClick r:id="rId'+ opts.hyperlink.rId +'" invalidUrl="" action="" tgtFrame="" tooltip="'+ (opts.hyperlink.tooltip ? decodeXmlEntities(opts.hyperlink.tooltip) : '') +'" history="1" highlightClick="0" endSnd="0" />';
}
else if ( opts.hyperlink.slide ) {
startInfo += '<a:hlinkClick r:id="rId'+ opts.hyperlink.rId +'" action="ppaction://hlinksldjump" tooltip="'+ (opts.hyperlink.tooltip ? decodeXmlEntities(opts.hyperlink.tooltip) : '') +'" />';
}
}

Expand Down

0 comments on commit 6d5a593

Please sign in to comment.