Git Product home page Git Product logo

pdf-test's Introduction

Maven Central Coverage Status

PDF Test

PDF testing library

Be sure that your code generates correct PDF!

How to use (Hamcrest)

import com.codeborne.pdftest.PDF;
import static com.codeborne.pdftest.PDF.*;
import static org.hamcrest.MatcherAssert.assertThat;

public class PDFContainsTextTest {
  @Test
  public void canAssertThatPdfContainsText() {
    PDF pdf = new PDF(new File("src/test/resources/50quickideas.pdf"));
    assertThat(pdf, containsText("50 Quick Ideas to Improve your User Stories"));
  }
}

How to use (AssertJ)

import com.codeborne.pdftest.PDF;
import static com.codeborne.pdftest.assertj.Assertions.assertThat;

public class PDFContainsTextTest {
  @Test
  public void canAssertThatPdfContainsText() {
    PDF pdf = new PDF(new File("src/test/resources/50quickideas.pdf"));
    assertThat(pdf).containsExactText("50 Quick Ideas to Improve your User Stories");
  }
}

How to start

If you use Maven, add the following dependency to pom.xml:

  <dependency>
    <groupId>com.codeborne</groupId>
    <artifactId>pdf-test</artifactId>
    <version>1.8.1</version>
    <scope>test</scope>
  </dependency>

If you use Gradle, add the following dependency to build.gradle:

  testImplementation 'com.codeborne:pdf-test:1.8.1'

How to contribute

You are welcome to suggest your features and fixes!

Just fork the pdf-test and create pull request. Any contribution is important!

** Become part of open-source community! **

Thanks

Many thanks to these incredible tools that help us to create open-source software:

Intellij IDEA

YourKit Java profiler

License

pdf-test is open-source project and distributed under MIT license

pdf-test's People

Contributors

asolntsev avatar dependabot[bot] avatar pavlogs avatar plagov avatar vitalyshalaev avatar vladimirglinskikh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pdf-test's Issues

Question: asserting with built-in assertions vs get `text` from PDF and use 3rd party assertions?

It is not an issue report and just a question.

I had a use case today when I had to check if the PDF doesn't contain two strings. As I understand, using built-in AssertJ assertions, it can be done as:

val pdf = PDF(File(file.toURI()))
assertThat(pdf).doesNotContainText("null")
assertThat(pdf).doesNotContainText("1 Jan 0001")

Not ideal, IMO, since I have to repeat the same assertion twice with just different parameters.

At the same time, it is possible to get the text from the PDF as a String and use any other assertion library to assert against the String. For example, with "native" AssertJ assertions:

val pdf = PDF(File(file.toURI())).text
Assertions.assertThat(pdf).doesNotContain("null", "1 Jan 0001")

So, the text field in the PDF class is public. Was it done intentionally? And if so, then is there a difference between using assertions from pdf-test comparing to getting a text and assert it the way you want?

Please add the ability to start checking from a specific page or on a specific page of the document.

I know that it is possible to start checking from a specific page in org.apache.pdfbox:
PDFTextStripper pdfStrip = new PDFTextStripper();
pdfStrip.setStartPage(2);
String content = pdfStrip.getText(doc);

But it would be nice to add the ability to take text only from a certain number of the page, I can tell you about this on a separate issue if necessary.

UPD: the end can be set like this
pdfStrip.setEndPage(2);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.