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 6707919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:41:48+00:00 2026-05-26T07:41:48+00:00

I need to edit a specific page from a PDF file and I have

  • 0

I need to edit a specific page from a PDF file and I have to save that page only as a separate PDF file. I have successfully completed the job. The input file is of letter size pages. But now what I need is to save the edited page in A4 size. Can anyone help me. I am waiting for the responses.

Following is my code.

import java.awt.Color;

import java.io.FileOutputStream;
import java.io.IOException;

import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Element;
import com.lowagie.text.Font;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.ColumnText;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfReader;
import com.lowagie.text.pdf.PdfStamper;

public class pdfEdit {

    private static String INPUTFILE = "./pdf/eng.pdf";
    private static String OUTPUTFILE = "./pdf/output.pdf";
    private static String footerRight = "Web content and services";
    private static String footerLeft = "All Rigths Reserved";
    private static Document document;

    public static void main(String[] args) throws IOException, DocumentException {

        document = new Document();      
        document.open();

        PdfReader reader = new PdfReader(INPUTFILE);
        PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(OUTPUTFILE));      

        int editingPage = 3;

        PdfContentByte cb = stamper.getOverContent(editingPage);
        cb.rectangle(10, 10, 550, 30);
        cb.setRGBColorFill(255, 255, 255);
        cb.fill();

        PdfContentByte cByte = stamper.getOverContent(editingPage);
        editFooterText(cByte);
        reader.selectPages(Integer.toString(editingPage));

        stamper.close();
        document.close();
    }


    private static void editFooterText(PdfContentByte cByte) throws DocumentException {

        Font footerFont = new Font(Font.HELVETICA, 5f, Font.NORMAL, Color.BLACK);

        ColumnText cTextLeft = new ColumnText(cByte);
        Paragraph leftPara = new Paragraph();
        cTextLeft.setAlignment(Element.ALIGN_LEFT);
        cTextLeft.setSimpleColumn(document.left(), 10, 500, document.bottom());
        Chunk strFooterLeft = new Chunk(footerLeft, footerFont);
        leftPara.add(strFooterLeft);
        cTextLeft.addElement(leftPara);
        cTextLeft.go();

        ColumnText cTextRight = new ColumnText(cByte);
        cTextRight.setSimpleColumn(document.left(), 10, 430, document.bottom());
        Paragraph Rightpara = new Paragraph();
        Chunk strfooterRight = new Chunk(footerRight, footerFont);
        Rightpara.setAlignment(Element.ALIGN_RIGHT);
        Rightpara.add(strfooterRight);
        cTextRight.addElement(Rightpara);
        cTextRight.go();
    }       
}
  • 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-26T07:41:49+00:00Added an answer on May 26, 2026 at 7:41 am
    private static void createPDFFile() throws FileNotFoundException {
            OutputStream outputStream = new FileOutputStream("./A4SizePdf.pdf");
            Document document = new Document(PageSize.A4, 40, 40, 40, 40);
            try {
    
                PdfWriter writer = PdfWriter.getInstance(document, outputStream);
                PdfReader reader = new PdfReader(./InputPdf.pdf);
                reader.setViewerPreferences(editedPageNo);
    
                PdfImportedPage page = writer.getImportedPage(reader, 1);
                document.open();                
    
                PdfContentByte cb = writer.getDirectContent();
                cb.addTemplate(page, 1.4f, 0, 0, 1.19f, -13, 7);
                document.close();
                outputStream.close();           
                setFooter();
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                if (document.isOpen())
                    document.close();
                try {
                    if (outputStream != null)
                        outputStream.close();
                } catch (IOException ioe) {
                    ioe.printStackTrace();
                }
            }
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to edit XML files on a small Linux box that we have
I have a page that generates json data from several fields and I want
In onw of our application, we have some reports that need very specific margins
I need to edit the web.config file on a live Sharepoint environment, but I'm
I need to edit (using javascript) an SVG document embedded in an html page.
Problem: I have to support users who need to edit web pages. Some of
i'm working with TFS and i need to edit file localy without checking it
From my previous question for selecting specific html text, I have gone through this
I have an index page for listing products. From this page I would like
I need to do some model-level validation in an MVC 3 edit page. (To

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.