Upload file to Fibery in Action button

Thanks for that Oleg.
I’ve succeeded in generating a PDF containing the rich text field contents, but I did notice that where I have references to entities in the rich text field, they are replaced by [???] in the output.
I’m guess that there’s no easy fix for this :-/

Please attach example of your template and describe related fibery types schema. Will try to help you with that.

So this is the code I have used within the action button “Attach PDF using template”

<%
    const fibery = context.getService('fibery');
    const x = await fibery.getEntityById(Entity.Type, Entity.Id, ['Name','Description']);
    const markdownContent = await fibery.getDocumentContent(x["Description"].secret, `md`);
    const text = x.Name
%>
<% NAME(text) %>

{{Name}}

{{State.Name}}

**Description**

<%= markdownContent %>

The resultant PDF is named correctly, and contains what I would expect it to, except that any #mention of an entity in the description field shows as [???].

Please give me some time. Will get back to you tomorrow.

Hi, @Chr1sG

Sorry, unfortunately can not be done in a simple way right now. References indeed are returned as [???] from server. The workaround is pretty hard to implement and involves travelling in JSON of document. We will think about fixing the issue. Will let you know.

Thanks,
Oleg

1 Like

Thanks for getting back to me.
FYI my use case is to be able to create a record of an entity at a particular point in time (e.g. after approval/design freeze).
If the ability to generate PDF from an entity was natively implemented (as discussed here: PDF export of documents - #4 by anayericov) then the support for entity references in markdown would become less important.

1 Like

Actually you can open Entity as View and hit Print in browser. Most contemporary browsers support print into PDF. In that case Entity Mentions will be printed int PDF with their Names.

Hope this helps

Thanks @Viktar_Zhuk
I didn’t make it clear in my post that I was looking for an automated solution, e.g. when state = done, generate a pdf. Unfortunately, I can’t rely on the user to always remember to do it :-/

Thank you a lot.

It works well.
Only the filename argument does not seem to be respected : I get the file in fibery with name “File 16 Jun 2021 08_40_01.pdf” instead of “2021-06-16-F21030004.pdf”

I created a pull request in gitlab with the script
Script for generating pdf file via pdfMonkey and uploading it in fibery (!3) · Merge requests · fibery-community / Action Buttons · GitLab

Hope it will be helpful to others.

2 Likes

Hi, Sylvain

Thanks. Will check the issue with a file name.

Thanks,
Oleg

@Sylvain_Vuilliot The issue with filename is seems to be fixed and your request is merged.
Thanks for helping.

yes, perfect, thank you for the fix

Hi all,

So, I’m looking to generate a very particular PDF in order to print access cards. Converting this SVG into PDF results in the right layout:

<svg width="244" height="154" viewBox="0 0 244 154" fill="none" xmlns="http://www.w3.org/2000/svg">
	<style>
		text {
			font-family: Poppins;
			font-size: 12px;
			font-weight: 500;
			fill: black;}
    </style>
	<rect width="244" height="154" fill="white"/>
	<text x="12" y="132">TESTY MCTESTFACE</text>
</svg>

Now, it seems that I can do some styling like font size and colour, but I cannot seem to override the size of the PDF generated. I’ve tried with something like this:

<%
	const fibery = context.getService('fibery');
	const x = await fibery.getEntityById(Entity.Type, Entity.Id, ['CardName']);
	//const text = x.CardName.toUpperCase();
	const text = "TESTY MCTESTFACE";
%>

<style>
	html, body {
	margin: 0;
	padding: 0;}
html {
	border: 1px solid red;}
body { 
	border: 1px solid blue;}

 @media print {
	@page {
		 size: 85.6mm 53.98mm;
		 margin: 0;
		 padding: 0;
	}
</style>

<svg width="244" height="154" viewBox="0 0 244 154" fill="none" xmlns="http://www.w3.org/2000/svg">
	<style>
		text {
			font-family: Poppins;
			font-size: 12px;
			font-weight: 500;
			fill: blue;}
	 </style>
	<rect width="244" height="154" fill="white"/>
	<text x="12" y="132"><%= text %></text>
</svg>

Now, ignoring the size mismatch of the card and the SVG, I can fix that easily, I’m struggling because the PDF generated still has margins. It does seem to be portrait, but not respecting the page definition, as you can see in this file: (converted from PDF)

@Oleg, are you able to shine some light if the @page instruction is supposed to be respected?

Thanks,
Wolf

Hi, @njyo

Indeed we had hardcoded margins in the code for converting md to pdf. I removed margin. Please find below our default css.

* {
	box-sizing: border-box;
}

html {
	font-size: 100%;
}

body {
	font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
	line-height: 1.6;
	font-size: 0.6875em; /* 11 pt */
	color: #111;
	padding: 2em;
}

body > :first-child {
	padding-top: 0;
	margin-top: 0;
}

body > :last-child {
	margin-bottom: 0;
	padding-bottom: 0;
}

h1,
h2,
h3,
h4,
h5,
h6 {
	margin: 0;
	padding: 0.5em 0 0.25em;
}

h5,
h6 {
	padding: 0;
}

h5 {
	font-size: 1em;
}

h6 {
	font-size: 0.875em;
	text-transform: uppercase;
}

p {
	margin: 0.25em 0 1em;
}

blockquote {
	margin: 0.5em 0 1em;
	padding-left: 0.5em;
	padding-right: 1em;
	border-left: 4px solid gainsboro;
	font-style: italic;
}

ul,
ol {
	margin: 0;
	margin-left: 1em;
	padding: 0 1.5em 0.5em;
}

pre {
	white-space: pre-wrap;
}

h1 code,
h2 code,
h3 code,
h4 code,
h5 code,
h6 code,
p code,
li code,
pre code {
	background-color: #f8f8f8;
	padding: 0.1em 0.375em;
	border-radius: 0.25em;
	font-family: monospace;
	font-size: 1.2em;
}

pre code {
	display: block;
	padding: 0.5em;
}

.page-break {
	page-break-after: always;
}

img {
	max-width: 100%;
	margin: 1em 0;
}

table {
	border-spacing: 0;
	border-collapse: collapse;
	display: block;
	margin: 0 0 1em;
	width: 100%;
	overflow: auto;
	font-size: x-small;
}

table th,
table td {
	padding: 0.5em 1em;
	border: 1px solid gainsboro;
}

table th {
	font-weight: 600;
}

table tr {
	background-color: white;
	border-top: 1px solid gainsboro;
}

table tr:nth-child(2n) {
	background-color: whitesmoke;
}

Thanks,
Oleg

1 Like

Thanks a lot, @Oleg.

Sorry the delay in responding…

Though, after some more experimentation, it seems to me, that there is implicitly still an A4 sheet in play. And here is why:

I’m intending to generate a card print file. Here’s the code that should work for this:

<%
	const fibery = context.getService('fibery');
	const x = await fibery.getEntityById(Entity.Type, Entity.Id, ['CardName']);
	//const text = x.CardName.toUpperCase();
        const text = "Testy Mc Testface";
%>

<style>
	html, body, svg {
	margin: 0;
	padding: 0;}
html {
	border: 1px solid red;}
body { 
	border: 1px solid blue;}

 @media print {
	@page {
		size: 85.6mm 53.98mm;
		margin: 0;
		padding: 0;
	}
</style>

<svg width="244" height="154" viewBox="0 0 244 154" fill="none" xmlns="http://www.w3.org/2000/svg">
	<style>
		text {
			font-family: Poppins;
			font-size: 12px;
			font-weight: 500;
			fill: blue;}
	 </style>
	<rect width="244" height="154" fill="green"/>
	<text x="12" y="132"><%= text %></text>
</svg>

The above yields the following PDF:

When I adjust the page height by 10 via:

 @media print {
	@page {
		size: 85.6mm 530.98mm;

I get the following PDF:

Note, that there is no vertical padding.

Now, if I adjust the page width by a factor 10 too, it scales up:

 @media print {
	@page {
		size: 850.6mm 530.98mm;

Note the bottom margins again:

I’ve tried this in Chrome and Orion (Safari) and it doesn’t—as it shouldn’t—make a difference… it seems like the base paper size used to generate the PDF is still A4.

I’m not sure if this can be fixed in any way. I guess the alternative would be to be able to generate a text file through ha script, then I can generate an SVG file.

Any help is much appreciated!

Hey Oleg :wave:
Does this feature still exist? I can’t seem to find this option when creating a button

Creating a pdf requires that the Files field is enabled.