PDFsharp & MigraDoc Forum

PDFsharp - A .NET library for processing PDF & MigraDoc - Creating documents on the fly
It is currently Sun Sep 14, 2025 7:40 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules

Also see our new Tailored Support & Services site.



Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Tue Aug 25, 2015 1:54 pm 
Offline

Joined: Tue Aug 25, 2015 1:46 pm
Posts: 2
Hi,

I am new to PDFSharp.

I have a PDF document consisting of a table with some data saved on my hard drive by my c# service. The size of the table is actually meant to print on a compliments slip sized page, so about 1/3 of an A4 page.

I need to rotate the table by 90" then save it back, as the paper for these cashier receipts needs to be fed long-wise into the printer using the manual feed tray.

So I tried the below code to open an existing document:
Code:
               // Rotate and save the PDF;
                PdfDocument doc = new PdfDocument(reportName); ;
                var page = doc.Pages[0];
                page.Rotate = 90;

                //Save pdf file.
                doc.Save("PDFSharp _" + reportName);
                doc.Close();


Before I run the above code, the document referenced by reportName is 25KB...after that line of code executes, the document is 0 bytes in size.

So obviously I am creating a new document and overwriting my existing one.

What is the correct method call to open an existing single page PDF, rotate it's single page, and save it?

Thanks


Top
 Profile  
Reply with quote  
PostPosted: Tue Aug 25, 2015 2:05 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3135
Location: Cologne, Germany
Hi!

There are many samples that modify (Watermark) or import (Two Pages on One, Combine Documents) PDF pages.
Please check those samples to get started:
http://www.pdfsharp.net/wiki/PDFsharpSamples.ashx

Specifying a filename with "new PdfDocument(reportName)" allows to later call "Save()" without filename. It does not pretend to import the file.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Tue Aug 25, 2015 2:08 pm 
Offline

Joined: Tue Aug 25, 2015 1:46 pm
Posts: 2
Thanks Thomas, I will take a look.

In fact I managed to do it by the below:
Code:
                // Rotate and save the PDF;
                PdfDocument doc= PdfReader.Open(reportName);
                var page = doc.Pages[0];
                page.Rotate = 90;

                //Save pdf file.
                doc.Save("PDFSharp _" + reportName);
                doc.Close();


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 172 guests


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 post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group