0

I am working with project in which I am handling PDF file in order to verify the valies generated in report but, when I opened it on chrome as well as in adobe pdfviewer it feels little off: pic:

A) In Adobe: enter image description here

B) In chrome: enter image description here

As you can see in both of the mediums the column after "Alaram Value" i.e "Low Limit" isn't visible very well. So I decided to view it in java using PDFBox.Using PDFBox in java I view it in java there too the output was shady

Console O/P: enter image description here

Here too if you can see the value after "Alarm Value " i.e "Low Value" isn't rendered aptly P.S: Console O/P is of the same page as shown in the above screenshots. So is there anyway to handle this scenario and also is there any way to validate the rendered pdf/ validate the downloaded pdf is corrent or not

Java Code:

File file = new File(System.getProperty("user.dir") + "//Download//" + "random" + ".pdf");
        if (file.exists()) {
            System.out.println("Its"+true   );
            PDDocument doc = PDDocument.load(file); 
            PDFTextStripper pdfStripper = new PDFTextStripper();
            pdfStripper.setStartPage(1);
            pdfStripper.setEndPage(1);
            
            int count = doc.getNumberOfPages();
            PDDocumentInformation pdd = doc.getDocumentInformation();
            System.out.println("tile"+pdfStripper.getText(doc));
            System.out.println(count);
            doc.close();
        }

POM.xml:

<!-- https://mvnrepository.com/artifact/org.apache.pdfbox/pdfbox -->
        <dependency>
            <groupId>org.apache.pdfbox</groupId>
            <artifactId>pdfbox</artifactId>
            <version>2.0.27</version>
        </dependency>

    </dependencies>

Please help me if you can

  • Is your question about rendering (i.e. display), text extraction or PDF generation? – Tilman Hausherr Dec 26 '22 at 09:25
  • 1
    This is report design problem, set bigger paper layout size (A3). or set very small font size, if you have a lots of columns. or Reduce columns. Not a program question. – life888888 Dec 26 '22 at 10:31
  • @TilmanHausherr it is about PDF generated cause if it is genraed/rendered properly then. Every other operation also will be carried out accordingly – Avdhut Joshi Dec 26 '22 at 12:43
  • @life888888 is there any way to do that via PDFBox – Avdhut Joshi Dec 26 '22 at 12:44
  • 1
    As far as I understand it, the only way to programmatically verify whether it is rendered correctly would be comparing hash values over the resulting picture with the one of a visually validated reference. Maybe good preflight tools may help to some extent. – Max Wyss Dec 26 '22 at 16:55
  • 1
    PDFBox is rather low level. There are products on top of PDFBox (easytable, boxable) to generate tables. If you want to compare a PDF with an existing "good" pdf then you should convert both to images ( https://stackoverflow.com/questions/23326562/convert-pdf-files-to-images-with-pdfbox ) and compare these images. – Tilman Hausherr Dec 26 '22 at 17:38

0 Answers0