Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Tue Aug 14, 2018 1:26 pm

Maybe I'm missing something but I can't print a legal size document with legal paper. It always prints on letter size page. Here is the code I'm using:

Dim ctl As Spire.PdfViewer.Forms.PdfDocumentViewer = TryCast(uxViewerPageView.SelectedPage.Controls(0), Spire.PdfViewer.Forms.PdfDocumentViewer)
Dim prtSettings As New PrinterSettings
prtSettings.Copies = 1
prtSettings.DefaultPageSettings.PaperSize = ctl.PrintSettings.PaperSize
prtSettings.FromPage = 1
prtSettings.MaximumPage = ctl.PageCount
prtSettings.MinimumPage = 1
prtSettings.ToPage = ctl.PageCount
Dim pSettings As PrinterSettings = HelperFunctions.ShowPrinterDialog(Me, prtSettings, False)
If pSettings IsNot Nothing Then
ctl.PrintSettings.PrinterName = pSettings.PrinterName
ctl.PrintSettings.DocumentName = uxViewerPageView.SelectedPage.Text
ctl.PrintSettings.Collate = pSettings.Collate
ctl.PrintSettings.Copies = pSettings.Copies
ctl.PrintSettings.Duplex = pSettings.Duplex
ctl.PrintSettings.PaperSize = pSettings.DefaultPageSettings.PaperSize
'ctl.PrintSettings.PrintController = New Printing.StandardPrintController 'This will hide printing dialog
Select Case pSettings.PrintRange
Case PrintRange.AllPages
ctl.PrintDoc()
Case PrintRange.CurrentPage
ctl.PrintSettings.SelectPageRange(ctl.CurrentPageNumber, ctl.CurrentPageNumber)
ctl.PrintDoc()
Case PrintRange.SomePages
ctl.PrintSettings.SelectPageRange(pSettings.FromPage, pSettings.ToPage)
ctl.PrintDoc()
End Select
End If

mark@closerschoice.com
 
Posts: 7
Joined: Tue Sep 19, 2017 3:45 pm

Wed Aug 15, 2018 3:47 am

Hello,

Thanks for your inquiry.
Please set the paper size to Legal before printing. If there is any question, please feel free to write back.
Code: Select all
Dim paperSize As New PaperSize()
paperSize.RawKind = CType(PaperKind.Legal,Integer)
ctl.PrintSettings.PaperSize = paperSize

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1187
Joined: Tue Sep 27, 2016 1:06 am

Wed Aug 15, 2018 1:42 pm

Nina.Tang wrote:Hello,

Thanks for your inquiry.
Please set the paper size to Legal before printing. If there is any question, please feel free to write back.
Code: Select all
Dim paperSize As New PaperSize()
paperSize.RawKind = CType(PaperKind.Legal,Integer)
ctl.PrintSettings.PaperSize = paperSize

Sincerely,
Nina
E-iceblue support team


Ok, but how do I know if it is supposed to be a legal size document? Our users have many unique documents and there is no way for me to know what size paper is needed beforehand.

mark@closerschoice.com
 
Posts: 7
Joined: Tue Sep 19, 2017 3:45 pm

Thu Aug 16, 2018 7:36 am

Hello,

Thanks for your feedback.
You could use below code to get page size of Pdf document and set corresponding paper size.
Code: Select all
Dim paperSize As PaperSize = New PaperSize
paperSize.Width = CType(pdf.Pages(0).Size.Width,Integer)
paperSize.Height = CType(pdf.Pages(0).Size.Height,Integer)
paperSize.RawKind = CType(PaperKind.Custom,Integer)

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1187
Joined: Tue Sep 27, 2016 1:06 am

Thu Aug 16, 2018 1:39 pm

There is no item 'Pages' available to pick. This is a dynamically created PdfDocumentViewer.

Dim ctl As Spire.PdfViewer.Forms.PdfDocumentViewer = TryCast(uxViewerPageView.SelectedPage.Controls(0), Spire.PdfViewer.Forms.PdfDocumentViewer)

mark@closerschoice.com
 
Posts: 7
Joined: Tue Sep 19, 2017 3:45 pm

Fri Aug 17, 2018 8:50 am

Hello Mark,

Thanks for your feedback.
Sorry that our Spire.PDFViewer product doesn't support to get size of Pdf document, which is supported by our Spire.PDF api.
I suggest please first use Spire.Pdf api to get the pdf page size, and then deal with printing operation with PdfDocumentViewer control.

Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2767
Joined: Wed Jun 27, 2012 8:50 am

Tue Aug 21, 2018 3:40 am

Hello Mark,

Hope you are doing well.
Have you tried the way I suggested? Could you please give us some feedback at your convenience? Thanks in advance.

Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2767
Joined: Wed Jun 27, 2012 8:50 am

Tue Aug 21, 2018 1:43 pm

Yes. I now load the document with Spire.Pdf and get all the necessary info from that and then load the PdfViewer from the pdf stream. Now before printing I make all the necessary adjustments and it works.

Code: Select all
Using p As New Spire.Pdf.PdfDocument
    p.LoadFromFile(doc.FullName)
    Dim Size As SizeF = p.Pages(0).Size
    Dim paper As Printing.PaperSize = New Printing.PaperSize("Custom", CType(Size.Width / 72 * 100, Integer), CType(Size.Height / 72 * 100, Integer))
    paper.RawKind = CInt(PaperKind.Custom)

    Dim pdf As New Spire.PdfViewer.Forms.PdfDocumentViewer
    AddHandler pdf.PageNumberChanged, AddressOf pdf_PageNumberChanged
    pdf.Name = _fileNo & "_" & doc.Name & "_PdfViewer"
    pdf.Dock = DockStyle.Fill
    Page.Controls.Add(pdf)
    pdf.Show()
    Using myStream As Stream = New MemoryStream
         pdf.Tag = paper
         p.SaveToStream(myStream)
         pdf.LoadFromStream(myStream)
    End Using
    pageTotal = pdf.PageCount
    p.Close()
End Using

mark@closerschoice.com
 
Posts: 7
Joined: Tue Sep 19, 2017 3:45 pm

Wed Aug 22, 2018 2:13 am

Hello Mark,

Thanks for your feedback.
If you need any assistance in the future, please feel free to contact us.
Wish you all the best.

Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2767
Joined: Wed Jun 27, 2012 8:50 am

Wed Dec 01, 2021 4:28 pm

Hello,
please help me out this function, review the attachment and give the fix.


public static Spire.Pdf.PdfDocument AddHeaderMarginsForPDF(Spire.Pdf.PdfDocument doc, int linecount)
{

Spire.Pdf.PdfDocument destDoc = new Spire.Pdf.PdfDocument();
float top = 5;
float bottom = 5;
float left = (35 * linecount);
float right = 5;

foreach (Spire.Pdf.PdfPageBase page in doc.Pages)
{
destDoc.PrintSettings.PaperSize = new D.Printing.PaperSize("custom", (int)page.Size.Height / 72 * 100, (int)page.Size.Width / 72 * 100);
destDoc.PrintSettings.SelectSinglePageLayout(PdfSinglePageScalingMode.ActualSize, true, 50f);
Spire.Pdf.PdfPageBase newPage = destDoc.Pages.Add(new D.SizeF(page.Size.Height,page.Size.Width), new Spire.Pdf.Graphics.PdfMargins(0));
newPage.Canvas.ScaleTransform((page.ActualSize.Height - top - bottom) / page.ActualSize.Height, (page.ActualSize.Width - left - right) / page.ActualSize.Width);
newPage.Canvas.TranslateTransform(20, 630);
newPage.Canvas.RotateTransform(270);
newPage.Canvas.DrawTemplate(page.CreateTemplate(), new System.Drawing.PointF(0,0));
}

return destDoc;
}

naveenmoorthi
 
Posts: 1
Joined: Wed Dec 01, 2021 4:21 pm

Thu Dec 02, 2021 2:53 am

Hello Naveen,

Thank you for your inquiry.
I simulated a PDF file and used your code to do an initial test, but did not reproduce your issue. The version I used is the latest version(Spire.PDF Pack(Hot Fix) Version:7.11.1). If you were not using the latest version, please first give it a try. If the issue still exists after trying, please provide the following information for our reference. You could attach them here or send them to us via email (support@e-iceblue.com). Thanks in advance.
1)Your sample PDF file.
2) Your test environment, such as OS info (E.g. Windows 7, 64-bit) and region setting (E.g. China, Chinese).
3) Your application type, such as Console app (. Net Framework 4.5).

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1651
Joined: Wed Apr 07, 2021 2:50 am

Return to Spire.PDF

cron