logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
PDFium.Net User  
#1 Posted : Wednesday, September 19, 2018 8:07:01 AM(UTC)
Guest

Rank: Guest

Groups: Guests
Joined: 1/5/2016(UTC)
Posts: 162

Was thanked: 5 time(s) in 5 post(s)
Hello,

we're using the PDFViewer in our Application, we buied a Site License.

If I print a Document via Patagames.Pdf.Net.Controls.WinForms.PdfPrintDocument,
it's rendered a Bitmap.

If we print to a Virtual Printer like "Microsoft XPS Document Writer",
the text is also rendered as Image.

I've looked over the PDFfium DLL and I think it's possible to print as EMF instead
as Bitmap. It will also have a great effect of minimizing the print document size.

E.g we use third party tools, where we print the document in a printcontroller and add it
to another document, and it remains as vector.

Could you check if's possible to take this changes.

Regards, B.Bücher



Paul Rayman  
#2 Posted : Wednesday, September 19, 2018 8:23:15 AM(UTC)
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 1,138

Thanks: 10 times
Was thanked: 133 time(s) in 130 post(s)
Hi,
I do not have the slightest idea how this can be done.
We render the PDF directly into the printer Device Context and it does not seems that this can be done as a vector.

Could you please point me the right direction, where and what did you look in Pdfium.dll
This is very interesting functionality and we could explore it.
PDFium.Net User  
#3 Posted : Wednesday, October 3, 2018 10:49:03 AM(UTC)
Guest

Rank: Guest

Groups: Guests
Joined: 1/5/2016(UTC)
Posts: 162

Was thanked: 5 time(s) in 5 post(s)



Hello,

sorry for my late answer.

The forum didn't inform me, that there's a reply.

I asked because I'd found an article on stackoverflow.com: Article on Stackoverflow.

There they posted the following sample code:

Code:
void WriteEmf(FPDF_PAGE page, const char* pdf_name, int num) {
  int width = static_cast<int>(FPDF_GetPageWidth(page));
  int height = static_cast<int>(FPDF_GetPageHeight(page));

  char filename[256];
  snprintf(filename, sizeof(filename), "%s.%d.emf", pdf_name, num);

  HDC dc = CreateEnhMetaFileA(nullptr, filename, nullptr, nullptr);

  HRGN rgn = CreateRectRgn(0, 0, width, height);
  SelectClipRgn(dc, rgn);
  DeleteObject(rgn);

  SelectObject(dc, GetStockObject(NULL_PEN));
  SelectObject(dc, GetStockObject(WHITE_BRUSH));
  // If a PS_NULL pen is used, the dimensions of the rectangle are 1 pixel less.
  Rectangle(dc, 0, 0, width + 1, height + 1);

  FPDF_RenderPage(dc, page, 0, 0, width, height, 0,
                  FPDF_ANNOT | FPDF_PRINTING | FPDF_NO_CATCH);

  DeleteEnhMetaFile(CloseEnhMetaFile(dc));
}


This sample refers to the sample on googlesource: Sample on Googlesource

So i think it's possible to export as emf.
Paul Rayman  
#4 Posted : Wednesday, October 3, 2018 4:54:35 PM(UTC)
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 1,138

Thanks: 10 times
Was thanked: 133 time(s) in 130 post(s)
Well ... The PdfPrintdocument does exactly the same thing. It renders to device context (dc) directly as in your example. For one exception, in your example dc is obtained by the CreateMetaFile function, but PdfPrintDocument get it from the target printer.

You can easily reproduce the code you provided in .Net

Code:
[DllImport(@"gdi32.dll", EntryPoint = "CreateEnhMetaFileA", SetLastError = true)]
private static extern IntPtr CreateEnhMetaFileA(IntPtr hdc, [MarshalAs(UnmanagedType.LPStr)]string file, IntPtr rect, IntPtr desc);

[DllImport(@"gdi32.dll", EntryPoint = "CloseEnhMetaFile", SetLastError = true)]
private static extern IntPtr CloseEnhMetaFile(IntPtr hdc);

[DllImport(@"gdi32.dll", EntryPoint = "DeleteEnhMetaFile", SetLastError = true)]
private static extern bool DeleteEnhMetaFile(IntPtr hMetaFile);


Code:
using (var doc = PdfDocument.Load(@"d:\0\1\review.pdf"))
{
    var page = doc.Pages[0];
    int width = (int)page.Width;
    int height = (int)page.Height;


    IntPtr hdc = CreateEnhMetaFileA(IntPtr.Zero, @"d:\9\test.emf", IntPtr.Zero, IntPtr.Zero);

    using (var g = System.Drawing.Graphics.FromHdc(hdc))
    {
        g.SetClip(new Rectangle(0, 0, width, height));
        g.FillRectangle(Brushes.White, 0, 0, width, height);
        page.Render(hdc, 0, 0, width, height, PageRotate.Normal, RenderFlags.FPDF_PRINTING | RenderFlags.FPDF_ANNOT | RenderFlags.FPDF_NO_CATCH);
    }

    DeleteEnhMetaFile(CloseEnhMetaFile(hdc));
}


Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.