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 

How to auto adding pages when you've run out of space

 
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
nass



Joined: 24 Mar 2009
Posts: 3
Location: TROYES / FRANCE

PostPosted: Tue Mar 24, 2009 4:08 pm    Post subject: How to auto adding pages when you've run out of space Reply with quote

Hi everybody,
I am a new PDFSharp french user and in fact I've encountered a worry.
I bind one MigraDoc paragraph with MS SQL data source and I dont know how to auto adding pages when you've out of space.

I give you my code, please help me
Idea

Code:
    protected void LinkButtonPDF_Click(object sender, EventArgs e)
    {

        DateTime time;
        // Create new PDF document
        PdfDocument document = new PdfDocument();
        time = document.Info.CreationDate;
        document.Info.Title = "Fiche produit FISA";
        document.Info.Author = "FAUCONNET Ingénierie SA";
        document.Info.Subject = "Server time: " +
        time.ToString("F", CultureInfo.InvariantCulture);

        // Create new page
        PdfPage page = document.AddPage();
        page.Width = XUnit.FromMillimeter(210);
        //page.Height = XUnit.FromMillimeter(297);

        // Create graphics object and draw clock
        XGraphics gfx = XGraphics.FromPdfPage(page);
        //XGraphics formGfx = XGraphics.FromForm(page);
        // Create a font
        XFont font = new XFont("Verdana", 12, XFontStyle.Regular);
        XFont font2 = new XFont("Trebuchet MS", 25, XFontStyle.Bold);
        XFont font3 = new XFont("Trebuchet MS", 17, XFontStyle.Bold);
        XFont fontTitre = new XFont("Trebuchet MS", 15, XFontStyle.Underline);

        String path = "D:/HostingSpaces/jerome@fisa.fr/fisa.fr.sphere-hosting.com/wwwroot/images/bg_top.png";
        XImage img = XImage.FromFile(path);
        gfx.DrawImage(img, 0, 0, page.Width, 112);

        String path2 = "D:/HostingSpaces/jerome@fisa.fr/fisa.fr.sphere-hosting.com/wwwroot/images/logo00.png";
        XImage logo = XImage.FromFile(path2);
        gfx.DrawImage(logo, 10, 15);

        gfx.DrawString("Services et support technique", font2, XBrushes.DarkSlateGray, new XRect(0, 35, page.Width, page.Height), XStringFormat.TopCenter);

        gfx.DrawString("Logiciel Fauconnet Ingénirie SA", font3, XBrushes.DarkGray, new XRect(0, 57, page.Width, page.Height), XStringFormat.TopCenter);

        String StrConnect = ConfigurationManager.ConnectionStrings["supportConnectionString"].ConnectionString;
        SqlConnection Connection = new SqlConnection(StrConnect);
        Connection.Open();

        SqlCommand command = new SqlCommand("SELECT titre_fr, commentaire_fr, date_publication FROM articles INNER JOIN titre_traduction ON titre_traduction.id_titre=articles.id_titre_ INNER JOIN commentaire_traduction ON commentaire_traduction.id_commentaire=articles.id_commentaire_ WHERE type_fiche=1 AND id_produits_=@id_art", Connection);
        command.Parameters.Add("@id_art", SqlDbType.Int, 10);
        command.Parameters["@id_art"].Value = Request.QueryString["produit_id"];

        //on créé le reader pour parcourir le résultat de la requête précédente
        SqlDataReader read = command.ExecuteReader();
        int y = 120;
        int y2 = 150;
        while (read.Read())
        {
            string titre = (string)read["titre_fr"];
            string comment = (string)read["commentaire_fr"];
            DateTime date_pub = (DateTime)read["date_publication"];


            string result1 = String.Format(titre);
            string result2 = String.Format("Mise en ligne le : "+date_pub);
            string result3 = String.Format(comment);
            gfx.DrawString(result1, fontTitre, XBrushes.DarkSlateGray, new XRect(20, y, page.Width, page.Height), XStringFormat.TopLeft);
            gfx.DrawString(result2, font, XBrushes.Black, new XRect(20, 140, page.Width, page.Height), XStringFormat.TopLeft);
           
            y += 40;
            y2 += 40;

            // You always need a MigraDoc document for rendering.
            Document doc = new Document();
            Section sec = doc.AddSection();
            // Add a single paragraph with some text and format information.
            Paragraph para = sec.AddParagraph();
            para.Format.Alignment = ParagraphAlignment.Left;
            para.Format.Font.Name = "Trebuchet MS";
            para.Format.Font.Size = 10;
            para.Format.Font.Color = MigraDoc.DocumentObjectModel.Colors.SlateGray;
            para.AddText(comment);
            para.Format.Borders.Distance = "2pt";
            para.Format.Borders.Color = Colors.DarkGray;
           
            // Create a renderer and prepare (=layout) the document
            MigraDoc.Rendering.DocumentRenderer docRenderer = new DocumentRenderer(doc);
            docRenderer.PrepareDocument();

            // Render the paragraph. You can render tables or shapes the same way.
            docRenderer.RenderObject(gfx, XUnit.FromCentimeter(1), XUnit.FromCentimeter(6), "19cm", para);

        }

        // Fermeture connection
        Connection.Close();

        // Draw the text
        gfx.DrawString("Généré le : " + time.ToString(), font, XBrushes.Black, new XRect(0, 0, page.Width, page.Height), XStringFormat.BottomCenter);
        //RenderClock(gfx);

        // Send PDF to browser
        MemoryStream stream = new MemoryStream();
        document.Save(stream, false);
        Response.Clear();
        Response.ContentType = "application/pdf";
        Response.AddHeader("content-length", stream.Length.ToString());
        Response.BinaryWrite(stream.ToArray());
        Response.Flush();
        stream.Close();
        Response.End();


    }

