This is a migrated thread and some comments may be shown as answers.

Scaling PDF document

2 Answers 598 Views
PdfProcessing
This is a migrated thread and some comments may be shown as answers.
Peter
Top achievements
Rank 1
Peter asked on 08 Jun 2020, 01:33 PM

Hi

I'm trying to create report as a PDF file and the report might have several PDF documents as appendixes. 

01.
02.RadFixedDocument reportPdf = CreateReportPdf();
03.foreach(RadFixedDocument appendixPdf = appendixes)
04.{
05.  // here I would like to scale appendixPdf to 80% of reportPdf.
06.  // Then I would like to add some header/footer telling which appendix file that has been added
07.  reportPdf.merge(appendixPdf);
08.}
09.return reportPdf;

 

I hope the above example gives an idea on what I'm trying to do. Hope somebody can give some inspiration on how to accomplish it.

 

Yours
/peter

2 Answers, 1 is accepted

Sort by
0
Accepted
Dimitar
Telerik team
answered on 11 Jun 2020, 08:33 AM

Hi Peter,

To achieve this you should add all page elements in a form and add the form to a new page. This will allow you to fit the form on a smaller page. Here is an example that shows this: 

PdfFormatProvider provider = new PdfFormatProvider();

var doc1 = provider.Import(File.ReadAllBytes(@"..\..\SampleDoc.pdf"));

RadFixedDocument modifiedDocument = new RadFixedDocument();

foreach (var page in doc1.Pages)
{
    RadFixedPage modifiedPage = modifiedDocument.Pages.AddPage();
    var newSize = new System.Windows.Size(page.Size.Width * 0.6, page.Size.Height * 0.6);
    modifiedPage.Size = newSize;

    List<ContentElementBase> contentElements = new List<ContentElementBase>();
    foreach (var contentElement in page.Content)
    {
        contentElements.Add(contentElement);
    }

     
    page.Content.Clear();

    FormSource formSource = new FormSource
    {
        Size = page.Size
    };

    foreach (var contentElement in contentElements)
    {
        formSource.Content.Add(contentElement);
    }

    Form form = modifiedPage.Content.AddForm(formSource);
    form.Width = newSize.Width;
    form.Height = newSize.Height;

    //form.Position.Translate(-25, -25);
    //form.Position.Scale(0.8, 0.8);
}

byte[] data = provider.Export(modifiedDocument);
File.WriteAllBytes(@"scaled.pdf", data);

Please note that you can scale the form as well (see the commented lines). 

I hope this helps. Should you have any other questions do not hesitate to ask.

Regards,
Dimitar
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Peter
Top achievements
Rank 1
answered on 12 Jun 2020, 06:45 AM

Works perfectly! Thank you very much :-)

Yours
/peter

 

Tags
PdfProcessing
Asked by
Peter
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Peter
Top achievements
Rank 1
Share this question
or