Change the font of PDF files using private font

Source: Internet
Author: User

UsePrivate FontChangePDFthe font of the file

To do the project the other day, you need to use the fonts that are not installed to change the PDF file. I've never done anything like this before, and fortunately I've found a similar tutorial on the Web and successfully implemented this feature.

Now let's share with you how I have achieved this.

1. first I downloaded a system font library does not have fonts, independent Deedeeflowers.ttf font files, open preview such as:

2. What we do next is to enter some content in a new PDF file and replace the font with Deedeeflowers.ttf.

I downloaded this on their website. Components The latest hotfix, unzip and add the. dll file to my project. After installing this component, a folder called Bin is generated on the installed path, which contains this component, which has NET 2.0,. NET 3.5,. NET 4.0 corresponding. dll files, because the target of the project I created The framework is. NET 4.0, so I quoted it. All the. dll files contained in the NET4.0 folder.

has now put its . DLL files successfully added to the project:

3. on The use of namespaces, add


4. First create a new file called doc annoying PDF in the Main function and give Doc to add a page to pages .

Pdfdocument doc =NewPdfdocument ();
Pdfpagebase page = doc. Pages.Add ();

5. Import the font file we just downloaded deedeeflowers.ttf, here is a name for Truetypefont

One of the Pdftruetypefond parameters and set the font size to 20f.

String Fontfilename ="Deedeeflowers.ttf";
Pdftruetypefont Truetypefont =NewPdftruetypefont (Fontfilename, 20f);

6.Here's what we've just created.pagepage to add some text, and then set their properties, the method used here ispage. Canvas.drawstring (). Note Here is the use of the font we just imported, and set the color for the beautiful lavender,New Pdfsolidbrush(Color. Orchid), starting coordinatesXYare theTen. The most favorite article in the WorldYoutha paragraph.

Page. Canvas.drawstring ("years may wrinkle the skin,\n"
+"give up enthusiasm wrinkles the soul.\n"
+"worry, fear, self-distrust bows the heart\n"
+"and turns the spirit back to dust.", Truetypefont,NewPdfsolidbrush (Color.Black),Ten,Ten);

7. then save it as a Pdf file and preview it again.

here is the display of the use Deedeeflowers.ttf of the.

The font is very beautiful, but the PDF is not how to line it?

Below we will then set their opacity, to highlight the effect of youthful vitality.

The 6th step is followed by the following code, where you first add a picture of the original transparency, and then the XY direction offset by 10, plus 50% transparency of the second one. The image is set to the 75% size of the original JPG.

//Draw the image with transparency
Pdfimage image = Pdfimage.fromfile (@"youth.jpg");
floatwidth = image. Width *0.75f;
floatHeight = image. Height *0.75f;
floatx = (page. Canvas.clientsize.width-width)/2;
floatAlpha =1.0f;
Page. Canvas.settransparency (alpha, Alpha);
Page. Canvas.drawimage (image, X, -, width, height);

//Draw Another with half transparency and X y ten shift
Pdfimage Image2 = Pdfimage.fromfile (@"youth.jpg");
floatWidth2 = image. Width *0.75f;
floatHeight2 = image. Height *0.75f;
floatx2 = (page. Canvas.clientsize.width-width)/2;
floatALPHA2 =1.0f/2;
Page. Canvas.settransparency (ALPHA2, ALPHA2);
Page. Canvas.drawimage (Image, x+Ten, the, width, height);

Last step, save and preview.

Doc. SaveToFile ("Result.pdf");
System.Diagnostics.Process.Start ("Result.pdf");

Change the font of PDF files using private font

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.