PDFsharp & MigraDoc Foundation
http://forum.pdfsharp.com/

Multi page Tiff to Pdf
http://forum.pdfsharp.com/viewtopic.php?f=2&t=4318
Page 1 of 1

Author:  m07thomson [ Thu Feb 03, 2022 4:07 pm ]
Post subject:  Multi page Tiff to Pdf

I am using the following code to convert a tiff file to a pdf, but it is only showing the 1st page of the tiff file.

If there are 3 pages in the tiff file, there will be 3 pages in the pdf, but they will all be the same (the 1st page).

Image MyImage = Image.FromFile(filePath);

PdfDocument doc = new PdfDocument();

XImage img = XImage.FromFile(filePath);

for (int PageIndex = 0; PageIndex < MyImage.GetFrameCount(FrameDimension.Page); ++PageIndex)
{
MyImage.SelectActiveFrame(FrameDimension.Page, PageIndex);

var page = new PdfPage();

if (img.PixelWidth > img.PixelHeight)
{
page.Orientation = PageOrientation.Landscape;
}
else
{
page.Orientation = PageOrientation.Portrait;
}
doc.Pages.Add(page);

XGraphics xgr = XGraphics.FromPdfPage(doc.Pages[PageIndex], XGraphicsPdfPageOptions.Replace);

xgr.DrawImage(img, 0, 0);
}
doc.Save(newFilePath);
doc.Close();
img.Dispose();
MyImage.Dispose();

Any help would be appreciated.

Thanks.

Author:  TH-Soft [ Mon Feb 07, 2022 11:39 am ]
Post subject:  Re: Multi page Tiff to Pdf

You select the active frame for "MyImage", but you draw "img" in the PDF file.
Try creating "img" from "MyImage" after selecting the frame.

See also:
viewtopic.php?p=12586#p12586

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/