_________________
Excuse me for my english Wink
Back to top
View user's profile Send private message Send e-mail
Thomas Hoevel



Joined: 16 Oct 2006
Posts: 387
Location: Cologne, Germany

PostPosted: Wed Mar 25, 2009 10:13 am    Post subject: Reply with quote

MigraDoc adds pages automatically (if used correctly).

After calling "docRenderer.PrepareDocument()" MigraDoc should know how many pages are needed.

See also here:
http://pdfsharp.s3.bizhat.com/viewtopic.php?t=592
_________________
Regards
Thomas Hoevel
PDFsharp Team
Back to top
View user's profile Send private message Visit poster's website
nass



Joined: 24 Mar 2009
Posts: 3
Location: TROYES / FRANCE

PostPosted: Wed Mar 25, 2009 4:30 pm    Post subject: Reply with quote

Thank you for your reply,
I have tried to specify the number of pages as you advised me previously.
This time I have well 2 pages but in only one page.
I am so confusing, I don't arrive to find the right solution.Embarassed
Please help me again, I have the feeling that I am near.Confused

I give you my code
Code:
        PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(true);
        pdfRenderer.Document = doc;
        pdfRenderer.RenderDocument();
        pdfRenderer.PrepareRenderPages();
        pdfRenderer.RenderPages(1,2);
       
        // Create a renderer and prepare (=layout) the document
        DocumentRenderer docRenderer = new DocumentRenderer(doc);
        docRenderer.PrepareDocument();
        docRenderer.RenderPage(gfx, 1, PageRenderOptions.All);
        docRenderer.RenderPage(gfx, 2, PageRenderOptions.All);

        //docRenderer.RenderObject(gfx, XUnit.FromCentimeter(1), XUnit.FromCentimeter(6), "19cm",para);


        // Draw the text
        gfx.DrawString("Généré le : " + time.ToString(), font, XBrushes.Black, new XRect(0, 0, page.Width, page.Height), XStringFormat.BottomCenter);

        // Send PDF to browser
        MemoryStream stream = new MemoryStream();
        document.Save(stream, false);
        Response.Clear();
        Response.ContentType = "application/pdf";
        Response.AddHeader("content-length", stream.Length.ToString());
        Response.BinaryWrite(stream.ToArray());
        Response.Flush();
        stream.Close();
        Response.End();


Thank you in advance Wink
_________________
Excuse me for my english Wink
Back to top
View user's profile Send private message Send e-mail
Thomas Hoevel



Joined: 16 Oct 2006
Posts: 387
Location: Cologne, Germany

PostPosted: Wed Mar 25, 2009 4:59 pm    Post subject: Reply with quote

MigraDoc adds pages automatically (if used as intended).

See also here:
http://pdfsharp.s3.bizhat.com/viewtopic.php?t=592

You're code requires you to create the pages.
So before calling
Code:
docRenderer.RenderPage(gfx, 2, PageRenderOptions.All);

to render the second page, make sure you created a second page and set gfx to that page.

The way you use it, it gives you all opportunities to modify the created pages - this includes rendering two document pages on one PDF page.

Or look at the MigraDoc samples to let MigraDoc do the work.
_________________
Regards
Thomas Hoevel
PDFsharp Team
Back to top
View user's profile Send private message Visit poster's website
nass



Joined: 24 Mar 2009
Posts: 3
Location: TROYES / FRANCE

PostPosted: Thu Mar 26, 2009 9:04 am    Post subject: Reply with quote

Thank you very much Thomas Hoevel for your patience.
I arrive now to render my content in 2 pages by making it:
Code:
        // Create a renderer and prepare (=layout) the document
        DocumentRenderer docRenderer = new DocumentRenderer(doc);
        docRenderer.PrepareDocument();
        docRenderer.RenderPage(gfx, 1, PageRenderOptions.RenderContent);
        PdfPage page2 = document.AddPage();
        page2.Size = PdfSharp.PageSize.A4;
        gfx = XGraphics.FromPdfPage(page2);
        docRenderer.RenderPage(gfx, 2, PageRenderOptions.RenderContent);

The only problem is that my content takes place on my image in the top of my first page.

I would like to know if it's possible to do the same thing by making it:

Code:
        // Create a renderer and prepare (=layout) the document
        DocumentRenderer docRenderer = new DocumentRenderer(doc);
        docRenderer.PrepareDocument();
        docRenderer.RenderObject(gfx, XUnit.FromCentimeter(1), XUnit.FromCentimeter(6), "19cm",para);
        PdfPage page2 = document.AddPage();
        page2.Size = PdfSharp.PageSize.A4;
        gfx = XGraphics.FromPdfPage(page2);
        docRenderer.RenderObject(gfx, XUnit.FromCentimeter(1), XUnit.FromCentimeter(1), "19cm", para);


In fact, I would like to know if it's possible to specify the page number by calling
Code:
docRenderer.RenderObject()


In this way, I can re-size and give a position to my contents.

Thank you again Smile
_________________
Excuse me for my english Wink
Back to top
View user's profile Send private message Send e-mail
Thomas Hoevel



Joined: 16 Oct 2006
Posts: 387
Location: Cologne, Germany

PostPosted: Thu Mar 26, 2009 9:41 am    Post subject: Reply with quote

Hi!

You can set the Page Setup using Document.LastSection.PageSetup.

On the first page you can call "sec.AddParagraph();" to leave some extra space to "protect" the image.
You can set paragraph.Format.SpaceAfter to make a single paragraph as big as you need it.
_________________
Regards
Thomas Hoevel
PDFsharp Team
Back to top
View user's profile Send private message Visit poster's website
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