Search code examples
pdfidewhitespacecopy-paste

I can't copy exact amount of whitespaces from a pdf file


For homework, I need to copy this template from pdf but I can't get exact amount of whitespaces from copy pasting. How can I solve that?

Code from pdf:

enter image description here

Code after copy-paste:

System.out.println("j\tK--A--F--V--Ş--V--F--A--K");
System.out.println(" \t| | | |\\ | /| | | |");
System.out.println("i\t-------------------------");
System.out.println(" \t| | | |/ | \\| | | |");
System.out.println("h\t---T-----------------T---");
System.out.println(" \t| | | | | | | | |");
System.out.println("g\tE-----E-----E-----E-----E");
System.out.println(" \t| | | | | | | | |");
System.out.println("f\t-------------------------");
System.out.println(" \t| |");
System.out.println("e\t-------------------------");
System.out.println(" \t| | | | | | | | |");
System.out.println("d\te-----e-----e-----e-----e");
System.out.println(" \t| | | | | | | | |");
System.out.println("c\t---t-----------------t---");
System.out.println(" \t| | | |/ | \\| | | |");
System.out.println("b\t-------------------------");
System.out.println(" \t| | | |\\ | /| | | |");
System.out.println("a\tk--a--f--v--ş--v--f--a--k");
System.out.println();
System.out.println(" \t1--2--3--4--5--6--7--8--9");

Solution

  • Use a pdftotext fixed width "-LAYOUT" extractor to inject the same amount of whitespace bars, enter image description here However, it only takes a fast find and replace to correct in 15 seconds, thus faster than write a line of code and test it !

    System.out.println("j\tK--A--F--V--Ş--V--F--A--K");
    System.out.println(" \t|  |  |  |\\| /|  |  |  |");
    System.out.println("i\t-------------------------");
    System.out.println(" \t|  |  |  |/ |\\|  |  |  |");
    System.out.println("h\t---T-----------------T---");
    System.out.println(" \t|  |  |  |  |  |  |  |  |");
    System.out.println("g\tE-----E-----E-----E-----E");
    System.out.println(" \t|  |  |  |  |  |  |  |  |");
    System.out.println("f\t-------------------------");
    System.out.println(" \t|                       |");
    System.out.println("e\t-------------------------");
    System.out.println(" \t|  |  |  |  |  |  |  |  |");
    System.out.println("d\te-----e-----e-----e-----e");
    System.out.println(" \t|  |  |  |  |  |  |  |  |");
    System.out.println("c\t---t-----------------t---");
    System.out.println(" \t|  |  |  |/ |\\|  |  |  |");
    System.out.println("b\t-------------------------");
    System.out.println(" \t|  |  |  |\\| /|  |  |  |");
    System.out.println("a\tk--a--f--v--ş--v--f--a--k");
    System.out.println();
    System.out.println(" \t1--2--3--4--5--6--7--8--9");
    

    But you need to check if the spaces are correctly exported by the extractor as a Non-proportional "Typewriter" font such as historic Courier