Welcome Guest Search | Active Topics | Sign In | Register

CovertURL with existing pdf as base Options
soppie
Posted: Monday, February 11, 2013 6:50:43 AM
Rank: Newbie
Groups: Member

Joined: 6/9/2011
Posts: 9
Hi,

I've worked for quite a time now with EO pdf to generate pdf in my web applications. Normally, when I want to use an existing pdf (with company header and footer info already in it), I calculate the height of content when adding (eg from a database) and add a new page (= the existing pdf model file) if the height exceeds the height still left on my current page. This works fine.

the question: Is this also possible with ConvertURL?

So I want to use a existing url, but write my content on an existing pdf. When a new page is needed if the content exceeds my pageheight, I want to start again with the existing pdf.


eo_support
Posted: Monday, February 11, 2013 8:46:35 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,195
Hi,

I believe so. They work almost exactly the same way.

Thanks!
soppie
Posted: Tuesday, February 12, 2013 9:13:53 AM
Rank: Newbie
Groups: Member

Joined: 6/9/2011
Posts: 9
Hi,

that's the point were I am now. They work almost exactly the same. Almost...
The big difference is that a url used as source for converting, is treated as one chunk, so how to determine if the space on (for instance) on the first page is used?

When I use a certain font which I load in the PDF generating process, I can calculated the vertical space used by the text I'm gonna place in a page. So can you tell me how to do this when I get a complete block of text and images: that's what a url is usually contains.

Thx!
eo_support
Posted: Tuesday, February 12, 2013 9:36:43 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,195
Hi,

I am not exactly sure what you meant by "space". No matter you use ConvertHtml or ConvertUl, you do NOT need to calculate spacing and paging by yourself. The converter can do that for you. For example, if you use the following code:

//Create a PdfDocument object
PdfDocument doc = new PdfDocument();

Code: C#
//Perform the first conversion
HtmlToPdfResult result1 = HtmlToPdf.ConvertUrl(url1, doc);

//Tell the second conversion to follow the first conversion
HtmlToPdf.Options.Follow(result1);

//Perform the second conversion
HtmlToPdf.ConvertUrl(url2, doc);


You can use the same code with ConvertHtml, or even mix ConvertHtml/ConvertUrl together. With this code, the output for the second conversion will automatically starts from where the first conversion ends. Alternatively, you can adjust HtmlToPdf.Options.StartPosition based on HtmlToPdfResult.LastPosition (this is basically what Options.Follow does) yourself. For example, you can set StartPosition = LastPosition + 1 to insert a once inch gap between the second conversion and the previous conversion.

Paging are also automatically handled when you use Follow. If you want to add gap yourself, you may need to insert a page manually.

Hope this helps. Please feel free to let us know if you still have more questions.

Thanks!
soppie
Posted: Tuesday, February 12, 2013 9:42:56 AM
Rank: Newbie
Groups: Member

Joined: 6/9/2011
Posts: 9
Thx for the quick respons!
I think I was not clear enough: I use one URL, not multiple url's

Say: my Url uses 6 Letter pages in total. How can I make sure every NEWpage needed starts "writing" on my empty model pdf (with company info, logo etc) already in it? That was my initial question.
eo_support
Posted: Tuesday, February 12, 2013 9:55:24 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,195
Hi,

You will need to do something like this:

1. Measure how many pages you have. If you already know it (for example, 6), then you can skip this step. If you do not know how many pages, then you can perform the conversion once:

Code: C#
PdfDocument doc = new PdfDocument();
HtmlToPdfResult result = HtmlToPdf.ConvertUrl(url, doc);
int pageCount = result.LastPageIndex + 1;


Note the purpose of this conversion is purely to measure how many pages you will need. The result of this conversion is discarded.

2. Use PdfDocument.Merge to create a model pdf with enough pages. For example, you can use the following code to create a model pdf with two pages:

Code: C#
PdfDocument doc1 = new PdfDocument("model.pdf");
PdfDocument doc2 = new PdfDocument("model.pdf");

