SmartBlocks icon indicating copy to clipboard operation
SmartBlocks copied to clipboard

PDF & DOCX Export

Open mlava opened this issue 4 years ago • 29 comments

✂️ Copy of your #42SmartBlock from Roam

PDF - DOCX Export.zip

📋 Describe the SmartBlock

This SmartBlock exports the current page as either PDF or DOCX format.

You can configure whether you want to include the linked references section from the bottom of the page.

It relies on @roamhacker's Roam42 conversion engine, using the Markdown flattening and Markdown to HTML functions.

Note: all the available scripts to convert html to pdf do so by creating an image and then printing that to pdf. This will mean your pdf is not searchable. I will be happy to update if/when someone smarter than me figures out how to export html to pdf without doing so via image.

Created to fulfil a bounty posted by Justin Shaffner and the linked references section by Owen Cyrulnik.

✅ Describe any prerequisites or dependencies that are required for this SmartBlock

Roam 42 and roam/js.

📷 Screenshot of your #42SmartBlock workflow/template from Roam

💡 Additional Info

Loom video: https://www.loom.com/share/23a3e2f913cc4cb69aff548fe10a56a6

mlava avatar Feb 16 '21 09:02 mlava

This is fantastically useful - thank you. I don't have the expertise, but would it be feasible to extend this using https://docverter.com/api/

stevenhill1 avatar Feb 22 '21 11:02 stevenhill1

Hi, sorry, pretty new to smartblocks here. Am I supposed to copy /paste the contents of PDF DOCX Export.zip into a block in a Smartblock workflow? This does not seem to work for me. Thanks for helping!

migdur avatar Feb 22 '21 17:02 migdur

Hi, sorry, pretty new to smartblocks here. Am I supposed to copy /paste the contents of PDF DOCX Export.zip into a block in a Smartblock workflow? This does not seem to work for me. Thanks for helping!

You need to extract the json file from the zip archive and then import the file (PDF & DOCX Export.json) into your Roam database (choose 'import files' from the ... menu). This will add a new page to you Roam graph which has full instructions for set up.

stevenhill1 avatar Feb 22 '21 18:02 stevenhill1

@stevenhill1 Thanks, I am glad it's helpful. Will take a look at your link. And thanks for helping @migdur.

@migdur - did you get it working?

mlava avatar Feb 23 '21 03:02 mlava

New version in first post.

Fixed: removal of trigger phrase before rendering of pdf/docx file.

mlava avatar Feb 23 '21 04:02 mlava

@stevenhill1 Thanks, I am glad it's helpful. Will take a look at your link. And thanks for helping @migdur.

@migdur - did you get it working?

Yes I did - thanks!

migdur avatar Feb 23 '21 06:02 migdur

This is great; would love it if it were somehow able to parse and output footnotes.

lkonstan avatar Feb 23 '21 21:02 lkonstan

This looks very useful. I've installed, fire the SB, but it just disappears without exporting anything. That goes for both the PDF and the DOCX formats. It looks like the Loom is on a PC and I'm on a Mac - would that affect the export? I'm using Roam on Chrome, which is set to export to /downloads after asking. I've tried turning off other jss in Roam but that doesn't make any difference. My other SBs are working fine. Thanks.

mottonew avatar Feb 26 '21 23:02 mottonew

Did you uncomment the correct javascript imports in the roam/js block?

On Sat, 27 Feb 2021, 10:32 am mottonew, [email protected] wrote:

This looks very useful. I've installed, fire the SB, but it just disappears without exporting anything. That goes for both the PDF and the DOCX formats. It looks like the Loom is on a PC and I'm on a Mac - would that affect the export? I'm using Roam on Chrome, which is set to export to /downloads after asking. I've tried turning off other jss in Roam but that doesn't make any difference. My other SBs are working fine. Thanks.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/roamhacker/SmartBlocks/issues/209#issuecomment-786949404, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABUKIPWQZUWFPWSXVRGG3BLTBAVQ3ANCNFSM4XWCLLAA .

