PDFをイメージに作成し、PDFのサイズを変更してリンクを追加しようとしています。私はこれをやっているので、複数のプロジェクトで使用するために画像にリンクを埋め込むことができます。私はPDFsharpを使用しています。画像上のリンクでうまくいきましたが、PDFページのサイズを変更するとリンクが機能しなくなりました。PDFsharpリンクが正常に動作しない
private static void createPDF()
{
string image = "C:\\download.png";
string filename = "C:\\Test.pdf";
PdfDocument doc = new PdfDocument();
PdfPage page = doc.AddPage();
XGraphics gfx = XGraphics.FromPdfPage(page);
AddImage(gfx, page, image, 0, 0);
doc.Save(filename);
}
private static void AddImage(XGraphics gfx, PdfPage page, string imagePath, int xPosition, int yPosition)
{
if (!File.Exists(imagePath))
{
throw new FileNotFoundException(String.Format("Could not find image {0}.", imagePath));
}
XImage xImage = XImage.FromFile(imagePath);
page.Width = xImage.PixelWidth;
page.Height = xImage.PixelHeight;
gfx.DrawImage(xImage, xPosition, yPosition, xImage.PixelWidth, xImage.PixelHeight);
XRect rec = gfx.Transformer.WorldToDefaultPage(new XRect(new XPoint(xPosition, yPosition), new XSize(page.Width, page.Height)));
PdfRectangle rect = new PdfRectangle(rec);
page.AddWebLink(rect, "http://www.google.com");
}
これはうまくいくように思われるかもしれませんが、いつもうまくいくとは限りません。 XGraphics.FromPdfPage(page);を呼び出す前にページの幅と高さを設定してください。 –