PDFLib Chinese display and watermark removal

Recently, I started to contact PDFLib and record the learning process. Using PDFLib, the most difficult problem for beginners is to remove the watermark and display Chinese characters.

1. Remove watermark

      The easiest and most direct way to download the cracked version of PDFLib, download PDFLib-9.1.2-win32

2. Display Chinese characters

    PDFlib-CMap To create Chinese, Japanese or Korean (CJK) text output with PDFlib and use one of the predefined CMaps. Download PDFlib-CMap-3.0 , and extract to any path, but the CMap file path must be configured when using,

eg:    p.set_option("SearchPath=/path/to/resource/cmap"); or   PDF_set_option(p,"SearchPath=/path/to/resource/cmap")

 Use the most commonly used Song type STSong-Light (Chinese font that comes with PDFLib) , the decoding method is GB-EUC-H (in cmap)

Code:

#include <stdio.h>
#include<iostream>
#include "pdflib.h"

int main(int argc, char *argv[])

{

	PDF * pdf = PDF_new ();
	// open the document
	if (PDF_begin_document(pdf, "d://hello.pdf", 0, "") == -1)
	{
		printf("Error: %sn", PDF_get_errmsg(pdf));
		return(0);
	}
	PDF_TRY (pdf)
	{
		PDF_set_option(pdf, "SearchPath=./PDFlib-CMap-3.0/resource/cmap");//配置cmap
		PDF_set_info(pdf, "Creator", "PDF Creator");
		PDF_set_info(pdf, "Title", "Convert to PDF");
		PDF_begin_page_ext(pdf, a4_width, a4_height, "");// start A4 page
		int nHeight = a4_height;//Current height
		int font_song = PDF_load_font(pdf, "STSong-Light", 0, "GB-EUC-H", "");
		PDF_setfont(pdf, font_song, 34);// Set the font to 34 Song type
		// set start point
		nHeight -= 50;
		PDF_set_text_pos(pdf, 50, nHeight);
		// set the color to blue
		PDF_setcolor(pdf, "fill", "rgb", 0, 0, 1, 0);
		static const char *DFTitle[] = { "Hello!", "China." };
		for (int i = 0; i < 2; i++)
		{
			PDF_set_text_pos(pdf, 100* i, nHeight-40*i);//Font coordinates
			PDF_show(pdf, DFTitle[i]);
		}
		 
	}
	PDF_CATCH(pdf)
	{
		printf("PDFlib exception occurred in sample:/n");

		printf("[%d] %s: %s/n",

			PDF_get_errnum(pdf), PDF_get_apiname(pdf), PDF_get_errmsg(pdf));

	}
	PDF_end_page_ext(pdf, "");// end this page
	PDF_end_document(pdf, "");// Close the PDF file
	PDF_delete (pdf);
	 
	return 0;

Result screenshot:

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324908642&siteId=291194637
Recommended