private static void PrintPage(HPdfPage page, int page_num) { page.SetWidth(800); page.SetHeight(800); page.BeginText(); page.MoveTextPos(30, 740); string buf = "Page:" + page_num; page.ShowText(buf); page.EndText(); }
public static void Main() { Console.WriteLine("libhpdf-" + HPdfDoc.HPdfGetVersion()); byte[] raw_image_data = new byte[] { 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff, 0xf0, 0xf3, 0xf3, 0xff, 0xe0, 0xf3, 0xf3, 0xff, 0xc0, 0xf3, 0xf3, 0xff, 0x80, 0xf3, 0x33, 0xff, 0x00, 0xf3, 0x33, 0xfe, 0x00, 0xf3, 0x33, 0xfc, 0x00, 0xf8, 0x07, 0xf8, 0x00, 0xf8, 0x07, 0xf0, 0x00, 0xfc, 0xcf, 0xe0, 0x00, 0xfc, 0xcf, 0xc0, 0x00, 0xff, 0xff, 0x80, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x00, 0xff, 0xfc, 0x00, 0x00, 0xff, 0xf8, 0x0f, 0xe0, 0xff, 0xf0, 0x0f, 0xe0, 0xff, 0xe0, 0x0c, 0x30, 0xff, 0xc0, 0x0c, 0x30, 0xff, 0x80, 0x0f, 0xe0, 0xff, 0x00, 0x0f, 0xe0, 0xfe, 0x00, 0x0c, 0x30, 0xfc, 0x00, 0x0c, 0x30, 0xf8, 0x00, 0x0f, 0xe0, 0xf0, 0x00, 0x0f, 0xe0, 0xe0, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; try { HPdfDoc pdf = new HPdfDoc(); pdf.SetCompressionMode(HPdfDoc.HPDF_COMP_ALL); /* create default-font */ HPdfFont font = pdf.GetFont("Helvetica", null); /* add a new page object. */ HPdfPage page = pdf.AddPage(); page.SetWidth(172); page.SetHeight(80); page.BeginText(); page.SetFontAndSize(font, 20); page.MoveTextPos(220, page.GetHeight() - 70); page.ShowText("RawImageDemo"); page.EndText(); /* load RGB raw-image file. */ HPdfImage image = pdf.LoadRawImageFromFile("rawimage\\32_32_rgb.dat", 32, 32, HPdfColorSpace.HPDF_CS_DEVICE_RGB); float x = 20; float y = 20; /* Draw image to the canvas. (normal-mode with actual size.)*/ page.DrawImage(image, x, y, 32, 32); /* load GrayScale raw-image file. */ image = pdf.LoadRawImageFromFile("rawimage\\32_32_gray.dat", 32, 32, HPdfColorSpace.HPDF_CS_DEVICE_GRAY); x = 70; y = 20; /* Draw image to the canvas. (normal-mode with actual size.)*/ page.DrawImage(image, x, y, 32, 32); /* load GrayScale raw-image (1bit) file from memory. */ image = pdf.LoadRawImageFromMem(raw_image_data, 32, 32, HPdfColorSpace.HPDF_CS_DEVICE_GRAY, 1); x = 120; y = 20; /* Draw image to the canvas. (normal-mode with actual size.)*/ page.DrawImage(image, x, y, 32, 32); /* save the document to a file */ pdf.SaveToFile("RawImageDemo.pdf"); } catch (Exception e) { Console.Error.WriteLine(e.Message); } }
public static void Main() { Console.WriteLine("libhpdf-" + HPdfDoc.HPdfGetVersion()); try { HPdfDoc pdf = new HPdfDoc(); pdf.SetCompressionMode(HPdfDoc.HPDF_COMP_ALL); /* create default-font */ HPdfFont font = pdf.GetFont("Helvetica", null); /* add a new page object. */ HPdfPage page = pdf.AddPage(); page.SetWidth(550); page.SetHeight(500); HPdfDestination dst = page.CreateDestination(); dst.SetXYZ(0, page.GetHeight(), 1); pdf.SetOpenAction(dst); page.BeginText(); page.SetFontAndSize(font, 20); page.MoveTextPos(220, page.GetHeight() - 70); page.ShowText("ImageDemo"); page.EndText(); /* load image file. */ HPdfImage image = pdf.LoadPngImageFromFile("pngsuite\\basn3p02.png"); /* image1 is masked by image2. */ HPdfImage image1 = pdf.LoadPngImageFromFile("pngsuite\\basn3p02.png"); /* image2 is a mask image. */ HPdfImage image2 = pdf.LoadPngImageFromFile("pngsuite\\basn0g01.png"); /* image3 is a RGB-color image. we use this image for color-mask * demo. */ HPdfImage image3 = pdf.LoadPngImageFromFile("pngsuite\\maskimage.png"); float iw = image.GetWidth(); float ih = image.GetHeight(); page.SetLineWidth(0.5f); float x = 100; float y = page.GetHeight() - 150; /* Draw image to the canvas. (normal-mode with actual size.)*/ page.DrawImage(image, x, y, iw, ih); ShowDescription(page, x, y, "Actual Size"); x += 150; /* Scalling image (X direction) */ page.DrawImage(image, x, y, iw * 1.5f, ih); ShowDescription(page, x, y, "Scalling image (X direction)"); x += 150; /* Scalling image (Y direction). */ page.DrawImage(image, x, y, iw, ih * 1.5f); ShowDescription(page, x, y, "Scalling image (Y direction)"); x = 100; y -= 120; /* Skewing image. */ float angle1 = 10; float angle2 = 20; float rad1 = angle1 / 180 * 3.141592f; float rad2 = angle2 / 180 * 3.141592f; page.GSave(); page.Concat(iw, (float)Math.Tan(rad1) * iw, (float)Math.Tan(rad2) * ih, ih, x, y); page.ExecuteXObject(image); page.GRestore(); ShowDescription(page, x, y, "Skewing image"); x += 150; /* Rotating image */ float angle = 30; /* rotation of 30 degrees. */ float rad = angle / 180 * 3.141592f; /* Calcurate the radian value. */ page.GSave(); page.Concat((float)(iw * Math.Cos(rad)), (float)(iw * Math.Sin(rad)), (float)(ih * -Math.Sin(rad)), (float)(ih * Math.Cos(rad)), x, y); page.ExecuteXObject(image); page.GRestore(); ShowDescription(page, x, y, "Rotating image"); x += 150; /* draw masked image. */ /* Set image2 to the mask image of image1 */ image1.SetMaskImage(image2); page.SetRGBFill(0, 0, 0); page.BeginText(); page.MoveTextPos(x - 6, y + 14); page.ShowText("MASKMASK"); page.EndText(); page.DrawImage(image1, x - 3, y - 3, iw + 6, ih + 6); ShowDescription(page, x, y, "masked image"); x = 100; y -= 120; /* color mask. */ page.SetRGBFill(0, 0, 0); page.BeginText(); page.MoveTextPos(x - 6, y + 14); page.ShowText("MASKMASK"); page.EndText(); image3.SetColorMask(0, 255, 0, 0, 0, 255); page.DrawImage(image3, x, y, iw, ih); ShowDescription(page, x, y, "Color Mask"); /* save the document to a file */ pdf.SaveToFile("ImageDemo.pdf"); } catch (Exception e) { Console.Error.WriteLine(e.Message); } }
private static void PrintPage(HPdfPage page, string caption, HPdfFont font, HPdfTransitionStyle type, HPdfPage prev, HPdfPage next) { float r = (float)rand.Next(255) / 255; float g = (float)rand.Next(255) / 255; float b = (float)rand.Next(255) / 255; HPdfRect rect; HPdfDestination dst; HPdfAnnotation annot; page.SetWidth(800); page.SetHeight(600); page.SetRGBFill(r, g, b); page.Rectangle(0, 0, 800, 600); page.Fill(); page.SetRGBFill(1.0f - r, 1.0f - g, 1.0f - b); page.SetFontAndSize(font, 30); page.BeginText(); page.SetTextMatrix(0.8f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f); page.TextOut(50, 530, caption); page.SetTextMatrix(1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f); page.SetFontAndSize(font, 20); page.TextOut(55, 300, "Type \"Ctrl+L\" in order to return from full screen mode."); page.EndText(); page.SetSlideShow(type, 5.0f, 1.0f); page.SetFontAndSize(font, 20); if (next != null) { page.BeginText(); page.TextOut(680, 50, "Next=>"); page.EndText(); rect.left = 680; rect.right = 750; rect.top = 70; rect.bottom = 50; dst = next.CreateDestination(); dst.SetFit(); annot = page.CreateLinkAnnot(rect, dst); annot.SetBorderStyle(0, 0, 0); annot.SetHighlightMode(HPdfAnnotHighlightMode.HPDF_ANNOT_INVERT_BOX); } if (prev != null) { page.BeginText(); page.TextOut(50, 50, "<=Prev"); page.EndText(); rect.left = 50; rect.right = 110; rect.top = 70; rect.bottom = 50; dst = prev.CreateDestination(); dst.SetFit(); annot = page.CreateLinkAnnot(rect, dst); annot.SetBorderStyle(0, 0, 0); annot.SetHighlightMode(HPdfAnnotHighlightMode.HPDF_ANNOT_INVERT_BOX); } }
public static void Main() { Console.WriteLine("libhpdf-" + HPdfDoc.HPdfGetVersion()); try { const int PAGE_HEIGHT = 210; string samp_text = "アメンボ赤いなあいうえお。浮き藻に小エビもおよいでる。"; HPdfFont[] detail_font = new HPdfFont[16]; HPdfDoc pdf = new HPdfDoc(); /*declaration for using Japanese font, encoding. */ pdf.UseJPEncodings(); pdf.UseJPFonts(); detail_font[0] = pdf.GetFont("MS-Mincyo", "90ms-RKSJ-H"); detail_font[1] = pdf.GetFont("MS-Mincyo,Bold", "90ms-RKSJ-H"); detail_font[2] = pdf.GetFont("MS-Mincyo,Italic", "90ms-RKSJ-H"); detail_font[3] = pdf.GetFont("MS-Mincyo,BoldItalic", "90ms-RKSJ-H"); detail_font[4] = pdf.GetFont("MS-PMincyo", "90msp-RKSJ-H"); detail_font[5] = pdf.GetFont("MS-PMincyo,Bold", "90msp-RKSJ-H"); detail_font[6] = pdf.GetFont("MS-PMincyo,Italic", "90msp-RKSJ-H"); detail_font[7] = pdf.GetFont("MS-PMincyo,BoldItalic", "90msp-RKSJ-H"); detail_font[8] = pdf.GetFont("MS-Gothic", "90ms-RKSJ-H"); detail_font[9] = pdf.GetFont("MS-Gothic,Bold", "90ms-RKSJ-H"); detail_font[10] = pdf.GetFont("MS-Gothic,Italic", "90ms-RKSJ-H"); detail_font[11] = pdf.GetFont("MS-Gothic,BoldItalic", "90ms-RKSJ-H"); detail_font[12] = pdf.GetFont("MS-PGothic", "90msp-RKSJ-H"); detail_font[13] = pdf.GetFont("MS-PGothic,Bold", "90msp-RKSJ-H"); detail_font[14] = pdf.GetFont("MS-PGothic,Italic", "90msp-RKSJ-H"); detail_font[15] = pdf.GetFont("MS-PGothic,BoldItalic", "90msp-RKSJ-H"); /*configure pdf-document to be compressed. */ pdf.SetCompressionMode(HPdfDoc.HPDF_COMP_ALL); /*Set page mode to use outlines. */ pdf.SetPageMode(HPdfPageMode.HPDF_PAGE_MODE_USE_OUTLINE); /*create outline root. */ HPdfOutline root = pdf.CreateOutline(null, "JP font demo", null); root.SetOpened(true); for (int i = 0; i <= 15; i++) { float x_pos; /*add a new page object. */ HPdfPage page = pdf.AddPage(); /*create outline entry */ HPdfOutline outline = pdf.CreateOutline(root, detail_font[i].GetFontName(), null); HPdfDestination dst = page.CreateDestination(); outline.SetDestination(dst); HPdfFont title_font = pdf.GetFont("Helvetica", null); page.SetFontAndSize(title_font, 10); page.BeginText(); /*move the position of the text to top of the page. */ page.MoveTextPos(10, 190); page.ShowText(detail_font[i].GetFontName()); page.SetFontAndSize(detail_font[i], 15); page.MoveTextPos(10, -20); page.ShowText("abcdefghijklmnopqrstuvwxyz"); page.MoveTextPos(0, -20); page.ShowText("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); page.MoveTextPos(0, -20); page.ShowText("1234567890"); page.MoveTextPos(0, -20); page.SetFontAndSize(detail_font[i], 10); page.ShowText(samp_text); page.MoveTextPos(0, -18); page.SetFontAndSize(detail_font[i], 16); page.ShowText(samp_text); page.MoveTextPos(0, -27); page.SetFontAndSize(detail_font[i], 23); page.ShowText(samp_text); page.MoveTextPos(0, -36); page.SetFontAndSize(detail_font[i], 30); page.ShowText(samp_text); HPdfPoint p = page.GetCurrentTextPos(); /*finish to print text. */ page.EndText(); page.SetLineWidth(0.5f); x_pos = 20; for (int j = 0; j <= samp_text.Length / 2; j++) { page.MoveTo(x_pos, p.y - 10); page.LineTo(x_pos, p.y - 12); page.Stroke(); x_pos = x_pos + 30; } page.SetWidth(p.x + 20); page.SetHeight(PAGE_HEIGHT); page.MoveTo(10, PAGE_HEIGHT - 25); page.LineTo(p.x + 10, PAGE_HEIGHT - 25); page.Stroke(); page.MoveTo(10, PAGE_HEIGHT - 85); page.LineTo(p.x + 10, PAGE_HEIGHT - 85); page.Stroke(); page.MoveTo(10, p.y - 12); page.LineTo(p.x + 10, p.y - 12); page.Stroke(); } pdf.SaveToFile("JPFontDemo.pdf"); } catch (Exception e) { Console.Error.WriteLine(e.Message); } }