Do you own a Debenu Quick PDF Library version 7, 8, 9, 10, 11, 12, 13 or iSEDQuickPDF license? Upgrade to Debenu Quick PDF Library 14 today!

Debenu Quick PDF Library - PDF SDK Community Forum Homepage
Forum Home Forum Home > For Users of the Library > Sample Code
  New Posts New Posts RSS Feed - Creating a multi page PDF from a multipage TIFF
  FAQ FAQ  Forum Search   Register Register  Login Login

Creating a multi page PDF from a multipage TIFF

 Post Reply Post Reply
Author
Message
 Rating: Topic Rating: 1 Votes, Average 5.00  Topic Search Topic Search  Topic Options Topic Options
AndrewC View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 08 Dec 10
Location: Geelong, Aust
Status: Offline
Points: 841
Post Options Post Options   Thanks (1) Thanks(1)   Quote AndrewC Quote  Post ReplyReply Direct Link To This Post Topic: Creating a multi page PDF from a multipage TIFF
    Posted: 01 Feb 12 at 9:06AM

Here is some code that correctly imports and scales pages from a multipage TIFF image and creates a multipage PDF file.

NOTE : ImageWidth and ImageHeight return the size of the image in pixels, not points, so we must calculate the correct page size by extracting the DPI from the image.

Andrew.

        private void AddImageFromFile_Click(object sender, EventArgs e)
        {
            openFileDialog1.Filter = "TIFF Files|*.tif";

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                QP.NewDocument();

                int pages = QP.GetImagePageCount(openFileDialog1.FileName);
                if (pages == 0)
                    pages = 1;

                for (int i=1;i<=pages;i++)
                {
                    if (i != 1)
                        QP.NewPage();

                    int id = QP.AddImageFromFile(openFileDialog1.FileName, i);

                    QP.SelectImage(id);

                    int dpix = QP.ImageHorizontalResolution();
                    int dpiy = QP.ImageVerticalResolution();

                    if (dpix == 0) dpix = 72;
                    if (dpiy == 0) dpiy = 72;

                    double ImageWidthInPoints = (double)QP.ImageWidth() / dpix * 72.0; // assumming dpi units
                    double ImageHeightInPoints = (double)QP.ImageHeight() / dpiy * 72.0;

                    QP.SetPageDimensions(ImageWidthInPoints, ImageHeightInPoints);
                    QP.SetOrigin(1);
                    QP.DrawImage(0, 0, ImageWidthInPoints, ImageHeightInPoints);

                }

                QP.SaveToFile("out.pdf");

                QP.RemoveDocument(QP.SelectedDocument());
            }
        }

Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.01
Copyright ©2001-2014 Web Wiz Ltd.

Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. AboutContactBlogSupportOnline Store