We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Resizing PDF using PdfFileEditor produces corrupt PDF

Hello,

I am resizing pdf’s to normalize their content to all the same paper size, for example, resize a page size from A4 to Letter. For some documents the output is corrupted and returns the following error when you open with acrobat: “there was an error processing an annotation or link. there was a problem reading this document (16)”

Attached is sample input and the output used in the code example below.

string inputFile = @"d:\input\input.pdf";
string outFile = @"d:\output\output.pdf";

            Document doc = new Document(inputFile);
        PdfFileEditor fileEditor = new PdfFileEditor();

        for (int i = 0; i < doc.Pages.Count; i++)
        {
            fileEditor.ResizeContents(doc, new int[] {i + 1},
                PdfFileEditor.ContentsResizeParameters.PageResize(PageSize.PageLetter.Width,
                    PageSize.PageLetter.Height));
        }

        doc.Save(outFile);

Examples.zip (321.1 KB)

@ejt66

Thanks for contacting support.

We have tested the scenario in our environment and managed to replicate the same issue, which you have mentioned. However, when we tried to resize the Pages of document with DOM approach and Aspose.Pdf for .NET 17.12, the output PDF document was fine and no error message was prompted while opening the document in Adobe Reader. Following is the code snippet, which we have tried to test the scenario with DOM model.

string inputFile = dataDir + @"input.pdf";
string outFile = dataDir + @"outputExample_out.pdf";
Document doc = new Document(inputFile);
foreach(Page page in doc.Pages)
{
 page.SetPageSize(PageSize.PageLetter.Width, PageSize.PageLetter.Height);
}
doc.Save(outFile);

outputExample_out.pdf (173.6 KB)

For your kind reference, an output PDF document is also attached. Furthermore, we have also logged an issue related to Facades API as PDFNET-43947 in our issue tracking system. We will further investigate the issue in details and keep you updated with the status of its resolution. Meanwhile you may please use DOM approach with latest version of the API, which resolves the issue.

We are sorry for the inconvenience caused.

Thank you for the work around, unfortunately this does not resize the content. What I want to do is take a pdf that has a paper size of A4 and resize the content down to fit into Letter.

@ejt66

Thanks for writing back.

We have noticed your concerns and also observed same thing while checking the output PDF document, generated by suggested code snippet. We have updated the information of the issue in the logged ticket. As soon as we receive some significant updates regarding resolution of your issue, we will surely inform you. Please spare us little time.

We are sorry for the inconvenience.

Hello,

Is there any update to when this issue might be addressed?

Thanks

Ed

@ejt66

Thanks for posting your inquiry.

We have checked the status of logged ticket and it is not yet resolved, as there are large number of pending issues in the queue which were logged prior to your issue. As soon as we have some definite updates regarding resolution progress of your issue, we will let you know. Please be patient and spare us little time.

We are sorry for the inconvenience.

Hello Asad,

I was wondering if you had an estimation on when this might be worked on?

Thanks

Ed

@ejt66

Thanks for your inquiry.

I am afraid that earlier logged issues has not been yet resolved and we are not in position to share any reliable ETA for now, as there are other pending issues in the queue already. We will definitely provide a fix against your issue after resolving issues logged prior to yours. As soon as we have some definite update regarding resolution progress, we will let you know. We greatly appreciate your patience and comprehension in this regard. Please spare us little time.

We are sorry for the inconvenience.

Any update on a resolution for this bug or should I start looking for a different product?

@ejt66

Thanks for your inquiry.

I am afraid that earlier logged issue has not been yet resolved due to other pending issues in the queue. Please note that, issue has been logged under free support model and will be resolved on first come first serve basis. Also, please note that we do realize the significance of the issue and will definitely consider your concerns while fixing it. As soon as we make some significant progress towards resolution of the issue, we will let you know. Please spare us little time.

We are sorry for the inconvenience.

@asad.ali

We have this same issue using Aspose.PDF v 20.2. Can you please advise if this has been resolved at all or if there are any plans to resolve it?

@daveywc

Regretfully the ticket is not yet resolved due to other high priority tasks and implementations to the API. However, we have recorded your concerns and will surley keep them in view while investigating the ticket. We will inform you as soon as we have some additional updates in this regard. Please spare us some time.

We are sorry for the inconveneince.

Aspose provided the following solution via my paid support request. Hope it helps someone else out in the future:

In case you want to proportionally resize content, please consider using the PdfPageEditor.Zoom:

            double width = PageSize.PageLetter.Width;  //  set page Width
            double height = PageSize.PageLetter.Height;  //  set page Height

            Document doc = new Document("Original Attachment.pdf");
            Aspose.Pdf.Rectangle rect = doc.Pages[1].Rect;
            // isLandscape
            if (rect.Width > rect.Height) {
                double temp = width;
                width = height;
                height = temp;
            }

            double zoomWidth = width / rect.Width;
            double zoomHeight = height / rect.Height;

            PdfPageEditor ppe = new PdfPageEditor();
            ppe.BindPdf(doc);
            ppe.PageSize = new Aspose.Pdf.PageSize((float)width, (float) height);

            ppe.Zoom = (zoomWidth > zoomHeight) ? (float)zoomHeight :  (float)zoomWidth;

            ppe.VerticalAlignmentType = VerticalAlignment.Center;
            ppe.HorizontalAlignment = HorizontalAlignment.Center;

            ppe.Save("Resized with Zoom_PageLetter.pdf");

@daveywc

Thanks for posting the solution here.

It would definitely help others having similar issue.