We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How to overlay documents

Hi!

I try to overlay documents (http://www.syncfusion.com/products/reporting-edition/pdf/overlay-documents); however, I got an exception.

Would you give me the syntax on how to overlay Documents?

Thanks!


~~~~~~~~~~~~~~


string path1 = @"C:\path1.pdf";
string path2 = @"C:\path2.pdf";
string saveToPath = @"C:\out.pdf";

PdfLoadedDocument loadDocument1 = new PdfLoadedDocument(path1);

PdfLoadedDocument loadDocument2 = new PdfLoadedDocument(path2);

PdfDocument doc = new PdfDocument();
PdfPage page = doc.Pages.Add();
//doc.PageSettings.Size = PdfPageSize.A1;
doc.ImportPage(loadDocument1, (PdfPageBase)page);

doc.ImportPage(loadDocument2, page);

doc.Save(saveToPath);
doc.Close(true);
System.Diagnostics.Process.Start(saveToPath);

~~~~~~~~~~~~~~~


System.Windows.Markup.XamlParseException was unhandled
Message="Cannot create instance of 'Window1' defined in assembly 'SyncfusionPDFPrac, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Exception has been thrown by the target of an invocation. Error in markup file 'Window1.xaml' Line 1 Position 9."
Source="PresentationFramework"
LineNumber=1
LinePosition=9
.........
at SyncfusionPDFPrac.Window1..ctor() in C:\Documents and Settingsvan\My Documents\Visual Studio 2008\Projects\SyncfusionPDFPrac\SyncfusionPDFPrac\Window1.xaml.cs:line 50
InnerException:



4 Replies

AG Angappan G Syncfusion Team September 15, 2010 09:53 AM UTC

Hi Kim,

Thank you for using Essential PDF.

We have analyzed your code snippet and found that you were using the page object of the PdfDocument object in which the pages of the PdfLoadedDocument pages where imported. The importPage method will only accept the page objects of the PdfLoadedDocument. Please refer to the sample for more details.

Please try this and let us know if you have any queries.

Regards,
Angappan.





F96425_6fb36de2.zip


KI kim September 15, 2010 07:37 PM UTC

Thanks for the answer; however, the code is just importing pages (not overlaying documents). (Please check attachment for the overlay document screen shot)( http://www.syncfusion.com/products/reporting-edition/pdf/overlay-documents )


Would you provide some sample code on how to do it?

Thanks!



OverlayDocuments_1284ef66.zip


KI kim September 15, 2010 08:10 PM UTC

Hi!

I got it work now, so thanks again.

Just save time for someone, who are looking for solution like me, the code below is working:


string pdfPath1 = @"C:\file1.pdf";
string pdfPath2 = @"C:\file2.pdf";
string outPdfPath = @"C:\outPdf.pdf";


private void OverlayDocument()
{

PdfLoadedDocument ldDoc1 = new PdfLoadedDocument(this.pdfPath1);
PdfLoadedDocument ldDoc2 = new PdfLoadedDocument(this.pdfPath2);
PdfDocument doc = new PdfDocument();

for (int i = 0, count = ldDoc2.Pages.Count; i < count; ++i)
{
PdfPage page = doc.Pages.Add();
PdfGraphics g = page.Graphics;

PdfPageBase lpage = ldDoc2.Pages[i];
PdfTemplate template = lpage.CreateTemplate();

g.DrawPdfTemplate(template, PointF.Empty, page.GetClientSize());

lpage = ldDoc1.Pages[0];
template = lpage.CreateTemplate();

g.DrawPdfTemplate(template, PointF.Empty, page.GetClientSize());
}

doc.Save(this.outPdfPath);
System.Diagnostics.Process.Start(this.outPdfPath);
}

Found sample code from:

http://samples.syncfusion.com/ASPNET/7.3.0.20/web/Pdf.Web/samples/3.5/Modify%20Documents/Overlay%20Documents/CS/default.aspx




AG Angappan G Syncfusion Team September 16, 2010 03:45 AM UTC

Hi Kim,

Thanks for the update.

Please let us know if you have any queries.

Regards,
Angappan.


Loader.
Live Chat Icon For mobile
Up arrow icon