Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BugFix: Hyperlinks causing duplicate relationship ID when other objects on page #477

Merged
merged 1 commit into from
Jan 26, 2019

Conversation

ReimaFrgos
Copy link
Contributor

Bugfix for issue #465
Possible that it also resolves #454 but need more info from OP

When at least 1 hyperlink is included on a slide with another object such as a chart, image, video, audio etc, it creates a duplicate relationship ID as seen in the slide#.xml.rels file which leads to a corruption warning when opening the file.

Fix is to modify the var intRels = 1; to start counting from 0 when creating hyperlink rels.

I've tested with a variety of combinations

Sample Test Code - ( It's not pretty, works as proof of concept )

var pptx = new PptxGenJS();
var slide = pptx.addNewSlide();

// 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: Image from remote URL
slide.addImage({ path:'https://upload.wikimedia.org/wikipedia/en/a/a9/Example.jpg', x:1, y:1, w:6, h:4 })

// Chart Type: RADAR
var dataChartRadar = [
    {
        name  : 'Region 1',
        labels: ['May', 'June', 'July', 'August', 'September'],
        values: [26, 53, 100, 75, 41]
    }
];
slide.addChart( pptx.charts.RADAR, dataChartRadar, { x:0.5, y:0.6, w:6.0, h:4, radarStyle:'standard' } );

// 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 }
);

pptx.save('PptxGenJS-Sandbox_'+getTimestamp());

slide1.xml.rels - PRE PATCH

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
    <Relationship Id="rId2" Target="https://github.com/gitbrent/pptxgenjs" TargetMode="External" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink"/>
    <Relationship Id="rId2" Target="../media/image1.jpg" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"/>
    <Relationship Id="rId3" Target="/ppt/charts/chart1.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart"/>
    <Relationship Id="rId5" Target="slide2.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide"/>
    <Relationship Id="rId6" Target="../slideLayouts/slideLayout1.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout"/>
    <Relationship Id="rId7" Target="../notesSlides/notesSlide1.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesSlide"/>
</Relationships>

slide1.xml.rels - POST PATCH

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
    <Relationship Id="rId1" Target="https://github.com/gitbrent/pptxgenjs" TargetMode="External" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink"/>
    <Relationship Id="rId2" Target="../media/image1.jpg" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"/>
    <Relationship Id="rId3" Target="/ppt/charts/chart1.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart"/>
    <Relationship Id="rId4" Target="slide2.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide"/>
    <Relationship Id="rId5" Target="../slideLayouts/slideLayout1.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout"/>
    <Relationship Id="rId6" Target="../notesSlides/notesSlide1.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesSlide"/>
</Relationships>

Fix starting value for intRels to avoid duplicate rId values when a hyperlink is on the page
@gitbrent gitbrent merged commit 45cb857 into gitbrent:master Jan 26, 2019
@gitbrent
Copy link
Owner

Thanks @ReimaFrgos !

@gitbrent gitbrent added this to the 2.5.0 milestone Jan 26, 2019
gitbrent added a commit that referenced this pull request Jan 26, 2019
@gitbrent gitbrent self-assigned this Jan 26, 2019
ericrockey pushed a commit to WeTransfer/PptxGenJS that referenced this pull request Mar 24, 2020
BugFix: Hyperlinks causing duplicate relationship ID when other objects on page
ericrockey pushed a commit to WeTransfer/PptxGenJS that referenced this pull request Mar 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Adding hyperlink to text in a slide corrupts presentation and results in blank slide
2 participants