Sign In  Sign Up Live-Chat

Set PageHeight of a section dynamically

Last post 01-02-2008, 6:30 AM by ArthurDent. 16 replies.
Page 1 of 2 (17 items)   1 2 Next >
Sort Posts: Previous Next
  •  12-05-2007, 3:05 AM 105214

    Set PageHeight of a section dynamically

    Hello,

    I wonder if it's possible to set the pageheight of a section dynamically. The section has several paragraphs with text and graphical content wich varies at runtime.

    I need to generate a PDF which has exactly the pageheight required for my content.

    Is there any solution for this issue?

    Thanks in advance!

     
  •  12-05-2007, 7:50 AM 105257 in reply to 105214

    Re: Set PageHeight of a section dynamically

    Hi,

    It is possible to set the page height of a section of pdf dynamically. For detailed information and code examples please consult http://www.aspose.com/Wiki/default.aspx/Aspose.Pdf/SetPageSizeAndMargins.html

    Thanks.

     
  •  12-05-2007, 8:25 AM 105272 in reply to 105257

    Re: Set PageHeight of a section dynamically

    Thanks for your answer.

    my problem is that the number and size of paragraphs depends on my datasource.  I can't set my pageheight until I know the exact height of all paragraphs. How do I get the height of a paragraph?

     
  •  12-05-2007, 8:54 AM 105280 in reply to 105272

    Re: Set PageHeight of a section dynamically

    Hi,

    I am sorry but there is no way to calculate exactly what the height of the paragraph will be before the pdf is created because it depends on a lot of parameters. This is currently not supported in Aspose.Pdf.

    As a work arround what you can do is first create a temporary pdf with some default page height. Then use Apose.Pdf.Kit to count the number of pages in that pdf. If the number of pages is more than one then that means that the contents didn't fit on one page. Simply multiply the page height of the temporary pdf with the number of pages and you will get the height that you need to set inorder to make all the content fit on one page.

    Thanks.

     
  •  12-05-2007, 9:59 AM 105305 in reply to 105280

    Re: Set PageHeight of a section dynamically

    Does it make sense to have a look at the Table.GetHeight(Aspose.Pdf.Pdf doc) Method? If so, how can I handle it?

    It's really important for me to set the pageheight to exactly the same size as my content.

    Best regards

     
  •  12-05-2007, 11:00 AM 105331 in reply to 105305

    Re: Set PageHeight of a section dynamically

    Hi,

    I am sorry for the confusion. You can use GetTextHeight of Text class to get the height of paragraph. For more information please consult  http://www.aspose.com/Products/Aspose.Pdf/Api/Aspose.Pdf.Text.GetTextHeight.html . You can also use Table.GetHeight if the content you are adding is a table. You can add up all the individual heights of the paragraphs to get the desired page size.

    Thanks.

     
  •  12-07-2007, 3:00 AM 105572 in reply to 105331

    Re: Set PageHeight of a section dynamically

    Thanks for your reply.

    It works fine now, but the performance of the GetTextHeight() and GetHeight()-Method is very bad. A function call takes about 30 seconds for
    a small text part. I have to call that function 3 times, so it takes me 1.5 minutes to generate a single page pdf. Without using that function, it takes 0.5 sec.! Is there any possibility to improve the performance?

    What does the parameter of the function mean? I use the function that way:

    table.GetHeight(new Aspose.Pdf.Pdf());

    Is that correct?

    Thanks

     
  •  12-07-2007, 8:32 AM 105616 in reply to 105572

    Re: Set PageHeight of a section dynamically

    Hi,

    I have checked this and function returns in milliseconds. In the argument you shouldn't create a new Pdf object but should pass the same one that you are going to add the table to. If you still have trouble then send me your complete code.

    Thanks.

     
  •  12-10-2007, 2:12 AM 105719 in reply to 105616

    Re: Set PageHeight of a section dynamically

    Hi,

    I found the reason for the long calculating time: In my code I set the TextName to "MS PGothic". I need to use that font because sometimes I have to display chinese or japanese texts.

    This reproduces my problem:

    Aspose.Pdf.Pdf pdfDocument = new Aspose.Pdf.Pdf();
    Aspose.Pdf.TextInfo textInfo = new Aspose.Pdf.TextInfo();
    textInfo.FontSize = 4.8F;
    textInfo.IsUnicode = true;
    textInfo.FontName = "MS PGothic";
    Aspose.Pdf.Text text = new Aspose.Pdf.Text("This is a Test!", textInfo);
    // This takes ages!
    float height = text.GetTextHeight(pdfDocument, 100F);

    If I don't set the FontName to "MS PGothic", the GetTextHeight-function works very fast, otherwise it takes about 30 seconds. Is there anything I have to set before (maybe the FontEncoding-Value)?

    Thank you

     
  •  12-10-2007, 7:49 AM 105749 in reply to 105719

    Re: Set PageHeight of a section dynamically

    Hi,

    I have been able to reproduce this error. I have logged this as PDFNET-4163 in our issue tracking system. We will try our best to resolve this as soon as possible.

    Thanks.

     
  •  12-10-2007, 11:07 AM 105781 in reply to 105719

    Re: Set PageHeight of a section dynamically

    Hi,

    When text.TextInfo.IsUnicode is true and text.TextInfo.FontName is set(not null), it will access the %windir%\Fonts directory and write each font's info into a xml file. That's why it takes a long time(It takes about 5 seconds on my machine). However,I think it is necessary. As it increases performance greatly when you access these fonts subsequently.
    Here is an example to describe this:

    Aspose.Pdf.Pdf pdfDocument = new Aspose.Pdf.Pdf();
    Aspose.Pdf.TextInfo textInfo = new Aspose.Pdf.TextInfo();
    textInfo.FontSize = 4.8F;
    textInfo.IsUnicode = true;
    textInfo.FontName = "MS PGothic";
    Aspose.Pdf.Text text = new Aspose.Pdf.Text("This is a Test!", textInfo);
    float height = 0;

    //need more time to create a fontmap file

    height  = text.GetTextHeight(pdfDocument, 100F);   
    text.TextInfo.FontName = "Tahmoa";     
    //execute fast this time as the fontmap works           
    height = text.GetTextHeight(pdfDocument, 100F);  

    Please be feel free to ask further question.

    Best regards.

    Hans Zhang
    Product Developer
    Aspose Changsha Team
    About Us
    Contact Us
     
  •  12-11-2007, 5:41 AM 105854 in reply to 105781

    Re: Set PageHeight of a section dynamically

    Thanks for your reply,

    but the problem still remains when I call the function for the first time (on my machine it takes about 30 seconds).

    Could it be a solution to create the fontmap file in advance using the pdfDocument.IsTruetypeFontMapCached-attribute?
    I tried to do this but a fontmap.xml file won't be created. Here is my code:

    Aspose.Pdf.Pdf pdfDocument = new Aspose.Pdf.Pdf();
    pdfDocument.IsTruetypeFontMapCached = true;
    Aspose.Pdf.TextInfo textInfo = new Aspose.Pdf.TextInfo();
    textInfo.FontSize = 4.8F;
    textInfo.IsUnicode = true;
    textInfo.FontName = "MS PGothic";
    Aspose.Pdf.Text text = new Aspose.Pdf.Text("This is a Test!", textInfo);
    float height = 0;
    //need more time to create a fontmap file
    height  = text.GetTextHeight(pdfDocument, 100F);   

    The pdfDocument.TruetypeFontMapPath should be the path of the application by default, is that true?

    Thanks

     
  •  12-11-2007, 10:43 AM 105890 in reply to 105854

    Re: Set PageHeight of a section dynamically

    Hi,

    Whenever the font map is created it will take some time. So I don't understand the point of having this delay a couple of statements before.

    Thanks.

     
  •  12-12-2007, 1:00 AM 105942 in reply to 105890

    Re: Set PageHeight of a section dynamically

    Hi,

    Could it be a solution to create the fontmap file in advance, so that everytime the programm starts I load the existing fontmpap file?

    Thanks

     
  •  12-12-2007, 2:13 AM 105950 in reply to 105942

    Re: Set PageHeight of a section dynamically

    Hi,

    The fontmap file should work as you said. But I find it doesn't work properly. I will investigate on it and give you a solution sonn.

    Best regards.

    Hans Zhang
    Product Developer
    Aspose Changsha Team
    About Us
    Contact Us
     
Page 1 of 2 (17 items)   1 2 Next >
View as RSS news feed in XML