typora/typora-issues

Export PDF or print support page option

jackxujh opened this issue · 29 comments

When using the export to PDF feature in Typora, it always exports using A4 Portrait, instead of using values in File > Page Setup. I don’t know if this was designed this way or it is not behaving correctly, but I think the normal practice in macOS apps is to use the Page Setup for exporting. I am using a workaround for now — first export to html, and then print the html to PDF from Safari. It would save some hassle if Typora could handle the page setup itself. Thanks!

any plan fix this problem? the exported A4 PDF font size too large to view especially for code part with little fonts.

pjeby commented

I was able to set page size and margins using CSS at the top of the document, e.g.:

<style type="text/css">@page { size: letter; margin: 0.25in; }</style>

I'm not sure what other options are supported, but this worked for me to get letter size paper with a usable margin.

That's a great hack. That CSS can also be added to one of the CSS override files -- putting it in base.user.css will affect all themes.

OHLIA commented

I was able to set page size and margins using CSS at the top of the document, e.g.:

<style type="text/css">@page { size: letter; margin: 0.25in; }</style>

I'm not sure what other options are supported, but this worked for me to get letter size paper with a usable margin.

It seems not work on my side.

That's a great hack. That CSS can also be added to one of the CSS override files -- putting it in base.user.css will affect all themes.

I agree. Not knowing much about coding, I put it straight into the base.use.css like so:
<style type="text/css">@page { size: letter; margin: 0.25in; }</style>
With this
}
immediately below.
But it does not work. Did I leave something out?

If this is the only custom CSS you're using, then your entire base.user.css file should look like this:

@page { size: letter; margin: 0.25in; }

If this is the only custom CSS you're using, then your entire base.user.css file should look like this:

@page { size: letter; margin: 0.25in; }

Thanks for your reply.
There is quite a bit more in my base.user.css
So, what I did was, below the last line of commands I left 1 blank line, then added the line as you stated. The only difference is that for size I put A4 instead of "letter".
But the output was as before, no change.

Even if I do use "letter" there is no change.

@abnerlee : any chance to give me some guidance on this?

Are you saying that when you use letter, you're still getting an A4 PDF?

Note that you should make the change in base.user.css with Typora closed, then open the app and create a PDF.

@asherber : thanks for your feedback.
What I mean is that the margins don't change. I have set them at 0.1 in but they are still at about 1 inch on either side.

There does seem to be a minimum margin applied somewhere else in the export process, but I still find that 0.25in gives me slightly smaller margins than the default. If you set it to something bigger, like 2in, you'll definitely see that it has an effect.

@asherber : yes, you are right, setting it to 2in does make a difference. I find the default minimum too wide: the user should be able to choose.
Anyway, thanks for your patience and help.

pjeby commented

The extra margin is probably on the body or some other tag. Export as HTML, open in a browser, and use the dev tools to inspect a paragraph and its parents, and that should let you find where it is. Then you can add a print rule to the stylesheet to drop out that body, or else change your page margins to compensate.

@pjeby : thanks for the advice. Unfortunately I am not technical enough to take that route.

As for "change your page margins to compensate": that does not work, as I described above.

can't set margin too。 anyelse other way ?

This issue troubled me quite a long time on my Mac. Nether @page Nor @media custom setting is worked for me. One day I found the PDF exported is affacted by default paper size setting of OSX Printers & Scanners. I customized a paper with 230 mm width, then the margins and font size of exporting PDF is very close to tpyora editor under github theme. Hope it works for you.

add this into theme.css, PDF margins will be a acceptable space.

@media print {
    #write{
        max-width: 100%;
    }
    @page {
        size: A4;
        margin-left: 0;
        margin-right: 0;
    }
}

add this into theme.css, PDF margins will be a acceptable space.

@media print {
    #write{
        max-width: 100%;
    }
    @page {
        size: A4;
        margin-left: 0;
        margin-right: 0;
    }
}

@yantanglife
I can use this to change my rendering experience within Typora by loading it from the Themes menu.
However, when exporting a PDF, the PDF still remains looking the same, just as @pjeby comment did not help in producing adapted exports on PDFs.

Is there any update on this issue?

I "just" want to export something that approximately looks the same as when I see it within Typora.

