C1.C1Pdf vs C1.Pdf

Posted by: ivan.stanojkovski on 1 May 2025, 2:16 pm EST

    • Post Options:
    • Link

    Posted 1 May 2025, 2:16 pm EST

    Hi

    We are currently using your namespace C1.C1Pdf.

    For each C1Page from the C1PrintDocument, we create an Image, add that Image as a PDF page in the C1PdfDocument, and include a PdfSignature with the logo and certificate.

    When migrating to the new namespace C1.Pdf, we can no longer add System.Drawing.Image, but instead, we must use GrapeCity.Documents.Drawing.Image.

    Do you perhaps have a better approach on how to create a PDF document from C1PrintDocument with an X509Certificate2?

    Attached is the source of our current procedure.

    Looking forward to your response.

    public bool SignPDF(string fileNameWithPath,
    					X509Certificate2 cetificate,
    					RectangleF location,
    					Image signatureLogo)
    {
    	C1PdfDocument c1PdfDocument1 = new();
    	foreach (C1Page page in _doc.Pages)
    	{
    		Image img = page.AsMetafile();
    
    		c1PdfDocument1.DrawImage(img, c1PdfDocument1.PageRectangle);
    
    		PdfSignature signature = new()
    		{
    			Reason = "Signature",
    			Certificate = cetificate,
    			Visibility = FieldVisibility.Visible,
    			Handler = SignatureHandler.PPKLite
    		};
    
    		signature.BorderWidth = FieldBorderWidth.Thin;
    		signature.BorderColor = Color.Gray;
    		signature.BackColor = Color.DarkGray;
    		signature.Image = signatureLogo;
    
    		c1PdfDocument1.AddField(signature, location);
    	}
    	c1PdfDocument1.Save(fileNameWithPath);
    
    	return true;
    }
  • Posted 2 May 2025, 4:26 am EST

    Hi Ivan,

    Since the new C1.Pdf library is based on .NET Standard, it does not support Windows Metafile images. Therefore, it is not possible to create a GrapeCity.Documents.Drawing.Image object using the Metafile returned from the C1Page.AsMetafile() method.

    To meet your current requirement without major code changes, we recommend using the C1.Win.Pdf package. It is specifically designed for WinForms and WPF, and it supports the older object model - i.e. it accepts System.Drawing.Image objects.

    Please refer to the attached sample project, which uses the C1.Win.Pdf package to run the code you shared (with some minor changes) - PrintDocToPdf.zip

    Best Regards,

    Kartik

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels