Export a large image (bigger than a page) to PDF file

1 Answer 311 Views
PdfProcessing
Adriana Lorena
Top achievements
Rank 1
Adriana Lorena asked on 20 Jun 2022, 05:52 PM

Hello,

I'm just learning to use Telerik so I hope you can help me. I have a large image of several pages and I need to export it complete to a pdf file. The pdf file must have the number of pages needed so the image is all there and it shouldn't have any added header (neither blank space) at top of evey page.

Right now, I'm able to export an image using RadFixedPage and PDFFormatProvider, but the image is only in one page and it's not complete.

RadFixedDocument document = new RadFixedDocument();
RadFixedPage page = document.Pages.AddPage();

PdfFormatProvider provider = new PdfFormatProvider();
FixedContentEditor editor = new FixedContentEditor(page);

....

using (Stream output = File.OpenWrite("output.pdf"))
{
    provider.Export(document, output);
}

 

Thanks in advance,

1 Answer, 1 is accepted

Sort by
0
Accepted
Dimitar
Telerik team
answered on 21 Jun 2022, 05:27 AM

Hello Adriana ,

We do not have a built-in method that split the images across pages. This should be done manually and each part of the image should be added to the page. Here is a simple example that shows a sample implementation:

RadFixedDocument document = new RadFixedDocument();

Bitmap bmp = new Bitmap(@"..\..\tick.png");

var firstHalf = bmp.Clone(new Rectangle(0, 0, bmp.Width, bmp.Height / 2), System.Drawing.Imaging.PixelFormat.DontCare);
var secondHalf = bmp.Clone(new Rectangle(0, bmp.Height / 2, bmp.Width, bmp.Height / 2), System.Drawing.Imaging.PixelFormat.DontCare);

RadFixedPage page = document.Pages.AddPage();
FixedContentEditor editor = new FixedContentEditor(page);
var ms = new MemoryStream();
firstHalf.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
ms.Seek(0, SeekOrigin.Begin);
editor.DrawImage(ms, new System.Windows.Size((int)page.Size.Width, (int)page.Size.Height));

RadFixedPage page1 = document.Pages.AddPage();
FixedContentEditor editor1 = new FixedContentEditor(page1);
var ms1 = new MemoryStream();
secondHalf.Save(ms1, System.Drawing.Imaging.ImageFormat.Png);
ms1.Seek(0, SeekOrigin.Begin);
editor1.DrawImage(ms1, new System.Windows.Size((int)page1.Size.Width, (int)page1.Size.Height));

 Should you have any other questions do not hesitate to ask.

Regards,
Dimitar
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Adriana Lorena
Top achievements
Rank 1
commented on 21 Jun 2022, 07:44 PM

Hello Dimitar,

Thank you very much. This is working for me.

Best regards,

Adriana

Upscale
Top achievements
Rank 1
commented on 06 Aug 2022, 12:06 PM

What Image size is thought to be the "large" for Telerik. I mean what can stop my bit from processing. I have been facing the issue for two days. Can anyone help me?
Dimitar
Telerik team
commented on 08 Aug 2022, 11:23 AM

Hi,

There is no specific limitation and in this case, the image size depends on the page size. I am not sure that you are experiencing the same issue. I would recommend posting a new ticket for this and describing your requirements in detail and providing all required files so we can reproduce this on our site. This will allow us to properly investigate your issue and provide a solution.  

Thank you in advance for your patience and cooperation. 

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