An update.

Having some themes.css with the following content

@media print {
    html {
        font-size: 12px!important;
        padding: 0 !important;
        margin: 0 !important;
    }
    body.typora-export {
        padding: 0 !important;
        margin: 0 !important;
    }
    .typora-export #write {
        padding: 0 !important;
        margin-top: -2mm !important;
        margin-right: 0mm !important;
        margin-bottom: -2mm !important;
        margin-left: 0mm !important;
    }
}

loading it via the Themes menu, and then Export > PDF has worked for me now - the margins of the pdf are pretty narrow.

This issue was opened almost 3 years ago, and here we are, still messing around with CSS to try to find a workaround. I wonder if Abner is ever going to tackle this properly.

Was working with a coworker on this exact issue and it seems margins work perfectly for the windows Typora but not for mac. So there might be an inconsistency somewhere there.

Any news on this?

Debug mode (Help menu -> Enable Debugging, then right-click on the document and Inspect Element) suggests that Typora is using Safari for its rendering engine as of v0.9.9.35.2 on the Mac.

Safari currently doesn't support CSS' @page as suggested in earlier fixes, that may have worked with a prior rendering engine?

Putting @zecevic-matej's solution in a file named <current-theme>.user.css in Typora's themes folder works for me.

add this into theme.css, PDF margins will be a acceptable space.

@media print {
    #write{
        max-width: 100%;
    }
    @page {
        size: A4;
        margin-left: 0;
        margin-right: 0;
    }
}

This procedure by @yantanglife works for me on Linux by putting it in base.user.css.

2021 is the year and this is still a problem ❓
on Linux when printing with the system dialog to a pdf you get almost zero customization options and it will get incredibly small

mifz commented

An update.

Having some themes.css with the following content

@media print {
    html {
        font-size: 12px!important;
        padding: 0 !important;
        margin: 0 !important;
    }
    body.typora-export {
        padding: 0 !important;
        margin: 0 !important;
    }
    .typora-export #write {
        padding: 0 !important;
        margin-top: -2mm !important;
        margin-right: 0mm !important;
        margin-bottom: -2mm !important;
        margin-left: 0mm !important;
    }
}

loading it via the Themes menu, and then Export > PDF has worked for me now - the margins of the pdf are pretty narrow.

Unfortunately, this does not help as it should be. :/

MarkText export:
Screenshot 2021-02-18 at 20 09 16

Typora export:
Screenshot 2021-02-18 at 20 10 01

An update.
Having some themes.css with the following content

@media print {
    html {
        font-size: 12px!important;
        padding: 0 !important;
        margin: 0 !important;
    }
    body.typora-export {
        padding: 0 !important;
        margin: 0 !important;
    }
    .typora-export #write {
        padding: 0 !important;
        margin-top: -2mm !important;
        margin-right: 0mm !important;
        margin-bottom: -2mm !important;
        margin-left: 0mm !important;
    }
}

loading it via the Themes menu, and then Export > PDF has worked for me now - the margins of the pdf are pretty narrow.

Unfortunately, this does not help as it should be. :/

MarkText export:
Screenshot 2021-02-18 at 20 09 16

Typora export:
Screenshot 2021-02-18 at 20 10 01

Same here. I'm on MacOS and all the solution above didn't work for me. When I export the PDF file the margin is still very large.

Reporting success. -- I solved this via a combination of recommendations above and @abnerlee's support page link, the following successfully defines the right/left margin at 16mm in Export PDF, on Windows, as a default for all themes:

File saved to themes directory: .../Typora/themes/base.user.css

@media print {
    html {
        font-size: 12px!important;
        padding: 0 !important;
        margin: 0mm !important;
    }
    body.typora-export {
        padding: 0 !important;
        margin: 0mm !important;
    }
    .typora-export #write {
        padding: 0 !important;
        margin-top: -2mm !important;
        margin-right: 16mm !important;
        margin-bottom: -2mm !important;
        margin-left: 16mm !important;
    }
}

Whereas, the following (alone) in base.user.css did not define the R/L margins at 16mm:

@media print {
  @page {
  	margin: 25mm 16mm 25mm 16mm; 
	}
}

hth.
(Apologies if this reopens the issue, please re-close if so).