|
Rank: Member Groups: Member
Joined: 11/14/2016 Posts: 10
|
Hi,
I'm evaluating your software for a project of mine. Looks good. One Question is open.
How can I add a watermark with a PDF to an PDF?
I have: a) the document.pdf which I created from an URL. It contains 4 pages A4 port. b) watermark1.pdf which I created in Photoshop. It contains 1 page A4 port. b) watermark2.pdf which I created in Photoshop. It contains 1 page A4 port.
I want to load document.pdf and add watermark1.pdf as background to page 1 and add watermark2.pdf as background to pages 2-4.
1) I did not found how to add a background or watermark in the documentation. How do I add an PDF as background in an existing PDF?
2) Do I have to split, add background and merge? Or can I do it in one step?
Thanks
Stefan
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
Hi, You can't add watermark.pdf. However you can add watermark.png. So when you create your watermark in Photoshop, you would want to save it as a real image format with alpha channel first. Once you have the image, you can either the the ACM interface or low level content API to overlay the image onto your PDF file. You can find more information on ACM interface here: https://www.essentialobjects.com/doc/pdf/acm/getting%20started/hello_world.aspxBased on the above code you will need to make the following changes: 1. You should use this AcmRender constructor that takes a PdfPage object instead of a PdfDocument object: https://www.essentialobjects.com/doc/eo.pdf.acm.acmrenderconstructor2.aspxThe code will be something like this:
Code: C#
//Convert your Url to PDF
PdfDocument doc = new PdfDocument();
HtmlToPdf.ConvertUrl(url, doc);
//Create an AcmRender for the first page. Note the
//first argument is doc.Pages[0], this is a PdfPage
//object, not a PdfDocument object
AcmRender render = new AcmRender(doc.Pages[0], 0);
2. You will need to use AcmImage object instead of AcmText object. If you wish to create a watermark on every page, you can write a look to create AcmRender an an AcmImage for each page. Do not use the same AcmImage object in different renderings. It can only be rendered once. Hope this helps. Please feel free to let us know if you have any questions. Thanks!
|
|
Rank: Member Groups: Member
Joined: 11/14/2016 Posts: 10
|
Hello,
thanks.
Can't I create an empty document, add watermark.pdf as the first page and put document.pdf on top of it?
My Software generates the watermarks as PDF. So I can't use PNG.
Stefan
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
Hi, In theory you can do that but in practice it may not work reliably. In order to use watermark, you need something that's transparent without a solid background. Most PDF file has a white solid background. So if you stack them together, the top layer will just completely obscure the bottom layer. Having that said, our HTML to PDF does try to create PDF with transparent background whenever possible. So you can try to call HTML to PDF on your watermark.pdf and it may work for you:
Code: C#
//Load your existing background PDF file
PdfDocument doc = new PdfDocument("watermark.pdf");
//This is important, otherwise the HTML to PDF converter will create new
//pages instead of output to existing pages
HtmlToPdf.Options.StartPageIndex = 0;
//Run HTML to PDF converter and output over to your
//existing PDF file
HtmlToPdf.ConvertUrl(url, doc);
You may need to duplicate your watermark.pdf to create multiple page PDF first. You can do this with PdfDocument.Merge. For example, the following code create a two page watermark.pdf:
Code: C#
//Use PdfDocument.Merge to create a two page watermark
//PDF file, assuming the original file is just one page
PdfDocument doc1 = new PdfDocument("watermark.pdf");
PdfDocument doc2 = new PdfDocument("watermark.pdf");
PdfDocument doc3 = PdfDocument.Merge(doc1, doc2);
If you do not know how many pages you need, you can do a trial HTML to PDF run to find out:
Code: C#
//Get the total number of output pages
PdfDocument doc = new PdfDocument();
HtmlToPdf.ConvertUrl(url, doc);
int totalPages = doc.Pages.Count;
Hope this helps. Let us know if this works for you. Thanks!
|
|
Rank: Member Groups: Member
Joined: 11/14/2016 Posts: 10
|
Hello,
maybe you consider adding a function to combine 2 loaded pdfs on one page in a new document. Currently I'm using pdftk for this but would like to remove the extra step.
The Backgound is a high resolution certificatebackground and the front is a simple webpage with no background and images with transparency.
With pdftk to add the background it works fine.
Stefan
|
|
Rank: Member Groups: Member
Joined: 11/14/2016 Posts: 10
|
Or to create layers? Load a pdf (to layer 0), add a layer and add a pdf (to layer 1) Stefan
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
Thanks for the suggestion. We will look into that in future release. Have you tried the method we described in our previous reply?
|
|
Rank: Member Groups: Member
Joined: 11/14/2016 Posts: 10
|
Hello,
yes, but when I use ConvertUrl with the url and the backgroundpdf it sizes the pdf from the url wron. If I use only ConvertUrl, save it and use pdftk it works perfect.
Because of the sequence I can't do this even. I need to combine the front- and backendpdf seperated from the convertion.
I'll check some things out and then buy a licence. We used phantomjs up to now but gone crazy with all kind of settings and formats.
Stefan
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
Ah. I am not sure what you meant by "it sizes the PDF from the Url wrong". If you can isolate the problem into a test project and send the test project to us, we will be happy to take a look. See here for more details: https://www.essentialobjects.com/forum/test_project.aspxIn any case, please feel free to let us know if you have any other questions.
|
|
Rank: Member Groups: Member
Joined: 11/14/2016 Posts: 10
|
>Because of the sequence of my project I can't do this even. >I need to combine the front- and backendpdf seperated from the convertion. Thanks for the offer
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
All right. Let us know if you need anything else.
|
|