PDFsharp - moved to http://forum.pdfsharp.net/ Forum Index PDFsharp - moved to http://forum.pdfsharp.net/
Please visit the new PDFsharp forum at http://forum.pdfsharp.net/
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Important Notice: We regret to inform you that our free phpBB forum hosting service will be discontinued by the end of June 30, 2024. If you wish to migrate to our paid hosting service, please contact billing@hostonnet.com.
XGraphics.ScaleTransform

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    PDFsharp - moved to http://forum.pdfsharp.net/ Forum Index -> Support - moved to http://forum.pdfsharp.net/
View previous topic :: View next topic  
Author Message
jeff2008



Joined: 01 Jul 2008
Posts: 3
Location: Whittier, California

PostPosted: Tue Jul 01, 2008 5:31 pm    Post subject: XGraphics.ScaleTransform Reply with quote

Hi,

I am trying to scale down an PDF document, and I am not invoking any change with the code that I have written. Here is what I have:

Code:

        private void testScaleADocument()
        {
           
            PdfSharp.Drawing.XGraphics gfx;

            //Create Source Document
            File.Copy(this.pdfFileForRead, this.pdfFileForWriteTmp, true);

            //Open the source document
            PdfSharp.Pdf.PdfDocument doc = PdfSharp.Pdf.IO.PdfReader.Open(pdfFileForWriteTmp, PdfSharp.Pdf.IO.PdfDocumentOpenMode.Import);

            // Create the output document
            PdfSharp.Pdf.PdfDocument outputDocument = new PdfSharp.Pdf.PdfDocument();
 
            foreach (PdfSharp.Pdf.PdfPage page in doc.Pages)
            {
                //Add the page to the output document, which returns
                //a new page object relative to the output document
                PdfSharp.Pdf.PdfPage newPage = outputDocument.AddPage(page);

                //Transform the page
                gfx = PdfSharp.Drawing.XGraphics.FromPdfPage(newPage);
                gfx.ScaleTransform(0.9);
               
            }

            outputDocument.Save(this.pdfFileForScalingWrite);
            doc.Close();
            outputDocument.Close();

            Process.Start(this.pdfFileForScalingWrite);
        }
    }


Admittedly I am new to PDFSharp, and I am sure that I must be missing something very simple, but I have not yet figured out what that might be. I appreciate any help that you can provide.

Thanks,

Jeff
Back to top
View user's profile Send private message
jeff2008



Joined: 01 Jul 2008
Posts: 3
Location: Whittier, California

PostPosted: Wed Jul 02, 2008 8:32 pm    Post subject: Reply with quote

I figured out my problem (I got hints from the two pages to one page sample code and from reading the Adobe PDF developers reference). I needed to set the scaling factor first, and then follow it with some sort of draw operation. Merely applying a scaling factor to a graphics object derived from a page does not work. This was definitely a newbie mistake.

Here is some code that utilizes ScaleTransform.

Code:

        private void testScaleADocument()
        {
           
            PdfSharp.Drawing.XGraphics gfx = null;
            PdfSharp.Drawing.XRect rect;
            PdfSharp.Pdf.PdfPage newPage;
 
            //Create Source Document
            File.Copy(this.pdfFileForScaling, this.pdfFileForWriteTmp, true);

            //Open the source document as XPdfForm object
            PdfSharp.Drawing.XPdfForm form =
            PdfSharp.Drawing.XPdfForm.FromFile(this.pdfFileForWriteTmp);

            // Create the output document
            PdfSharp.Pdf.PdfDocument outputDocument
                = new PdfSharp.Pdf.PdfDocument();

            for (int i = 0; i < form.PageCount; i++)
            {
                //Create a new page in the output document, which returns
                //a new page object relative to the output document
                newPage = outputDocument.AddPage();

                //Create a graphics element from the OUTPUT page
                gfx = PdfSharp.Drawing.XGraphics.FromPdfPage(newPage);

                //Set the source page number to indicate which page number to
                //work with.  The page number is one-based.
                form.PageNumber = i + 1;
                rect = new PdfSharp.Drawing.XRect(0, 0, newPage.Width, newPage.Height);

                //Set the scaling, which affects operations that follow.
                //Must be set prior to operations that require scaling.
                gfx.ScaleTransform(0.5);

                // Draw the page identified by the page number (set above)
                // as an image into a XRect
                gfx.DrawImage(form, rect);

            }

            //Write the new output PDF file to disk.
            outputDocument.Save(this.pdfFileForScalingWrite);
           
            //Cleanup
            form.Dispose();
            outputDocument.Close();
            if (gfx != null)
                gfx.Dispose();
               
            //View
            Process.Start(this.pdfFileForScalingWrite);
        }



Best Regards,

Jeff
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    PDFsharp - moved to http://forum.pdfsharp.net/ Forum Index -> Support - moved to http://forum.pdfsharp.net/ All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © phpBB Group. Hosted by phpBB.BizHat.com


Start Your Own YouTube Clone

Free Web Hosting | Free Forum Hosting | FlashWebHost.com | Image Hosting | Photo Gallery | FreeMarriage.com

Powered by PhpBBweb.com, setup your forum now!
For Support, visit Forums.BizHat.com