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

How to change the size of each page using PDFsharp & migrado
http://forum.pdfsharp.com/viewtopic.php?f=2&t=2038
Page 1 of 1

Author:  sasi kumar [ Sat Jun 02, 2012 6:43 am ]
Post subject:  How to change the size of each page using PDFsharp & migrado

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.

Author:  Thomas Hoevel [ Mon Jun 04, 2012 8:17 am ]
Post subject:  Re: How to change the size of each page using PDFsharp & mig

Hi!

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

Author:  sasi kumar [ Sat Jun 09, 2012 10:36 am ]
Post subject:  Re: How to change the size of each page using PDFsharp & mig

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;
}

Author:  () => true [ Sat Jun 09, 2012 4:06 pm ]
Post subject:  Re: How to change the size of each page using PDFsharp & mig

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).

Author:  sasi kumar [ Fri Jun 15, 2012 4:38 pm ]
Post subject:  Re: How to change the size of each page using PDFsharp & mig

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.

Author:  () => true [ Sat Jun 16, 2012 8:40 am ]
Post subject:  Re: How to change the size of each page using PDFsharp & mig

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.

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