# Upload file to Fibery in Action button

**URL:** <https://community.fibery.io/t/upload-file-to-fibery-in-action-button/1664>\
**Category:** API & Programming\
**Created:** [May 28, 2021, 11:10am UTC](https://community.fibery.io/t/upload-file-to-fibery-in-action-button/1664 "2021-05-28T11:10:31Z")\
**Posts on this page:** 17\
**Page:** 2

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [June 14, 2021, 1:42pm UTC](https://community.fibery.io/t/upload-file-to-fibery-in-action-button/1664/21 "2021-06-14T13:42:01Z")

</div>

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 :-/

---

<div class="post-metadata">

**Author:** ![Oleg](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/oleg/32/1887_2.png) [@Oleg](https://community.fibery.io/u/Oleg)\
**Post date:** [June 14, 2021, 1:48pm UTC](https://community.fibery.io/t/upload-file-to-fibery-in-action-button/1664/22 "2021-06-14T13:48:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [June 14, 2021, 2:02pm UTC](https://community.fibery.io/t/upload-file-to-fibery-in-action-button/1664/23 "2021-06-14T14:02:50Z")

</div>

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

```auto
<%
    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 [???].

---

<div class="post-metadata">

**Author:** ![Oleg](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/oleg/32/1887_2.png) [@Oleg](https://community.fibery.io/u/Oleg)\
**Post date:** [June 14, 2021, 2:09pm UTC](https://community.fibery.io/t/upload-file-to-fibery-in-action-button/1664/24 "2021-06-14T14:09:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Oleg](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/oleg/32/1887_2.png) [@Oleg](https://community.fibery.io/u/Oleg)\
**Post date:** [June 15, 2021, 1:42pm UTC](https://community.fibery.io/t/upload-file-to-fibery-in-action-button/1664/25 "2021-06-15T13:42:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [June 15, 2021, 2:09pm UTC](https://community.fibery.io/t/upload-file-to-fibery-in-action-button/1664/26 "2021-06-15T14:09:03Z")

</div>

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](https://community.fibery.io/t/pdf-export-of-documents/1472/4)) then the support for entity references in markdown would become less important.

---

<div class="post-metadata">

**Author:** ![Viktar\_Zhuk](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/viktar_zhuk/32/1934_2.png) [@Viktar\_Zhuk](https://community.fibery.io/u/Viktar_Zhuk)\
**Post date:** [June 15, 2021, 4:38pm UTC](https://community.fibery.io/t/upload-file-to-fibery-in-action-button/1664/27 "2021-06-15T16:38:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [June 15, 2021, 4:48pm UTC](https://community.fibery.io/t/upload-file-to-fibery-in-action-button/1664/28 "2021-06-15T16:48:26Z")

</div>

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 :-/

---

<div class="post-metadata">

**Author:** ![Sylvain\_Vuilliot](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/sylvain_vuilliot/32/1771_2.png) [@Sylvain\_Vuilliot](https://community.fibery.io/u/Sylvain_Vuilliot)\
**Post date:** [June 16, 2021, 9:06am UTC](https://community.fibery.io/t/upload-file-to-fibery-in-action-button/1664/29 "2021-06-16T09:06:03Z")

</div>

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](https://gitlab.com/fibery-community/action-buttons/-/merge_requests/3)

Hope it will be helpful to others.

---

<div class="post-metadata">

**Author:** ![Oleg](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/oleg/32/1887_2.png) [@Oleg](https://community.fibery.io/u/Oleg)\
**Post date:** [June 16, 2021, 9:13am UTC](https://community.fibery.io/t/upload-file-to-fibery-in-action-button/1664/30 "2021-06-16T09:13:35Z")

</div>

Hi, Sylvain

Thanks. Will check the issue with a file name.

Thanks,  
Oleg

---

<div class="post-metadata">

**Author:** ![Oleg](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/oleg/32/1887_2.png) [@Oleg](https://community.fibery.io/u/Oleg)\
**Post date:** [June 16, 2021, 10:32am UTC](https://community.fibery.io/t/upload-file-to-fibery-in-action-button/1664/31 "2021-06-16T10:32:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Sylvain\_Vuilliot](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/sylvain_vuilliot/32/1771_2.png) [@Sylvain\_Vuilliot](https://community.fibery.io/u/Sylvain_Vuilliot)\
**Post date:** [June 16, 2021, 12:18pm UTC](https://community.fibery.io/t/upload-file-to-fibery-in-action-button/1664/32 "2021-06-16T12:18:05Z")

</div>

yes, perfect, thank you for the fix

---

<div class="post-metadata">

**Author:** ![njyo](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/njyo/32/923_2.png) [@njyo](https://community.fibery.io/u/njyo)\
**Post date:** [July 19, 2023, 6:35pm UTC](https://community.fibery.io/t/upload-file-to-fibery-in-action-button/1664/33 "2023-07-19T18:35:06Z")

</div>

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:

```auto
<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:

```auto
<%
	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)

 ![test](https://us1.discourse-cdn.com/flex020/uploads/fibery/original/2X/5/5555e444f30360e9c06c238ac03e18e6cf7bcc2e.png)

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

Thanks,  
Wolf

---

<div class="post-metadata">

**Author:** ![Oleg](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/oleg/32/1887_2.png) [@Oleg](https://community.fibery.io/u/Oleg)\
**Post date:** [July 20, 2023, 7:42am UTC](https://community.fibery.io/t/upload-file-to-fibery-in-action-button/1664/34 "2023-07-20T07:42:00Z")

</div>

Hi, @njyo

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

```auto
* {
	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

---

<div class="post-metadata">

**Author:** ![njyo](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/njyo/32/923_2.png) [@njyo](https://community.fibery.io/u/njyo)\
**Post date:** [August 22, 2023, 8:56am UTC](https://community.fibery.io/t/upload-file-to-fibery-in-action-button/1664/35 "2023-08-22T08:56:36Z")

</div>

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:

```auto
<%
	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:

 ![856x540](https://us1.discourse-cdn.com/flex020/uploads/fibery/original/2X/e/ef93465452d121ab78de7c36217abf060addc930.png)

When I adjust the page height by 10 via:

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

```

I get the following PDF:

 ![856x5310](https://us1.discourse-cdn.com/flex020/uploads/fibery/original/2X/2/2f20e6947dcb2519c6992df4595c90e9682f839f.png)

Note, that there is no vertical padding.

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

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

```

Note the bottom margins again:

 ![8506x5301](https://us1.discourse-cdn.com/flex020/uploads/fibery/original/2X/f/fedbb7d17cdaec5aedab1a13782aea614b6b8ec9.png)

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!

---

<div class="post-metadata">

**Author:** ![Waleed\_Elaghil1](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/waleed_elaghil1/32/7598_2.png) [@Waleed\_Elaghil1](https://community.fibery.io/u/Waleed_Elaghil1)\
**Post date:** [January 9, 2024, 10:05pm UTC](https://community.fibery.io/t/upload-file-to-fibery-in-action-button/1664/36 "2024-01-09T22:05:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [January 10, 2024, 6:47am UTC](https://community.fibery.io/t/upload-file-to-fibery-in-action-button/1664/37 "2024-01-10T06:47:51Z")

</div>

> [@Waleed\_Elaghil1](#):
>
> 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.

[Previous page](https://community.fibery.io/t/upload-file-to-fibery-in-action-button/1664.md?page=1)