//result will be a two page model file
PdfDocument result = PdfDocument.Merge(doc1, doc2);


If you have more pages, you will want to write a loop for this step.

3. Pass the model file to the converter:

Code: C#
//Render HTML into the multi-page model file produced in step 2.
HtmlToPdf.ConvertUrl(url, result);


Note you can not do watermark with this method. So if your company logo is in the header area that does not overlap with your main HTML output area, then it's OK. However if your company logo is in the middle of the page then it will be completely covered by the HTML output and will not be visible.

Let us know if this works for you.

Thanks!
soppie
Posted: Tuesday, February 12, 2013 10:00:02 AM
Rank: Newbie
Groups: Member

Joined: 6/9/2011
Posts: 9
that's what I wanted to know!
I saw some posts about measuring etc, but I thought there were more options to achieve what I wanted.

Great support!
Thx
eo_support
Posted: Tuesday, February 12, 2013 10:06:37 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,195
Great! Glad that we finally found out a good way for you. Please feel free to let us know if there is anything else.
soppie
Posted: Wednesday, February 13, 2013 4:26:41 AM
Rank: Newbie
Groups: Member

Joined: 6/9/2011
Posts: 9
Somehow I can't get the PdfDocument.Merge to work with an array of PdfDocuments

If I merge 2 pdf files there's no problem, with an array my final pdf holds 0 pages.
Must be doing something wrong, but can't figure it out. Can you give me a example of using a loop, knowing my endresult needs (for example) 8 pages?

Thx!
soppie
Posted: Wednesday, February 13, 2013 6:07:50 AM
Rank: Newbie
Groups: Member

Joined: 6/9/2011
Posts: 9
Just found this thread http://www.essentialobjects.com/forum/postst5943_Merge-multiple-documents.aspx which gave me the impression I did it the same way, but still no luck: my final pdf holds 0 pages. My measurement of pages works oke based on testing with variable url's. When I write out my array with pdfdocuments as strings, I get the right number of items.
But my last lines:

BaseDocFull = PdfDocument.Merge(myPDFDocs)
HtmlToPdf.ConvertUrl(aUrlToUse, BaseDocFull)

still result in zero pages.

Can it be a bug in my EO.pdf.dll build (never had a problem, but never used the merge function)? : version 3.0.120.2
I need to program my project in vb.net, so maybe my conversion form c# to vb.net is rusty but as far as I can see everything is working in my code, except the Merge (with array) call.

Thx!
eo_support
Posted: Wednesday, February 13, 2013 10:01:23 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,195
Hi,

Your code looks fine. Please try the latest version first and see if it works for you. We have fixed some issues with the Merge function during the past. If the latest version still does not work for you, please try to isolate the problem into a small test project and send us the test project. We will then debug that here.

Thanks!
soppie
Posted: Wednesday, February 13, 2013 10:29:15 AM
Rank: Newbie
Groups: Member

Joined: 6/9/2011
Posts: 9
Didn't think of that. Now I get pages in my final pdf but... too many.

In my test it was calculated I needed 3 pages for a certain url (I know this is oke, because before I started to add the merge code, this url resulted in 3 pages (based on my marging settings and pagesize).
The final result pdf shows 3 empty pages with company info in it (my merged model pdfdocument = 3 times my model pdf = oke) and after that 3 pages with the url content and not placed on my merged pdfdocument

eo_support
Posted: Wednesday, February 13, 2013 7:10:53 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,195
Hi,

Please add the following code before calling ConvertUrl:

Code: C#
HtmlToPdf.Options.StartPageIndex = 0;


This line is important, otherwise the conversion will just keep adding pages instead of using existing pages.

Thanks!
soppie
Posted: Thursday, February 14, 2013 2:59:13 AM
Rank: Newbie
Groups: Member

Joined: 6/9/2011
Posts: 9
That solved it.
Reverted back to my licensed 2011 dll version and that one is now also working oke.

Again: great support!
eo_support
Posted: Thursday, February 14, 2013 8:19:13 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,195
Great. Glad that everything is working for you!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.