Git Product home page Git Product logo

Comments (9)

mkl-public avatar mkl-public commented on June 27, 2024

Can one assume that the content of the pages already fits on A4 and one merely has to increase or decrease the margins? Then it suffices to change media and crop boxes.
Or is it necessary to scale or even reflow the content?

from openpdf.

Lychengit avatar Lychengit commented on June 27, 2024

It should be necessary to scale. Such as this pdf:
dabaoz1.pdf
It's too big to see it all.

from openpdf.

asturio avatar asturio commented on June 27, 2024

You want to read an existing PDF and than recreate it with a "better" PageSize?

from openpdf.

Lychengit avatar Lychengit commented on June 27, 2024

image
change into
image

from openpdf.

asturio avatar asturio commented on June 27, 2024

I think, if you want to scale and reflow the content, you can use OpenPDF to do this. But this functionality is quite high level to implement directly in the library. I don't even know how one could do this. The text must be extracted, and den inserted in the new document. And images too. A very complex task.

from openpdf.

Lychengit avatar Lychengit commented on June 27, 2024

I tried itext,It can move the content of the page, but AcroForms are lost,How to transfer AcroForms as is,Like the 6.pdf this file, how complete scale:

PdfReader pdfReader = new PdfReader(source);
Document doc = new Document();
PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream(target));
doc.open();
PdfContentByte cb = writer.getDirectContent();
for(int i = 1; i <= pdfReader.getNumberOfPages(); i++){
PdfImportedPage page = writer.getImportedPage(pdfReader, i);
float width = page.getWidth();
float height = page.getHeight();
doc.setPageSize(new com.itextpdf.text.Rectangle(PageSize.A4.getHeight(), PageSize.A4.getWidth()));
doc.newPage();
float widthScale = getWidthScale(height);
float heightScale = getHeightScale(width);
cb.addTemplate(page, widthScale, 0, 0, heightScale,0,0);
}
doc.close();

from openpdf.

mkl-public avatar mkl-public commented on June 27, 2024

Copying the page with getImportedPage actually only copies the static page content, annotations are lost. Thus, I would propose instead to change the media box and crop box of the page and prepend a scaling transformation to the page content stream.

Scaling (obviously) changes the coordinates of the content. Thus, all other objects that also contain coordinates on the page, need to be adjusted. This includes the annotations but also objects like link destinations.

from openpdf.

Lychengit avatar Lychengit commented on June 27, 2024

Is there any code example of specific implementation? thanks.

from openpdf.

asturio avatar asturio commented on June 27, 2024

I fear there is no such an example. This is a very specific problem, and scaling thinks around is not trivial. Such an example "could" be in pdf-toolbox, but maybe it won't be a "simple" one.

from openpdf.

Related Issues (20)

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.