PDF Scaling Issue

Hi There

I am trying to scale a pdf and stamping by a certain percentage however the output file is removing the content.

Below is my code

Code 1


              Dim pEdit As Aspose.Pdf.Facades.PdfPageEditor = New Aspose.Pdf.Facades.PdfPageEditor()

                    For Each page As Page In doc.Pages
                            pEdit.ProcessPages = New Integer() {page.Number}
                            Dim origPageSize = pEdit.GetPageSize(page.Number)
                            pEdit.PageSize = origPageSize
                            pEdit.Zoom = Convert.ToSingle(ComboBox1.Text) / 100.0F '0.9F
                            pEdit.VerticalAlignmentType = VerticalAlignment.Center
                            pEdit.HorizontalAlignment = HorizontalAlignment.Center
                            ' pageint += 1
                        Catch ex As Exception
                            writer = New StreamWriter(errorlog, True)
                            If page Is Nothing Then
                                writer.WriteLine(Now() + " - " + file.ToString + " - Page Number: Unable to get Page Number - " + ex.Message)
                                writer.WriteLine(Now() + " - " + file.ToString + " - Page Number: " + page.Number.ToString + " " + ex.Message)
                            End If

                        End Try



Code 2

                     Dim fileeditor As New PdfFileEditor

                    'fileeditor.ResizeContents(pdfdocument, PdfFileEditor.ContentsResizeParameters.PageResize(pdfdocument.PageInfo.Width, pdfdocument.PageInfo.Height - 15))
                    Dim parameters As New PdfFileEditor.ContentsResizeParameters(leftMargin:=PdfFileEditor.ContentsResizeValue.Percents(3),
                    fileeditor.ResizeContents(pdfdocument, parameters)


Attached are the samples for before and after PDF’s.

Can you help me investigate and see where I am doing it wrong?

Scale and Stamp.zip (8.1 MB)


Can you verify if the scaling factor is not less than zero or greater than 1? when I run the code with a scaling factor outside those ranges I get a white page.

Also, for some reason, your PDF files gave me an error when processing.
The error happened at the moment of saving.

Here is a simple sample in c#

private void Logic(Document doc)
    var pEdit = new PdfPageEditor();

    pEdit.ProcessPages = new int[doc.Pages.Count];
    int count = 0;
    foreach (var page in doc.Pages)
        pEdit.ProcessPages[count] = page.Number;
        var origPageSize = pEdit.GetPageSize(page.Number);
        pEdit.PageSize = origPageSize;
        pEdit.Zoom = 0.5f;
        pEdit.VerticalAlignmentType = VerticalAlignment.Center;
        pEdit.HorizontalAlignment = HorizontalAlignment.Center;

So I used a random PDF I use for testing. Here are the input and output:
ScalingDocument3_input.pdf (3.0 KB)
ScalingDocument3_output.pdf (4.6 KB)

My thoughts are that you are getting a white page(losing content) because of the scaling factor outside of the > 0 and < 1 range.

Hi @carlosmc

I am using 0.95 as my scaling factor. I am also getting exception when saving the page. It is my code 1 example.

With code 2, I am using 3% content resize which is throwing a blank page with the error pop up.

I have tried couple of other random files and it worked fine. Having issues with this particular type of examples created by one of our external application we use. Looks like they are creating a OCR layer on top of PDF which is causing this issue. Is there anyway I can flatten the layer before scaling?

Thank you for checking this quickly

Kind Regards


I am doing a little bit of extra testing in case I figure something out to help you out in the meantime. Then I will contact the dev team.


I was not able to replicate the error with the second code. I did a direct translation to c# and your code worked fine.

I should have ask you before, what version are you using?

This code worked fine with Version 23.1:

var fileeditor = new PdfFileEditor();
var parameters = new ContentsResizeParameters();
parameters.LeftMargin = ContentsResizeValue.Percents(3);
parameters.TopMargin = ContentsResizeValue.Percents(3);
parameters.BottomMargin = ContentsResizeValue.Percents(3);
parameters.RightMargin = ContentsResizeValue.Percents(3);
parameters.ContentsWidth = null; 
parameters.ContentsHeight = null;
fileeditor.ResizeContents(doc, parameters);

I will open a ticket regarding the document with the OCR layer.

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PDFNET-53639

You can obtain Paid Support services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@carlos.molina I am using version 23.1.1. It didn’t throw the exception and saved the PDF however I got a popup from pdf when I opened it. Attached is the popup message. This test is on the OCRd PDF. Non-OCRd PDFs are fine. You can try the same on the samples I have sent you.

screenshot.png (11.6 KB)


@carlos.molina Thank you. We used to have paid support until a few months ago. I will see if we can get paid support back. What are our options to get paid support back?

You can ask the details of paid support when you visit Paid Support for any further questions.