PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Tue Mar 19, 2024 3:16 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Sat Jun 02, 2012 6:43 am 
Offline

Joined: Sat Jun 02, 2012 3:12 am
Posts: 6
I am using PDFSharp and Migradoc, i am not able to change the size of each page please guide me how to change the size of each page using migradoc.


Top
 Profile  
Reply with quote  
PostPosted: Mon Jun 04, 2012 8:17 am 
Offline
PDFsharp Guru
User avatar

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

Please start here:
viewtopic.php?f=2&t=832&p=2094#p2094

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Sat Jun 09, 2012 10:36 am 
Offline

Joined: Sat Jun 02, 2012 3:12 am
Posts: 6
I didnt find suitable answer for my question in the forum, that's why i have posted this question.

I am using MigraDoc Foundation and GDI+
Version is 1.30

I tried to change the page size based on the size of the image, but it does not allow me to change individual page since its a paragraph, i have marked in red color.

My requirement is based on each image the each doument page size has to be set it.

Reply as soon as possible.

public static Document CreateDocument(DataSet ds)
{
//DataAccessLayer objDAL = null;
//DataSet ds = null;
// Create a new MigraDoc document
Document document = new Document();
document.DefaultPageSetup.PageHeight = 927;
document.DefaultPageSetup.PageWidth = 702;
document.Info.Title = "MedNeutal Claim";
document.Info.Subject = "Processed MedNeutral Claim";
document.Info.Author = "Minacs IT Services";
document.DefaultPageSetup.BottomMargin = 36;
document.DefaultPageSetup.TopMargin = 36;
document.DefaultPageSetup.LeftMargin = 36;
document.DefaultPageSetup.RightMargin = 36;

Styles.DefineStyles(document);

//Cover.DefineCover(document);
TableOfContents.DefineTableOfContents(document, ds);

if (ds != null)
{
int InsightPageCount = 5;
string BlankPageImagePath = System.Configuration.ConfigurationSettings.AppSettings.Get("BlankPageImagePath");
string InsightBookmark = "InsightBlankPage";
int iIndexCount = 0;
int iInsightPageCount = 0;

int iIndexCounter = 0;
int iPageCounter = 1;

//Document Images
if (ds.Tables[1].Rows.Count > 0)
{
foreach (DataRow dr1 in ds.Tables[1].Rows)
{
if (dr1["ImageName"].ToString() != null)
{
string imagepath = Convert.ToString(dr1["Imagepath"]);
//imagepath = imagepath.Replace(@"\\10.226.2.26\Medneutral\Med_UAT\Destiny\1442940\ProcessedOutput", @"C:\PDFSharp\ClaimImages");

//document.LastSection.AddPageBreak();
Paragraph paragraph = document.LastSection.AddParagraph();
paragraph.Style = "Normal";

paragraph.AddFormattedText(Convert.ToString(dr1["StartDate"].ToString()), "Heading1");
//paragraph.AddFormattedText(Convert.ToString(dr1["Date"].ToString()), "Heading1");


MigraDoc.DocumentObjectModel.Shapes.Image image = paragraph.AddImage(imagepath);

System.Drawing.Image img;// = new System.Drawing.Image();
img = System.Drawing.Image.FromFile(imagepath);

paragraph.Document.DefaultPageSetup.PageHeight = img.Width;
paragraph.Document.DefaultPageSetup.PageWidth = img.Height;


if (ds.Tables[0].Rows.Count > 0)
{
if (ds.Tables[0].Rows[iIndexCounter].ItemArray[6].ToString() == iPageCounter.ToString())
{
if (iIndexCounter != ds.Tables[0].Rows.Count - 1)
{
iIndexCounter = iIndexCounter + 1;
}
paragraph.Style = "Heading1";
paragraph.AddBookmark(Convert.ToString(dr1["ImageName"].ToString()));
}
}
}
iPageCounter = iPageCounter + 1;
}
}
}
return document;
}


Top
 Profile  
Reply with quote  
PostPosted: Sat Jun 09, 2012 4:06 pm 
Offline
PDFsharp Expert
User avatar

Joined: Wed Dec 09, 2009 8:59 am
Posts: 339
Hi!
sasi kumar wrote:
I tried to change the page size based on the size of the image, but it does not allow me to
change individual page since its a paragraph, i have marked in red color.
PageSize is a property of the section. You can start a new section for every image and set the PageSize of this section to your needs (do not modify MigraDoc's DefaultPageSize - create a copy (Clone()) and modify that).
Please note that page size is specified in Points (not pixels). Not all image files have the correct size set. If images come from different sources, page sizes may vary very much.

I think it's wrong to change the size of every page according to the image.
I'd use a fixed page size and draw the image as large as possible maintaining it's aspect ratio. This is easier for the user flipping through the PDF (just my humble opinion).

_________________
Öhmesh Volta ("() => true")
PDFsharp Team Holiday Substitute


Top
 Profile  
Reply with quote  
PostPosted: Fri Jun 15, 2012 4:38 pm 
Offline

Joined: Sat Jun 02, 2012 3:12 am
Posts: 6
PageSize property is not there in Migradoc, it is available only in PDFSharp but i am using Migradoc for generating the PDF document, So i am not able to set the page size. Please guide me on this, if possible please share some sample code.


Top
 Profile  
Reply with quote  
PostPosted: Sat Jun 16, 2012 8:40 am 
Offline
PDFsharp Expert
User avatar

Joined: Wed Dec 09, 2009 8:59 am
Posts: 339
MigraDoc creates new pages automatically.
All pages in a section have the same page size.
You can set the page size for each section individually. If you need different page sizes for each image, add a new section for each image.

This is MigraDoc code, this is how you can set the page size:
Code:
Section section = document.AddSection();
section.PageSetup = document.DefaultPageSetup.Clone();
section.PageSetup.PageWidth = "32cm";
section.PageSetup.PageHeight = "22cm";
Please note that a section inherits the PageSetup from the previous section unless you specify a new PageSetup.

_________________
Öhmesh Volta ("() => true")
PDFsharp Team Holiday Substitute


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

All times are UTC


Who is online

Users browsing this forum: Bing [Bot] and 33 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