我正在使用 abcPdf 将 HTML 报告转换为 pdf 文件。pdf 必须是单个横向 A4 页面。
您知道是否有任何方法可以告诉 abcPdf 缩放 HTML 页面以适合 pdf 中的单个页面?我尝试使用Magnify() 方法,它会缩放内容,但仍会将其分成页面,即使它适合一页。我已经为此苦苦挣扎了一段时间,想知道是否有人这样做过。
这是我目前正在使用的代码:
public byte[] UrlToPdf(string url, PageOrientation po)
{
using (Doc theDoc = new Doc())
{
// When in landscape mode:
// We use two transforms to apply a generic 90 degree rotation around
// the center of the document and rotate the drawing rectangle by the same amount.
if (po == PageOrientation.Landscape)
{
// apply a rotation transform
double w = theDoc.MediaBox.Width;
double h = theDoc.MediaBox.Height;
double l = theDoc.MediaBox.Left;
double b = theDoc.MediaBox.Bottom;
theDoc.Transform.Rotate(90, l, b);
theDoc.Transform.Translate(w, 0);
// rotate our rectangle
theDoc.Rect.Width = h;
theDoc.Rect.Height = w;
// To change the default orientation of the document we need to apply a rotation to the root page object.
//By doing this we ensure that every page in the document is viewed rotated.
int theDocID = Convert.ToInt32(theDoc.GetInfo(theDoc.Root, "Pages"));
theDoc.SetInfo(theDocID, "/Rotate", "90");
}
theDoc.HtmlOptions.PageCacheEnabled = false;
theDoc.HtmlOptions.AddForms = false;
theDoc.HtmlOptions.AddLinks = false;
theDoc.HtmlOptions.AddMovies = false;
theDoc.HtmlOptions.FontEmbed = false;
theDoc.HtmlOptions.UseResync = false;
theDoc.HtmlOptions.UseVideo = false;
theDoc.HtmlOptions.UseScript = false;
theDoc.HtmlOptions.HideBackground = false;
theDoc.HtmlOptions.Timeout = 60000;
theDoc.HtmlOptions.BrowserWidth = 0;
theDoc.HtmlOptions.ImageQuality = 101;
// Add url to document.
int theID = theDoc.AddImageUrl(url, true, 0, true);
while (true)
{
if (!theDoc.Chainable(theID))
break;
theDoc.Page = theDoc.AddPage();
theID = theDoc.AddImageToChain(theID);
}
//Flattening the pages (Whatever that means)
for (int i = 1; i <= theDoc.PageCount; i++)
{
theDoc.PageNumber = i;
theDoc.Flatten();
}
return theDoc.GetData();
}
}