Is it possible to overlay HTML onto an existing PDF document with Essential PDF?

I would like to be able to use an existing PDF document as backdrop for new HTML that I want to layer over the top of it (a bit like using printed stationery). I guess I can do that by converting the existing PDF page into an image, and then adding the image as the backdrop of my HTML - but is there a way of doing it by adding the HTML output as another layer onto the existing document? Doing it with the image may impact file size, searchability etc.



7 Replies 1 reply marked as answer

PV Prakash Viswanathan Syncfusion Team August 4, 2020 12:38 PM UTC

Hi Charles,   
   
Thank you for contacting Syncfusion support.    
   
Yes, we can overlay the HTML to existing PDF document using HTML to PDF conversion. You can convert the HTML to PDF and then you can add the converted PDF document to the existing PDF document by using a PDF Page template of the converted PDF document. Then you can draw the PDF page template to an existing PDF document. Please refer below links for more information about HTML to PDF conversion,   
   
   
Kindly let us know your exact requirement about overlaying converted PDF documents to an existing PDF document. So, we can create a sample to achieve your requirement.    
 
Regards, 
Prakash V 


Marked as answer

PN Preethi Nesakkan Gnanadurai Syncfusion Team August 5, 2020 03:45 AM UTC

From: Charles Southey <Sent: Tuesday, August 4, 2020 8:55 AM
To: Syncfusion Support <[email protected]>
Subject: RE: Syncfusion support community forum 156606, Is it possible to overlay HTML onto an existing PDF document with Essential PDF?, has been updated. 

 
Hi Prakash, 
 
Oh I see – convert to PDF first then overlay onto another PDF. Makes sense – I will follow that approach: no need for a sample at this stage. 
 
Many thanks for the response! 
 
Charles 
 



CH Charles August 11, 2020 07:38 PM UTC

Hi - I have tried the solution you gave, and technically it's working..but both layers are the full page size: what I need is for the background layer to show through the whitespace on the top layer - is that possible? I'm using ASP.NET Core 3.1.



GK Gowthamraj Kumar Syncfusion Team August 12, 2020 01:17 PM UTC

Hi Charles, 
 
Thank you for your update. 
 
Yes. It is possible to show the background layer in the top layer of another PDF document using our library. To achieve this we need to draw the template with a specified size (like width=100 and height=100) based on your requirement. Please try the below code snippet in your end and let us know the result.   
   
Please find the below code snippet to draw the template with different bounds.    
 
//Load the existing documents 
 
PdfLoadedDocument loadedDocument1 = new PdfLoadedDocument(@"input.pdf"); 
 
PdfLoadedDocument loadedDocument2 = new PdfLoadedDocument(@"input1.pdf"); 
 
//Create the new document 
 
PdfDocument document = new PdfDocument(); 
 
PdfPage page = document.Pages.Add(); 
 
//Create a template from the first document 
 
PdfPageBase loadedPage = loadedDocument1.Pages[0]; 
 
PdfTemplate template = loadedPage.CreateTemplate(); 
 
//Draw the loaded template into new document. 
 
page.Graphics.DrawPdfTemplate(template, new PointF(0, 0), new SizeF(100, 100)); 
 
// Create a template from the second document 
 
loadedPage = loadedDocument2.Pages[0]; 
 
template = loadedPage.CreateTemplate(); 
 
//Draw the loaded template into new document. 
 
page.Graphics.DrawPdfTemplate(template, new PointF(10, 10), new SizeF(500, 600)); 
 
//Save the new document. 
 
document.Save(@"../../output.pdf"); 
 
//Close the documents 
 
loadedDocument1.Close(true); 
 
loadedDocument2.Close(true); 
 
document.Close(true); 
 
If still you are facing an issue, kindly provide more details such as complete code snippet, input documents, expected output document , product version to check the issue in our end. So, that it will be helpful for us to analyze and assist you further on this. 
 
Regards, 
Gowthamraj K 



CH Charles August 12, 2020 02:14 PM UTC

Hi Prakash,

The problem is both layers need to be the full size of the page - what I'm after is transparency - is it possible to have a transparent page background that allows lower layers to show through?

Thanks,

Charles


CH Charles August 12, 2020 03:38 PM UTC

Hi - you can ignore my previous message: I have worked out how to do it:

            var page = baseDocument.Pages.Add();
            page.Graphics.DrawPdfTemplate(backdrop, new PointF(0, 0), new SizeF(width, height));
            page.Graphics.SetTransparency(1.0f, 1.0f, PdfBlendMode.Multiply);
            page.Graphics.DrawPdfTemplate(overLay, new PointF(0, 0), new SizeF(width, height));


The PdfBlendMode.Multiply gives me exactly the result I need.

Thanks for your help,

Charles


GK Gowthamraj Kumar Syncfusion Team August 13, 2020 05:47 AM UTC

Hi Charles, 

Thank you for your update. We glad to know that the reported issue is resolved.  

Regards, 
Gowthamraj K 


Loader.
Up arrow icon