Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6597609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:13:52+00:00 2026-05-25T18:13:52+00:00

My application generates HTML reports. The users want the report to fit a single

  • 0

My application generates HTML reports. The users want the report to fit a single PDF page – doesn’t matter how much zoom you need for it.

Currently they render the page in Internet Explorer 8, and manually define a custom zoom level at the Print Preview window, then they print the page to PDF. I need to perform this operation automatically. How to achieve this?

The reports are actually created by BIRT, so BIRT-based solution is fine, too. Using the BIRT zoom options scale the document to fit height, but it doesn’t fit width (because it first renders the HTML then apply the zoom).

Now I’m trying to use Flying Saucer to convert to PDF the BIRT-generated HTML.

I’ve saw similar questions related to abcPDF (.NET) and CF8 (se below) but I need a Java-based solution, and I wasn’t able to use the same techniques with Flying Saucer or BIRT.

Tell abcPdf to scale the html to fit on a single pdf page

scale PDF to single page

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T18:13:53+00:00Added an answer on May 25, 2026 at 6:13 pm

    That’s the solution I found, based on Flying Saucer / iText:

    // A4 paper size = 297x210 mm
    int PAGE_WIDTH = 2100;
    int PAGE_LENGTH = 2970;
    float MARGIN = 19.05f; // 0.75 inch
    
    int width = PAGE_WIDTH; 
    
    // Java2DRenderer.NO_HEIGHT = -1 (it's private)
    // if used the required height is computed
    Java2DRenderer renderer = new Java2DRenderer(dom, width, -1); 
    BufferedImage img = renderer.getImage();
    
    // Adjusts width based on required height
    int height = img.getHeight(); 
    width = (int) Math.round(height * PAGE_WIDTH / PAGE_LENGTH);
    
    // Render same document again, now with the right dimensions
    renderer = new Java2DRenderer(dom, width, height);
    img = renderer.getImage();
    
    com.lowagie.text.Document pdf = new com.lowagie.text.Document(PageSize.A4);
    pdf.setMargins(MARGIN,MARGIN,MARGIN,MARGIN); 
    PdfWriter.getInstance(pdf, new FileOutputStream(args[0]+".pdf"));
    pdf.open();
    com.lowagie.text.Image pdfImage = com.lowagie.text.Image.getInstance(img,Color.WHITE);
    Rectangle ps = pdf.getPageSize();
    pdfImage.scaleAbsolute(
        ps.getWidth()-pdf.leftMargin()-pdf.rightMargin(),
        ps.getHeight()-pdf.topMargin()-pdf.bottomMargin()
    );
    pdf.add(pdfImage);
    pdf.close();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background: we have an application that generates reports from HTML (that may or may
My Java Swing application generates an HTML file, and I want to open it
Is there an application out there that Generates an HTML form from a PDF
I have a some of html strings that my application generates. Each html 'snippet'
My web application generates pdf files and either e-mails or faxes them to our
My application generates html emails with tables used for reporting. s = smtplib.SMTP(self.server) s.sendmail(self.addrFrom(),
I'm working with a rather large .net web application. Users want to be able
I'm finishing a PDF report implementation for my application, which works perfectly in development
On my two-page web application, users progressively enter info and make selections on page
I have a link as follows. @Html.ActionLink(Create Report, Screenreport, Reports, null, new { @class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.