Sejda-Console HTML to PDF Conversion - bash

I am attempting to convert HTML documents to PDF format using a bash script. I've found that the Sejda converter does a good job of fully rendering the charts I need, but am having some trouble using it in the console rather than the web interface. Although the documentation at https://www.sejda.com/developers gives an example of how to convert a URL, does anyone know of a similar way to convert a local file in the console?

The HTML to PDF conversion is not available via the sejda-console.
However, you can convert a local file through the sejda.com API, not only URLs, by posting the file's HTML contents.
Here's an example converting HTML code from the command line:
curl -i https://api.sejda.com/v1/tasks\
--fail --silent --show-error \
--header "Content-Type: application/json" \
--data '{"htmlCode": "<strong>HTML<\/strong> code here",
"type": "htmlToPdf" }' > converted.pdf
Disclaimer: I'm one of the developers.

Related

How to download a private repository from Gitlab without exposing the access token in the url?

I want to download a private repository from Gitlab using curl command (unfortunately I am obliged to do so). I know that the following works:
curl 'https://gitlab.com/api/v4/projects/2222/repository/archive?private_token=hlpat-21321' > your_project.tar.gz
where 21321 is the project id and hlpat-21321 is the access token (I put them random).
I want to do the same thing but without exposing the access token directly. An idea would be to use stdin,meaning taking the token as an input from the user in the command line. How can I do it ?
Quoting curl man pages
Starting in 7.55.0, this option can take an argument in #filename
style, which then adds a header for each line in the input file. Using
#- will make curl read the header file from stdin.
use it as header instead and pass the header from stdin
curl --header -# ...url... <<< "PRIVATE-TOKEN: private_token"
This way you dont need to pass to url

Go post a file with nested object field

I need to POST the following curl command using Go
curl -X POST http://localhost:8001/routes/route_name -F "name=function" -F "config.file[1]=#my_file.lua"
I have been looking into multipart file upload examples, but I can't wrap my head around how to create a post with a nested field name (config.file is a config object with file as an array of strings) using CreateFormFile(key, val).
The problem I am having is according to the docs (https://pkg.go.dev/mime/multipart#Writer.WriteField) the WriteField API takes a field name and a value (path to file to post). I am not sure how to post a field name that is in a nested object e.g. CreateFormFile("config.file", filePath).
Anyone know how to convert the above curl command to Go using POST.

curl - know i reached html file from header

I send curl cmd from shell with --head flag:
curl -k --head http://www.something.com/whatever
is there any way to know from answer headers if this link contains html file can be shown in browser or another type of downloading file (pdf, doc, txt, etc).
Thanks.
The response header should contain a Content-Type field,
for HTML files it should be:
Content-Type: text/html
See also the list of known MIME-types.

How to parse html with wget to download an artifact using pattern matching against Jenkins

I am trying to download an artifact from Jenkins where I need the latest build. If I curl jenkins.mycompany.com/view/iOS/job/build_ios/lastSuccessfulBuild/artifact/build it brings me to the page that contains the artifact I need to download, which in my case is myCompany-1234.ipa
so by changing curl to wget with --auth-no-challenge https://userIsMe:123myapikey321#jenkins.mycompany.com/view/iOS/job/build_ios/lastSuccessfulBuild/artifact/build/ it downloads the index.html file.
if I put --reject index.html it stops the index.html downloading.
if I add the name of the artifact with a wildcard like so MyCompany-*.ipait downloads a 14k file named MyCompany-*.ipa, not the MyCompany-1234.ipa I was hoping for. Keep in mind the page i am requesting only has 1 MyCompany-1234.ipa so there will never be multiple matches found
if I use a flag to pattern match -A "*.ipa" like so: wget --auth-no-challenge -A "*.ipa" https://userIsMe:123myapikey321#jenkins.mycompany.com/view/iOS/job/build_ios/lastSuccessfulBuild/artifact/build/ It still doesn't download the artifact.
It works if I perfectly input the exact url like so: wget --auth-no-challenge https://userIsMe:123myapikey321#jenkins.mycompany.com/view/iOS/job/build_ios/lastSuccessfulBuild/artifact/build/MyCompany-1234.ipa
The problem here is the .ipa is not always going to be 1234, tomorrow will be 1235, and so on. How can I either parse the html or use the wildcard correctly in wget to ensure I am always getting the latest?
NM, working with another engineer here at my work came up with a super elegant solution parsing json.
Install Chrome and get the plugin JSONView
Call the Jenkins API in your Chrome browser using https://$domain/$job/lastSuccessfulBuild/api/json
This will print out the key pair values in json. Denote your Key, for me it was number
brew install jq
In a bash script create a variable that will store the dynamic value as follows
This will store the build number to latest:
latest=$(curl --silent --show-error https://userIsMe:123myapikey321#jenkins.mycompany.com/job/build_ios/lastSuccessfulBuild/api/json | jq '.number')
Print it to screen if you would like:
echo $latest
Now with some string interpolation pass the variable for latest to your wget call:
wget --auth-no-challenge https://userIsMe:123myapikey321#jenkins.mycompany.com/view/iOS/job/build_ios/lastSuccessfulBuild/artifact/build/myCompany-$latest.ipa
Hope this helps someone out as there is limited info out there that is clear and concise, especially given that wget has been around for an eternity.

Pandoc: use variables in custom latex preamble

I have the file test.md which contains:
---
footertext: some text for the footer
headertext: this is in the header
---
here is the text body.
And the file format.tex which contains:
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead[L]{$headertext$}
\fancyfoot[L]{$footertext$}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\setlength{\headsep}{0.25in}
I run the command:
pandoc -H format.tex test.md -o test.pdf
You can see what I want to do. I am trying to get the text "this is in the header" to show up in the header, but it does not, it only shows the string "headertext" (same problem for footer).
What am I doing wrong?
Edit: OK, I think I understand. Apparently variables are only available in templates, not in included begin or end code blocks (like I am using), or in the md itself. So new question: Why is this? It is unintuitive, inconvenient, and poorly documented.
You can easily modify a pandoc template. Access the default template with
pandoc -D latex > new_template.latex
Paste the content of your format.tex in the preamble. You should use $if$ to check if the variable exists before using it if you want to use this template for more than one document :
\usepackage{fancyhdr}
\pagestyle{fancy}
$if(headertext)$\fancyhead[L]{$headertext$}$endif$
$if(footertext)$\fancyfoot[L]{$footertext$}$endif$
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\setlength{\headsep}{0.25in}
Then compile with :
pandoc test.md -o test.pdf --template=new_template.latex

Resources