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

Wiki PDf Exporter task - Corrupt PDF file #932

Closed
kbilkhoo opened this issue Jan 21, 2021 · 10 comments · Fixed by #933
Closed

Wiki PDf Exporter task - Corrupt PDF file #932

kbilkhoo opened this issue Jan 21, 2021 · 10 comments · Fixed by #933
Assignees

Comments

@kbilkhoo
Copy link

Hi can you help,

In a nutshell my requirement is to generate product release notes for our customers in markdown and PDF format, for each feature we release we have a release note text field in the workitem that the product owner fills in with ( with text pictures, etc), when it comes to release I have a release pipeline that call a powershell script then generates release notes in markdown format using devops query, this is then uploaded to the wiki using 'Wiki File Uploader', this all works as expected. What I am trying to do now is give the product owner the ability to dowwnload a PDF version of the markdown, given this I am using 'Wiki PDf Exporter task' to export the markdown file, but now I have a additional problem how to download the file from wiki page, this would be useful but the currently there is not a feature to do this, so what I did was use to modify the markdown file after the pdf was generated and embedded a link into the generated pdf, now when I click the link the pdf gets downloaded, however when I open the PDF the data is not viewable (blank), its seems to be a problem with encoding i think,

image

image

I have include a sample of the header for each file
Corrupt file

image

Same file that is viewable
image

Any suggestion how to achive this

@kbilkhoo kbilkhoo added the bug label Jan 21, 2021
@kbilkhoo kbilkhoo changed the title Corrupt PDF file Wiki PDf Exporter task - Corrupt PDF file Jan 21, 2021
@rfennell
Copy link
Owner

So can I check my understanding

  1. That the PDF generated by the WIKIPDF exporter is valid
  2. It is only when this file, after uploading to the WIKI), is accessed via the link [pdf](/releasenotes/release-79.pdf) that it appears corrupt.

This would suggest an issue with the rendering of the Azure DevOps WIKI page in the browser

I think I would use a different tactic to link to the PDF

  1. Within the pipeline
    • Generate the Release Notes - include a link back to the Azure DevOps pipeline results details
    • Update the WIKI
    • Generate the WIKI PDF
    • Add this PDF as a build resource
  2. The PDF release notes can then be download from the WIKI via the link back to the pipeline artefacts

@kbilkhoo
Copy link
Author

kbilkhoo commented Jan 21, 2021

Thanks for the reply,

after generating the PDF, I did a clone of the wiki repo to my laptop, which also brings down the pdf, these are also showing blank, ( not downloading via browse). I can however generate the file locally my running .exe which exports a viewable pdf, hope this make sense

@rfennell
Copy link
Owner

Ok, sorry if I am being slow here, but I just want to be clear in my head. Is this correct

Case PDF Source Is it corrupted?
1 Generated from a local WIKI repo using the EXE PDF tool No, it can be opened
2 Generated from using the WIKIPDFexport tool and attach as a pipeline artifact, then downloaded ?
3 Generated from using the WIKIPDFexport tool and added to a WIKI using a link, then downloaded Yes, it is blank
  • If case 2 is not corrupt we have to assume it is the copying into, or string the PDF, the WIKI that causes the issue
  • If case 2 is corrupt we have to assume the wrapping of the EXE in the task is causing the corruption

@kbilkhoo
Copy link
Author

Hi,

I have not tried case 2 ( will do later), but what I did was to run the release pipeline in a private agent, what I observed was the following:

  1. WIKIPDFexport tool did generate the file correctly. 👍
  2. The file is then updated in the wiki using WIKI File Updater ( this is where the file gets corrupted )

I

@rfennell
Copy link
Owner

Ok, I think your private agent test answers my question. So the step I guess are

  • Take the generated PDF and manually commit to the WIKI and see if also corrupts the it when viewed from the WIKI - I want to see if it any commit to the WIKI repo or just the way my task does does the commit, but is using simple-git which is standard npm library.

I will do a dig to see if I can find any reports of problems with PDFs in gut and or WIKis

@kbilkhoo
Copy link
Author

Hi,

I took the generated pdf and manually committed ( using VS code) to the wiki and then in a wiki page added a link to that pdf, pdf now gets downloaded and I can view it 👍

@rfennell
Copy link
Owner

That suggests the problem lies within the library i am using for git operations. I will gocus my investigation there

@rfennell
Copy link
Owner

I have managed to reproduce this problem.

I think the problem could be do do with the way my WIKIUpdater copies the PDF file onto the clone repo prior to the commit.

I am investigating

@kbilkhoo
Copy link
Author

Hi, also I get a corrupt markdown file generated from powershell if i do the following:

"Hello World 3" | out-File TestPDF.md

image

to make this work I had to change the script to "Hello World 3" | out-File TestPDF.md -Encoding utf8

@rfennell
Copy link
Owner

I have found the issue, it was with the fs.writefilesync call I was using to copy the generated file (a PDF in your based) into the repo prior to it being committing. It was treating the file contents as a UTF8 string when it should have been treated as a buffer. This is not an issue for markdown WIKI pages, but will be for other file formats.

I have added an extra task parameter to pick the file copy behaviour. The default is to work as it has in the past so I don't break backwards compatibility. This is called fixLineFeeds

  • If set to true, `n are swapped to \r\n as this is required for most WIKIs.
  • If set to false, no replacement is made, this should be used for non-text based files e.g. images or PDFs.

Note: This parameter is only used when replaceFile is set to true

So you usage will need to be something like

- task: WikiUpdaterTask@1
  displayName: 'Append a PDF'
  condition: succeeded()
  inputs:
    repo: 'dev.azure.com/richardfennell/Git%20project/_git/Git-project.wiki'
    filename: 'Azrepo.pdf'
    replaceFile: true
    appendToFile: true
    dataIsFile: true
    sourceFile: '$(Build.ArtifactStagingDirectory)\PDF\Azrepo.pdf'
    message: 'Store a PDF'
    gitname: 'Build.RequestedForId'
    gitemail: 'Build.RequestedForEmail'
    UseAgentToken: true
    localpath: '$(System.DefaultWorkingDirectory)\pdfrepo'
    fixLineFeeds: false

This has been released as 1.21.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants