When I export my Java notes to PDF, the code blocks have a wrong number of tab spaces that makes it hard to read, especially for long sentences in a code block.
Or would somebody explain why? It’s that really a bug, or just a feature?
It might help if others could see the source of the code causing the issue. Surround everything in three or four backticks ` and paste it here.
Also, check the debug help if you haven’t yet:
It’s a bug. Found this by searching tabs pdf
:
(One of the comments in that thread offers a workaround.)
Gah! I have that snippet in my @media snippet list with the problem/workaround, so must have seen that thread.
It’s hard to remember all this stuff! Especially set-it-once stuff like that.
Below is the code I’ve shown in this bug report, actually, every single code block has the same problem, they all have wrong Tabs in PDF.
/*Timer的使用*/
import java.awt.*;
import java.awt.event.*;
import java.time.*;
import javax.swing.*;
public class TimerTest
{
public static void main(String[] args)
{
var listener = new TimePrinter();
var timer = new Timer(1000, listener);
timer.start();
JOptionPane.showMessageDialog(null, "Quit program?");
System.exit(0);
}
}
class TimePrinter implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
System.out.println("At the tone, the time is " + Instant.ofEpochMilli(event.getWhen()));
Toolkit.getDefaultToolkit().beep();
}
}
Thanks for sharing the source. Yes, unfortunately, I see the same spacing issue in an exported PDF. The CSS snippet, courtesy of bvdg, in the bug report that @CawlinTeffid linked to above fixes the spacing and is a good workaround for now:
@media print {
code {
tab-size: 4;
}
}
Thanks for that! I applied it and now my code blocks look great!
I think I’ll keep it working until the bug is fixed
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.