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

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Can TPdfViewer fit all pages to a specified width?

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

View 
UserName:
Password:
Format  Bold Italicized Underline  Align Left Centered Align Right  Horizontal Rule  Insert Hyperlink   Browse for an image to attach to your post Browse for a zip to attach to your post Insert Code  Insert Quote Insert List
   
Message 

 

Emoji
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Black Eye [B)]
Frown [:(] Shocked [:0] Angry [:(!] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
atrust Posted - Jul 02 2026 : 23:13:20
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.
3   L A T E S T    R E P L I E S    (Newest First)
xequte Posted - Jul 06 2026 : 21:13:19
I've sent you the beta.


Nigel
Xequte Software
www.imageen.com
atrust Posted - Jul 04 2026 : 06:12:34
Thank you for addressing this issue. I've just emailed you as requested.
xequte Posted - Jul 02 2026 : 23:59:17
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