mlava avatar Feb 27 '21 00:02 mlava

Hey, I'm having trouble with the Docx exporting—they're blank when I try to open them. I'm on Mac btw.

ItsJamesWeiss avatar Feb 27 '21 19:02 ItsJamesWeiss

Yes, I uncommented all of them, removing the \

Where would the exported files go - to where the setting on Chrome tells them?

Thanks for getting to me so quickly

mottonew avatar Feb 27 '21 22:02 mottonew

Yes. You should get a download appear at the bottom of the window. Other thing to do would be check downloads using ctrl-j.

On Sun, 28 Feb 2021, 9:21 am mottonew, [email protected] wrote:

Yes, I uncommented all of them, removing the \

Where would the exported files go - to where the setting on Chrome tells them?

Thanks for getting to me so quickly

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/roamhacker/SmartBlocks/issues/209#issuecomment-787196455, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABUKIPQ72PMOE7K5VIDKP7LTBFV53ANCNFSM4XWCLLAA .

mlava avatar Feb 27 '21 23:02 mlava

@mottonew Could you send me a screenshot of your roam/js block please?

mlava avatar Feb 28 '21 08:02 mlava

This is great! My docx export did not preserve indentation - everything was at root level. Is this intended?

cobblepot1 avatar Mar 02 '21 02:03 cobblepot1

Hi. Yes, the original request from the person who posted the bounty was to simplify (flatten) the markdown language for readability. It can be modified, but we did find it was hard to follow in docx without flattening. Mark

On Tue, Mar 2, 2021 at 1:29 PM cobblepot1 [email protected] wrote:

This is great! My docx export did not preserve indentation - everything was at root level. Is this intended?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/roamhacker/SmartBlocks/issues/209#issuecomment-788528099, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABUKIPVX2YBQ4IAMBWO5QDLTBREPHANCNFSM4XWCLLAA .

mlava avatar Mar 02 '21 03:03 mlava

Part of the SmartBlock trigger (jj) still shows up when I export to PDF (see first line in the attached example). When I export to .docx, the file is empty.

When installing the script, I didn't have to uncomment any line as they weren't commented: image

PDF (see jj in the first line): Export pages using Roam42.pdf

DOCX (completely empty): Export pages using Roam42.docx

RoamStack avatar Mar 03 '21 11:03 RoamStack

Can you check which version of the script you're using? Current is 0.2

On Wed, Mar 3, 2021 at 10:41 PM RoamStack [email protected] wrote:

Part of the SmartBlock trigger (jj) still shows up when I export to PDF (see first line in the attached example). When I export to .docx, the file is empty.

When installing the script, I didn't have to uncomment any line as they weren't commented: [image: image] https://user-images.githubusercontent.com/77009918/109800536-94f65700-7c1d-11eb-814a-d7ee8a0ae7b4.png

PDF (see jj in the first line): Export pages using Roam42.pdf https://github.com/roamhacker/SmartBlocks/files/6075662/Export.pages.using.Roam42.pdf

DOCX (completely empty): Export pages using Roam42.docx https://github.com/roamhacker/SmartBlocks/files/6075663/Export.pages.using.Roam42.docx

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/roamhacker/SmartBlocks/issues/209#issuecomment-789653623, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABUKIPWSPVLXO5Q5WRWFLSLTBYN55ANCNFSM4XWCLLAA .

mlava avatar Mar 03 '21 21:03 mlava

For this page, which is rather short, Docx is empty, pdf is not. Roman Empire (1).docx Roman Empire (1).pdf

I have a longer page. PDF is empty but 50 pages long. Docx is also empty but only 1 page long.

Course_Stock 1_ Foundation (1).docx Course_Stock 1_ Foundation (4).pdf

And also is it possible to improve the image quality of pdf? It is actually a bit interesting. Blurry on 100% zoom but better when zoomed in.

100%: Screenshot 2021-03-06 at 13 22 30

