Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 9 of 9

Thread: Transposing a matrix from a PDF stripper

  1. #1
    Junior Member
    Join Date
    May 2020
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Transposing a matrix from a PDF stripper

    I am reading the text from PDF file using PDFBOX. I am able to read properly using "Rectangle2D". But issue where results shows one by one. Instead i want show in Transpose view.
    ================================================== ==================================
    Current Output ( Line 1 and below line 2 and below line3 and goes on)

    PO-00145678

    Vendor : AQ-00067

    Date...................................: 5/10/2021 Expected DeliveryDate...: 6/10/2021
    ================================================== ===================================
    Expected output In single line(Like Transpose) PO-00145678 Vendor : AQ-00067 Date...................................: 5/10/2021 Expected DeliveryDate...: 6/10/2021
    ================================================== ===================================

    Code using
    public class PDFBoxReadFromFile {
     
     
      public static void main(String[] args) throws Exception {
     
        try (PDDocument document = PDDocument.load(new File("C:\\Users\\ed\\Documents\\test2.pdf"))) {
     
          if (!document.isEncrypted()) {
            PDFTextStripperByArea stripper = new PDFTextStripperByArea();
            stripper.setSortByPosition(true);
            Rectangle2D rect4 = new Rectangle2D.Double(210, 160, 230, 25);
            Rectangle rect1 = new Rectangle(55, 290, 225, 17);
     
            Rectangle2D rect2 = new Rectangle2D.Double(281, 255, 255, 20);
            Rectangle2D rect3 = new Rectangle2D.Double(2, 365, 660, 1900);
            stripper.addRegion("class2", rect1);
            stripper.addRegion("class3", rect2);
            stripper.addRegion("class4", rect3);
            stripper.addRegion("class5", rect4);
            PDPage firstPage = document.getPages().get(0);
            stripper.extractRegions(firstPage);
            System.out.println(stripper.getTextForRegion("class5"));
            System.out.println(stripper.getTextForRegion("class2"));
            System.out.println(stripper.getTextForRegion("class3"));
            System.out.println(stripper.getTextForRegion("class4"));
     
            File file = new File("C:/Users/ed/eclipse-workspace/pdfboxreadfromfile/file.txt");
            FileWriter fw = new FileWriter(file);
            PrintWriter pw = new PrintWriter(fw);
            pw.println(stripper.getTextForRegion("class5"));
            pw.println(stripper.getTextForRegion("class2"));
            pw.println(stripper.getTextForRegion("class3"));
            pw.println(stripper.getTextForRegion("class4"));
            pw.close();
     
          }
        } catch (IOException e) {
          System.err.println("Exception while trying to read pdf document - " + e);
        }
      }
    Last edited by Leace; May 25th, 2020 at 04:10 PM. Reason: correction

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Transposing a matrix from a PDF stripper

    In one line
    Use the print method instead of the println method.

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    May 2020
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Transposing a matrix from a PDF stripper

    Done.. I have given current output and expected output

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Transposing a matrix from a PDF stripper

    Did the print method create the desired output?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    May 2020
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Transposing a matrix from a PDF stripper

    No . Struggling to get desired format

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Transposing a matrix from a PDF stripper

    What was the output like with the print method?
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    May 2020
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Transposing a matrix from a PDF stripper

    Output need multiple region in single line..

    Like below

    PO-003334823 Vendor : WL-00051

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Transposing a matrix from a PDF stripper

    Can you show what the output was like using the print method so we can see what the problem is?
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Transposing a matrix from a PDF stripper

    Problem continues here: https://www.dreamincode.net/forums/t...-pdf-stripper/
    and here: https://stackoverflow.com/questions/...-pages-display
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Printing the following Matrix
    By justfun87 in forum Loops & Control Statements
    Replies: 2
    Last Post: June 23rd, 2013, 09:31 AM
  2. Printing the following Matrix
    By justfun87 in forum The Cafe
    Replies: 1
    Last Post: June 22nd, 2013, 04:19 PM
  3. Knapsack problem , check if matrix can fill list of smaller matrix list.
    By ofirattia in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 8th, 2012, 01:20 PM
  4. Matrix Generator
    By kakb9091 in forum What's Wrong With My Code?
    Replies: 29
    Last Post: May 10th, 2012, 12:00 PM
  5. Adding two matrix together
    By papated21 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 2nd, 2011, 01:52 PM

Tags for this Thread