Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Fri Nov 20, 2020 1:57 pm

Hi,
I would like to generate PDF reports from C#, and now I am testing PDF libraries and Spire PDF is one of them. There re some basic features, what I need, but I have not found in the documentation, so I would like to take some questions:
-which image types support Spire.PDF? For me are PNG, EMF and SVG important. Png works, EMF appears strange, and by Svg I get a NullReferenceException from PdfImage.FromFile.
-does Spire.PDF support font fallback?
-can I insert with Spire.PDF small PDFs into my new document? Insert, e.g. in a cell of a table, and not merge!

csillikd
 
Posts: 3
Joined: Fri Nov 20, 2020 1:34 pm

Mon Nov 23, 2020 9:40 am

Hello,

Thanks for your inquiry!

1) Our Spire.Pdf supports PNG, EMF and SVG image types. I did not reproduce your issue when testing EMF and SVG types with Spire.Pdf v6.11.6, and here is my testing code. To help us reproduce your issue, please provide us with your EMF and SVG files. Thanks in advance.
Code: Select all
            PdfDocument pdf = new PdfDocument();
            PdfPageBase page = pdf.Pages.Add();
            float x = 0f;
            float y = 50f;

            //Select image type here(png,emf,svg)
            PdfImage img = PdfImage.FromFile(@"E:\testdoc\picSvg1.svg");
            page.Canvas.DrawImage(img, x, y);

            //save
            pdf.SaveToFile("imgSvg.pdf");



2) Our Spire.Pdf supports font fallback. When the font data is not embedded in pdf document, our program will read font data from computer according to the font name used in Pdf file. If the font is not installed on computer, we will use similar font installed on computer instead.

3) Our Spire.Pdf supports drawing the smaller Pdfs content on other Pdf at the specified location by page.Canvas.DrawTemplate() method. Please refer to the following code.
Code: Select all
            PdfDocument target = new PdfDocument();
            target.LoadFromFile(@"E:\testdoc\target.pdf");
            PdfDocument insert = new PdfDocument();
            insert.LoadFromFile(@"E:\testdoc\insert.pdf");

            PdfPageBase page = insert.Pages[0];
            PdfPageBase newpage = target.Pages[0];
            PdfTextFindCollection collection = newpage.FindText("aa", TextFindParameter.IgnoreCase);

            //drawing by coordinates
            newpage.Canvas.DrawTemplate(page.CreateTemplate(), collection.Finds[0].Position);

            target.SaveToFile("InsertSmallPdf.pdf");
            System.Diagnostics.Process.Start("InsertSmallPdf.pdf");

If the above code does not meet your needs, please provide us with your Pdfs and describe which pdf you need to insert into another pdf and which cell of another pdf is your target cell. Thanks in advance.

If you have any other problems, please feel free to contact us!

Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Thu Nov 26, 2020 12:54 pm

Hi Marci,
thank you for your answer!
I have tested with the attached images, the EMF appears strange, and with the SVG I get a NullReferenceException. Could you check it?
And int the fontfallback.zip you can find a sample text, with that the font fallback does not work, where some glyphs are missing. Could you check it too?

csillikd
 
Posts: 3
Joined: Fri Nov 20, 2020 1:34 pm

Fri Nov 27, 2020 9:49 am

Hello,

Thanks for your reply!

I used previous code to tested your EMF image and could generated PDF file, but the content of PDF looks a little dark, attached my output pdf(image-Emf.pdf), you mentioned that the EMF appears strange, do you refer to this issue?
Code: Select all
            PdfDocument pdf = new PdfDocument();
            PdfPageBase page = pdf.Pages.Add();
            float x = 0;
            float y = 50;
            PdfImage img = PdfImage.FromFile(@"C:/Test.Emf");
            page.Canvas.DrawImage(img, x, y);

            pdf.SaveToFile("C:/image-Emf.pdf");


For SVG,I am sorry for previous incorrect code. Please refer to the following solutions.

Converting SVG to PDF:
Code: Select all
 
            PdfDocument pdf = new PdfDocument();
            pdf.LoadFromSvg("C:/Test.Svg");
            pdf.SaveToFile("C:/image-SVG1.pdf", FileFormat.PDF);

Drawing SVG to an existing PDF:
Code: Select all
 
            string inputFile_svg = "C:/Test.Svg";
            string inputFile_pdf = "C:/sample.pdf";
            string outputFile = "C:/image-SVG2.pdf";

            PdfDocument doc1 = new PdfDocument();
            doc1.LoadFromSvg(inputFile_svg);
            PdfDocument doc2 = new PdfDocument();
            doc2.LoadFromFile(inputFile_pdf);
            PdfTemplate template = doc1.Pages[0].CreateTemplate();
            template.Draw(doc2.Pages[0].Canvas, new PointF(0, 100));
            doc2.SaveToFile(outputFile, FileFormat.PDF);


About font fallback, when drawing text to PDF, you must use fonts that support characters in your text. The text you provide contains characters in multiple languages, so you need to draw it with multiple fonts. "Arial Unicode MS" font supports many more languages. Perhaps you can try using this font for rendering, as shown in the code below.

Code: Select all
            PdfDocument doc = new PdfDocument();
            //Create one page
            PdfPageBase page = doc.Pages.Add();
            PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial Unicode MS", 10),true);

            //Draw the text
            page.Canvas.DrawString(text, font, PdfBrushes.Black, 10, 10);

            String result = "C:/output.pdf";
            doc.SaveToFile(result, FileFormat.PDF);


Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Wed Dec 09, 2020 10:11 am

Hello,

Hope you are doing well.

Has your issue been solved now? Could you please give us some feedback at your convenience?

Thanks in advance.

Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Return to Spire.PDF

cron