Zoomed in: Screenshot 2021-03-06 at 13 22 46

orkhan10 avatar Mar 06 '21 12:03 orkhan10

@RoamStack Are you on Mac by any chance?

@orkhan10 appears to be on Mac and is having issues.

I wonder if it is an OS issue as I am using Windows and both pdf and docx are working perfectly, without the trigger phrase and no empty files.

mlava avatar Mar 06 '21 12:03 mlava

@RoamStack Are you on Mac by any chance?

@orkhan10 appears to be on Mac and is having issues.

I wonder if it is an OS issue as I am using Windows and both pdf and docx are working perfectly, without the trigger phrase and no empty files.

Also works fine for me on Windows, but getting these problems on Safari on iOS

stevenhill1 avatar Mar 06 '21 16:03 stevenhill1

Ok, well that's interesting. I don't have a Mac or iphone so can't troubleshoot. Mark

On Sun, Mar 7, 2021 at 3:31 AM Steven [email protected] wrote:

@RoamStack https://github.com/RoamStack Are you on Mac by any chance?

@orkhan10 https://github.com/orkhan10 appears to be on Mac and is having issues.

I wonder if it is an OS issue as I am using Windows and both pdf and docx are working perfectly, without the trigger phrase and no empty files.

Also works fine for me on Windows, but getting these problems on Safari on iOS

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/roamhacker/SmartBlocks/issues/209#issuecomment-791983036, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABUKIPTEC6C4ODVP6SZCMWTTCJKG7ANCNFSM4XWCLLAA .

mlava avatar Mar 09 '21 02:03 mlava

Hi, in mi case it leaves jjdoc in exported document, and it doesn't recognizes Spanish characters image

diegouriarte avatar Mar 25 '21 21:03 diegouriarte

Hi, in mi case it leaves jjdoc in exported document, and it doesn't recognizes Spanish characters image

Turkish characters either :(

ghost avatar Apr 14 '21 22:04 ghost

image The trigger doesn't seem to do anything for me. I'm on Windows and using the Brave browser. Also tried on Chrome, but no luck. Is there something I'm missing. I followed the instructions in the configuration section.

sandeepkelvadi avatar Jun 09 '21 07:06 sandeepkelvadi

Hi, This is a great utility. Is there a way to export the page along with all the images embedded within a page while exporting as pdf with this smartblock trigger? Vinod

zzzgithubzzz avatar Jul 16 '21 06:07 zzzgithubzzz

I have custom CSS in my graph for both light and dark mode. I usually work in dark mode, but I definitely don't want the dark mode exported to PDF. Is there a way around this?

jbnv avatar Jul 18 '21 06:07 jbnv

This is a tremendous resource, but from time-to-time it quits working. Usually, restarting Roam gets it working again and if that doesn't then rebooting the computer does. But now it is not working at all. As far as I can tell, everything is still present. Any tips would be appreciated.

Elwood4415 avatar Sep 20 '21 20:09 Elwood4415

The DOCX version of this script is now available in the SmartBlocks store within Roam Research.

The required roam/js to allow it to work is below:

  • {{roam/js}}
    •  var script = document.createElement('script');
       script.type = 'application/javascript';
       script.src = url;
       document.head.appendChild(script); }     addScripts('https://evidenceprime.github.io/html-docx-js/build/html-docx.js');     addScripts('https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/1.3.8/FileSaver.js');     addScripts('https://tinymce.cachefly.net/4.1/tinymce.min.js');```
      
      
      

mlava avatar Nov 03 '21 21:11 mlava

The PDF version of this script is now available in the SmartBlocks store within Roam Research.

The required roam/js to allow it to work is below:

  • {{roam/js}}
    •  var script = document.createElement('script');
       script.type = 'application/javascript';
       script.src = url;
       document.head.appendChild(script); }     addScripts('https://raw.githack.com/eKoopmans/html2pdf/master/dist/html2pdf.bundle.js');```
      

mlava avatar Nov 03 '21 21:11 mlava