ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Can TPdfViewer fit all pages to a specified width?
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

atrust

10 Posts

Posted - Jul 02 2026 :  23:13:20  Show Profile  Reply
Hi, for example I have a 4-page PDF file where each page has a different page size. I want to permanently normalize all pages so that every page width becomes 1024, and all page contents are scaled accordingly (Fit to 1024 width). The goal is that in any PDF viewer, every page appears with the same width.

First, I calculate the scaling factor:

Scale := 1024 / PdfIn.PageWidth;


Then I create the new page size:

IEGlobalSettings().PdfViewerDefaults.DPI := 300;
PdfOut.AddPage(1024 / 300 * 72, PdfIn.PageHeight * Scale / 300 * 72);


The steps above seem to work correctly.

Next, I try to migrate image objects by iterating through TPdfObject:

if obj.ObjectType = ptImage then
begin
  bmp := TIEBitmap.Create();

  if not PdfIn.Objects[j].GetImageRaw(bmp) then
    PdfIn.Objects[j].GetImage(bmp);

  PdfOut.Objects.AddImage(
    obj.X * Scale,
    obj.Y * Scale,
    obj.Width * Scale,
    obj.Height * Scale,
    bmp
  );
end;



However, I encountered several issues:

1.I understand that PDF coordinate origin is at the bottom-left, so I am ignoring Y-axis inversion issues for now.

2.No matter how I adjust the parameters passed to AddImage, the images are not placed correctly. For example, two images that are originally left-aligned end up with noticeable X-axis offsets in the output PDF. Also, two images that originally have the same size (e.g. two portrait images) may end up with different sizes after conversion.

3.Some images appear to lose transparency or indexed color effects after being transferred, resulting in color differences in the output PDF.

After that, I tried the following approach:
PdfIn.SelectAll;
PdfIn.CopyToClipboard;
PdfOut.AllowObjectEditing := True;
PdfOut.PasteFromClipboard;
PdfOut.ApplyChanges;


However, this results in a blank page with no objects being pasted.

I am aware that rendering each page as a single image and then scaling it back into a PDF is an option, but that would lose object-level structure (text would no longer be selectable or copyable), so I would like to avoid that as a last resort.

Is there a better way to properly scale and migrate all PDF objects while preserving their structure and appearance?

Thanks for any advice.

xequte

39469 Posts

Posted - Jul 02 2026 :  23:59:17  Show Profile  Reply
Hi

Unfortunately you are pushing up against the limits of PDFium's functionality here.

One thing you could try is setting the page size, and then transfomring each of the objects on the page:

https://www.imageen.com/help/TPdfObject.TransformEx.html

or possibly:

http://www.imageen.com/help/TPdfObject.Matrix.html

You'll need to email me for the latest beta to set the page size.


Nigel
Xequte Software
www.imageen.com
Go to Top of Page

atrust

10 Posts

Posted - Jul 04 2026 :  06:12:34  Show Profile  Reply
Thank you for addressing this issue. I've just emailed you as requested.
Go to Top of Page

xequte

39469 Posts

Posted - Jul 06 2026 :  21:13:19  Show Profile  Reply
I've sent you the beta.


Nigel
Xequte Software
www.imageen.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: