Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #26419

    Hello PD4ML Support Team,

    I am using the below posted code to generate PD4ML from asp.net application. Every thing till the file creation process works fine except it is throwing a permissions error when application tried to save the PDF. I am an admin on my Box. Can you help me to solve the permissions issue please?
    Same time Can you also validate the stuff that I am doing below is proper as well.
    {I did use VB.NET with framework 3.5 and PD4ML.NET during this task.Hope this helps}

    '.................Purpose of the File ......................................................................
    'Title: Test.
    'This page will be used to testBuild any new functionality independently.
    '................................................................................................................
    Imports org.zefer.pd4ml
    Imports System.IO
    
    ''' <summary>
    '''
    ''' </summary>
    Partial Class PD4MLTest
    Inherits System.Web.UI.Page
    'Protected Shared USAGE As String = "Usage: pd4net.exe '<url>' <htmlWidth> [pageFormat] [-permissions <NUMBER>]" & _
    '"[-bookmarks <HEADINGS|ANCHORS>] [-orientation <PORTRAIT|LANDSCAPE>] " & _
    '"[-ttf <ttf_fonts_dir>] [-out <output_file_path>]"
    
    Protected Shared strUsage As String
    Protected Shared USAGE As ArrayList = New ArrayList()
    
    
    
    ''' <summary>
    ''' Handles the Load event of the Page control.
    ''' </summary>
    ''' <param name="sender">The source of the event.</param>
    ''' <param name="e">The <see cref="System.EventArgs" /> instance containing the event data.</param>
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    USAGE.Add("http://localhost:3013/web/Default.aspx")
    USAGE.Add(500)
    USAGE.Add("A4")
    USAGE.Add(1)
    USAGE.Add("HEADINGS")
    USAGE.Add("PORTRAIT")
    USAGE.Add("c:windowsfonts")
    USAGE.Add("C:P")
    strUsage = String.Format("Usage: pd4net.exe {0}, {1}, {2}, -permissions {3}, -bookmarks {4}, -orientation {5}, - ttf {6},-out {7}", USAGE(0), USAGE(1), USAGE(2), USAGE(3), USAGE(4), USAGE(5), USAGE(6), USAGE(7))
    Main(USAGE)
    'Converter.generatePDF(infile, width, Format, permissions, bookmarks, Orientation, ttf, outfile)
    End Sub
    ''' <summary>
    ''' Generates the PDF.
    ''' </summary>
    ''' <param name="inputUrl">The input URL.</param>
    ''' <param name="htmlWidth">Width of the HTML.</param>
    ''' <param name="pageFormat">The page format.</param>
    ''' <param name="permissions">The permissions.</param>
    ''' <param name="bookmarks">The bookmarks.</param>
    ''' <param name="orientation">The orientation.</param>
    ''' <param name="fontsDir">The fonts dir.</param>
    ''' <param name="outfile">The outfile.</param>
    Protected Sub generatePDF(ByVal inputUrl As String, ByVal htmlWidth As Integer, ByVal pageFormat As String, ByVal permissions As Integer, ByVal bookmarks As String, ByVal orientation As String, ByVal fontsDir As String, ByVal outfile As String)
    Dim pd4ml As PD4ML = New PD4ML()
    
    pd4ml.HtmlWidth = htmlWidth
    
    If (orientation = Nothing Or orientation.Trim.Length = 0) Then
    orientation = "portrait"
    End If
    
    If ("PORTRAIT".Equals(orientation.ToUpper())) Then
    pd4ml.PageSize = PD4Constants.getSizeByName(pageFormat)
    Else
    pd4ml.PageSize = pd4ml.changePageOrientation(PD4Constants.getSizeByName(pageFormat))
    End If
    
    If (permissions <> -1) Then
    pd4ml.setPermissions("empty", permissions, True)
    End If
    
    If (bookmarks <> Nothing AndAlso bookmarks.Trim.Length > 0) Then
    If ("ANCHORS".Equals(bookmarks.ToUpper())) Then
    pd4ml.generateOutlines(False)
    ElseIf ("HEADINGS".Equals(bookmarks.ToUpper())) Then
    pd4ml.generateOutlines(True)
    End If
    End If
    
    If (fontsDir <> Nothing AndAlso fontsDir.Length > 0) Then
    pd4ml.useTTF(fontsDir, True)
    End If
    
    If (outfile = Nothing OrElse outfile.Equals("-")) Then
    pd4ml.render(New Uri(inputUrl), Console.Out)
    Else
    pd4ml.render(New Uri(inputUrl), New System.IO.FileStream(outfile, System.IO.FileMode.Create))
    End If
    End Sub
    ''' <summary>
    ''' Wrongs the param.
    ''' </summary>
    ''' <param name="msg">The MSG.</param>
    Protected Shared Sub wrongParam(ByVal msg As String)
    Console.Out.WriteLine("invalid parameter: " + msg)
    Console.Out.WriteLine(USAGE)
    End Sub
    
    
    
    ''' <summary>
    ''' Mains the specified args.
    ''' </summary>
    ''' <param name="args">The args.</param>
    Private Shared Sub Main(ByVal args As ArrayList)
    'Private Shared Sub Main(ByVal args As string())
    '  converter.generatePDF(infile, width, format, permissions, bookmarks, orientation, ttf, outfile)
    Dim infile As String = args(0).ToString
    Dim width As Integer = CInt(args(1))
    Dim format As String = args(2).ToString
    Dim permissions As Integer = args(3).ToString
    Dim bookmarks As String = args(4).ToString
    Dim orientation As String = args(5).ToString
    Dim ttf As String = args(6).ToString
    Dim outfile As String = args(7).ToString
    Dim formatSet As Boolean = False
    Dim ff As FileInfo = Nothing
    Dim i As Integer
    
    For i = 0 To i < args.Count
    'For i = 0 To i < args.Length
    
    If ("-permissions".Equals(args(i))) Then
    i = i + i
    'If (i = args.Length) Then
    If (i = args.Count) Then
    wrongParam("missing permissions number (a sum of single permission codes)")
    Return
    End If
    permissions = Int32.Parse(args(i))
    Continue For
    End If
    
    If ("-bookmarks".Equals(args(i))) Then
    i = i + i
    If (i = args.Count) Then
    wrongParam("missing bookmark type (HEADINGS or ANCHORS)")
    Return
    End If
    bookmarks = args(i)
    Continue For
    End If
    
    If ("-orientation".Equals(args(i))) Then
    i = i + i
    If (i = args.Count) Then
    wrongParam("missing orientation type (PORTRAIT or LANDSCAPE)")
    Return
    End If
    orientation = args(i)
    Continue For
    End If
    
    If ("-ttf".Equals(args(i))) Then
    i = i + i
    If (i = args.Count) Then
    wrongParam("missing TTF fonts directory")
    Return
    End If
    ff = New FileInfo(args(i))
    ttf = ff.FullName
    Continue For
    End If
    
    If ("-out".Equals(args(i))) Then
    i = i + i
    If (i = args.Count) Then
    wrongParam("missing output file name")
    Return
    End If
    outfile = args(i)
    Continue For
    End If
    
    If (args(i).StartsWith("-")) Then
    wrongParam("unknown: " + args(i))
    Return
    End If
    
    If (infile = Nothing) Then
    Dim ss As String = args(i)
    If Not (ss.StartsWith("http://") AndAlso ss.StartsWith("file://")) Then
    ff = New FileInfo(ss)
    infile = "file:///" & ff.FullName
    Else
    infile = ss
    End If
    Continue For
    End If
    
    If (width = -1) Then
    width = Int32.Parse(args(i))
    Continue For
    End If
    
    If (Not formatSet) Then
    formatSet = True
    format = args(i)
    Continue For
    End If
    wrongParam(args(i))
    Return
    Next i
    
    If (infile = Nothing) Then
    Console.Out.WriteLine("source URL is missing")
    Console.Out.WriteLine(USAGE)
    Return
    End If
    
    If (width = -1) Then
    Console.Out.WriteLine("HTML width parameter is missing")
    Console.Out.WriteLine(USAGE)
    Return
    End If
    
    Dim converter As PD4MLTest = New PD4MLTest
    converter.generatePDF(infile, width, format, permissions, bookmarks, orientation, ttf, outfile)
    
    End Sub
    End Class

    Thanks and Regards,
    Venky

    #28111

    In fact ASP.NET pages are works under IIS with limited user creentials; so please check the following:

    1. Please check your application have writing permissions. Usually it are disabled.

    2. If your folder is out of IIS folders scope, please check you set write access to everyone or to at least local IUSR_* users.

Viewing 2 posts - 1 through 2 (of 2 total)

The forum ‘General questions / FAQ’ is closed to new topics and replies.